@apidevtools/swagger-parser

Parses, validates, and dereferences Swagger 2.0 and OpenAPI 3.x specs in Node.js and browsers

Library
npm
v13.1.0
1,207 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
64 /100 Good
Development Activity 60
Maintenance 36
Community 72
Maturity 60
Momentum 28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
78 /100 Good
Architecture 80
Code Quality 82
Innovation 72
Learning Curve 78

Swagger Parser reads Swagger 2.0 and OpenAPI 3.0/3.1 API definitions in JSON or YAML, validates them against the official schemas, and resolves every $ref pointer — including ones that point to external files or URLs — into a single, easy-to-use JavaScript object. It builds on @apidevtools/json-schema-ref-parser for the underlying reference-resolution engine and layers Swagger/OpenAPI-specific schema and semantic validation on top.

Beyond simple parsing, it can bundle a multi-file API definition into one file with only internal references, or fully dereference it into a plain object with no $ref pointers at all, while preserving object identity so that multiple references to the same definition resolve to the same instance. It’s tested against the Swagger 2.0 and OpenAPI 3.0 JSON Schemas as well as over 1,500 real-world API definitions from major providers, and runs in both Node.js and modern browsers.

What You Get

  • Parsing of Swagger/OpenAPI specs from JSON or YAML, from a file path, URL, or in-memory object
  • Schema validation against the official Swagger 2.0 and OpenAPI 3.0/3.1 JSON Schemas, plus additional semantic checks
  • resolve() to resolve every $ref pointer including external files and URLs, bundle() to collapse a multi-file spec into one file with only internal refs, and dereference() to produce a plain object with no $refs at all
  • Support for circular references, nested references, and back-references, with object-identity preservation so identical $ref targets resolve to the same instance
  • Works identically in Node.js and modern web browsers, with both CommonJS and ESM import styles

Common Use Cases

  • Validating an OpenAPI/Swagger definition file in CI before publishing it or generating client/server code from it
  • Loading a multi-file API spec (with external $refs split across files) and bundling or fully dereferencing it into one self-contained object for downstream tooling
  • Building developer tools (mock servers, documentation generators, code generators) that need a fully resolved, validated in-memory representation of an API definition
  • Programmatically inspecting or transforming an API definition’s structure, e.g. checking api.info.version after parsing before running further processing

Under The Hood

Architecture: SwaggerParser (lib/index.js) subclasses $RefParser from the sibling @apidevtools/json-schema-ref-parser package, so parse, resolve, bundle, and dereference all defer to that package’s reference-resolution engine, with this package layering Swagger/OpenAPI-specific behavior on top: after super.parse() returns a raw JS object, it checks version fields (schema.swagger / schema.openapi) against supportedVersions (3.0.x/3.1.x plus legacy 2.0) and raises helpful SyntaxErrors for common mistakes like a numeric version field. Validation itself is split across lib/validators/schema.js (JSON Schema conformance) and lib/validators/spec.js (Swagger/OpenAPI-specific semantic rules beyond what a JSON Schema can express), with lib/options.js centralizing configurable parser behavior.

Tech Stack: Plain JavaScript (no build/transpile step for the library itself, lib/index.d.ts ships hand-written TypeScript typings), with @apidevtools/json-schema-ref-parser, @apidevtools/openapi-schemas, and @apidevtools/swagger-methods as first-party dependencies from the same APIDevTools org, plus ajv/ajv-draft-04 for JSON Schema validation and call-me-maybe to support both promise and Node-style-callback call conventions. Test tooling uses Mocha, Chai, nyc for coverage, and a TypeScript compile-check of the .d.ts file against real usage.

Code Quality: The test/specs directory is unusually thorough for a small library — dedicated suites for circular references, deep-circular references, callback-vs-promise APIs, invalid specs, relative OAS servers, and a curated ‘real-world’ folder of specs from actual providers, plus a TypeScript-definition test that type-checks the .d.ts file against sample usage. Error handling favors specific, actionable messages (e.g. distinguishing a stringly-typed vs numeric version field) rather than generic failures. Repo health scoring flags low recent commit activity/infrequent maintenance, consistent with a mature, largely-feature-complete library that doesn’t need frequent changes.

API Design: The four core verbs — parse, resolve, bundle, dereference — map directly onto the four things a consumer actually wants to do with a multi-file spec, and each is available in both callback and promise/async-await form via the call-me-maybe shim, so callers can adopt whichever style their codebase already uses. Subclassing the underlying ref-parser rather than wrapping it means advanced users can drop to the lower-level $RefParser API when they need generic JSON Schema ref-resolution behavior not specific to Swagger/OpenAPI.

Used by 14 apps in this directory

TypeScript
90%
MIT

Plasmic

CMS · Design Tools · Low Code Platforms

7,125

The open-source visual builder that lets teams design React apps and websites with drag-and-drop while integrating seamlessly with your codebase.

View details
81
Repo Health
78
Technical
64
Dependency
Built with
TypeScript 90%
Updated 6 days ago
TypeScript
67%
MIT

Scalar

Developer Tools

16,313

Beautiful, interactive OpenAPI documentation with a built-in offline-first API client and multi-language code generation — all in one open-source platform.

View details
90
Repo Health
89
Technical
65
Dependency
Built with
TypeScript 67%
Vue 29%
Updated 5 days ago
TypeScript
89%
Other

strapi

CMS

73,368

Open-source headless CMS that auto-generates REST and GraphQL APIs from your content models, with a fully customizable admin panel you control.

View details
93
Repo Health
84
Technical
63
Dependency
Built with
TypeScript 89%
JavaScript 11%
Updated 6 days ago
TypeScript
97%
Apache 2.0

Unleash

Ab Testing Experimentation · Developer Tools · Devops

13,899

The open-source feature management platform that lets you ship code to production and control who sees it — without redeploying.

View details
91
Repo Health
84
Technical
69
Dependency
Built with
TypeScript 97%
Updated 6 days ago
Python
57%
Apache 2.0

Zulip

Team Chat

26,102

Topic-based team chat that brings the structure of email threads to real-time messaging, so distributed teams never lose context across hundreds of concurrent conversations.

View details
96
Repo Health
86
Technical
60
Dependency
Built with
Python 57%
TypeScript 19%
JavaScript 11%
Updated 6 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers