@apidevtools/swagger-parser

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

Library
npm
v12.1.0
1,206stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
45/100Fair
Development Activity0
Maintenance20
Community72
Maturity60
Momentum28

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
78/100Good
Architecture80
Code Quality82
Innovation72
Learning Curve78

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
69%
Other

Budibase

Low Code Platforms · No Code Platforms

28,220

Build AI agents, automations, and internal apps on a single open-source platform with full self-hosting control.

View details
92
Repo Health
81
Technical
63
Dependency
Built with
TypeScript69%
Svelte26%
Updated today
TypeScript
89%
Other

FastGPT

AI Agents · AI Development

29,387

Build, debug, and deploy knowledge-based AI agents with a visual workflow editor, RAG retrieval, and support for any OpenAI-compatible LLM.

View details
93
Repo Health
84
Technical
70
Dependency
Built with
TypeScript89%
Updated today
TypeScript
67%
MIT

Hoppscotch

Developer Tools

80,055

A lightweight, offline-capable API development ecosystem for testing HTTP, GraphQL, WebSocket, MQTT, and SSE endpoints across web, desktop, and CLI.

View details
91
Repo Health
83
Technical
66
Dependency
Built with
TypeScript67%
Vue23%
Updated 3 days ago
PHP
85%
Other

Invoice Ninja

Invoicing Finance · Project Management

10,008

Self-hostable invoicing, time-tracking, and multi-gateway payment platform for freelancers and small businesses, with built-in e-invoicing compliance for EU and global standards.

View details
97
Repo Health
83
Technical
62
Dependency
Built with
PHP85%
XSLT10%
Updated 2 days ago
TypeScript
97%
Other

Kibana

Analytics · Monitoring

21,251

Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.

View details
98
Repo Health
87
Technical
68
Dependency
Built with
TypeScript97%
Updated today
TypeScript
97%
MPL 2.0

Logto

Authentication

14,380

Open-source auth infrastructure for SaaS and AI apps with OIDC, SAML, and RBAC

View details
91
Repo Health
83
Technical
67
Dependency
Built with
TypeScript97%
Updated today
TypeScript
49%
MIT

Nginx Proxy Manager

Developer Tools · Networking · Security

33,903

Manage Nginx reverse proxies and free Let's Encrypt SSL through a beautiful web interface — no Nginx expertise required.

View details
92
Repo Health
77
Technical
73
Dependency
Built with
TypeScript49%
JavaScript46%
Updated 1 weeks ago
JavaScript
87%
GPL 3.0

NodeBB

Community

15,199

Modern Node.js forum software with real-time WebSockets, multi-database support, and a plugin ecosystem — the community platform built for the open web and the Fediverse.

View details
97
Repo Health
78
Technical
71
Dependency
Built with
JavaScript87%
Go Template12%
Updated today
Ruby
59%
MIT

OnetimeSecret

Security

2,900

Generate self-destructing single-use links to share passwords and sensitive data without leaving traces in inboxes or chat logs.

View details
91
Repo Health
81
Technical
74
Dependency
Built with
Ruby59%
TypeScript26%
Vue11%
Updated today

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

Search