Registry / devops / fetch-swagger-schema

fetch-swagger-schema

JSON →
library0.1.2jsnpmunverified

A command-line tool and library to fetch and resolve Swagger/OpenAPI 2.0 resource listing (api-docs) into a single JSON object. Current stable version: 0.1.2. This package is unmaintained and works only with Swagger 2.0 (OpenAPI 2.0). It recursively fetches all referenced API declarations and attaches them as 'apiDeclaration' properties. No alternatives are suggested in the repo; the package is minimal and has no runtime dependencies.

npm install fetch-swagger-schema
INSTALL
IMPORT
SIG · FETCH-SWAGGER-SCHE
F
fetch-swagger-schema
devopsjavascriptv0.1.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

fetchSchema (default function)
var fetchSchema = require('fetch-swagger-schema');
import fetchSchema from 'fetch-swagger-schema';
This package is CJS-only; no ESM or default export is available.
fetchSchema (default function) via ES import
import fetchSchema from 'fetch-swagger-schema';
const { fetchSchema } = require('fetch-swagger-schema');
In some bundlers or Node ESM, you can use default import, but it may trigger a CJS interop warning. The package has no named exports.
CLI command
npx fetch-swagger-schema http://example.com/api-docs output.json
fetch-swagger-schema --help
CLI is available when installed globally or via npx. The command expects exactly two arguments: URL and output file.
TypeScript usage
// @ts-ignore const fetchSchema = require('fetch-swagger-schema');
import fetchSchema from 'fetch-swagger-schema';
No TypeScript types are shipped, so type-checking is not possible without custom declaration.

Demonstrates fetching a Swagger 2.0 resource listing and resolving all referenced API declarations into a single object.

// Fetch Swagger schema from a petstore API docs endpoint and print the resolved schema var fetchSchema = require('fetch-swagger-schema'); var url = 'http://petstore.swagger.wordnik.com/api/api-docs'; fetchSchema(url, function(error, schema) { if (error) return console.error('Fetch error:', error); console.log('Resolved schema:', JSON.stringify(schema, null, 2)); });
Debug
Known issues
deprecatedThis package only supports Swagger 2.0 / OpenAPI 2.0. It does not support OpenAPI 3.x.
fix
Use a modern OpenAPI tool like 'swagger-parser' or 'openapi-fetch' for OpenAPI 3.x support.
affects: >=0.0.0
gotchaThe callback is invoked with (error, schema). If the URL is invalid or unreachable, the error may be a generic Node.js error object without detailed HTTP status codes.
fix
Wrap in try-catch or validate the URL before calling fetchSchema. Use a more robust HTTP client for better error handling.
affects: >=0.0.0
gotchaThe package recursively fetches all referenced API declarations. There is no timeout or concurrency limit, which may cause excessive network requests or hang on slow servers.
fix
Use a custom script with a proper HTTP client and implement timeouts/concurrency limits if needed.
affects: >=0.0.0
deprecatedThe package has no activity since 2017 and is archived. It has not received security updates.
fix
Switch to maintained alternatives like 'swagger-parser' (used by SwaggerUI) or '@apidevtools/swagger-parser'.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'fetch-swagger-schema'
The package is not installed or not found in node_modules.
fix
Run 'npm install fetch-swagger-schema' to install locally, or install globally with 'npm install -g fetch-swagger-schema'.
TypeError: fetchSchema is not a function
Attempted to import fetchSchema as a named export, but it is a default export (CJS).
fix
Use 'var fetchSchema = require('fetch-swagger-schema');' instead of destructured require.
Upgrade
Version history
0.1.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
fetch-swagger-schema — npm install fetch-swagger-schema · libregistry