GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - APIDevTools/swagger-parser: Swagger 2.0 and OpenAPI 3.0 parser/validator

BranchesTags
Open more actions menu

Latest commit

 

History

720 Commits
720 Commits

Folders and files

NameName
Last commit message
Last commit date
.github
.github
 
 
.vscode
.vscode
 
 
_includes
_includes
 
 
dist
dist
 
 
docs
docs
 
 
lib
lib
 
 
test
test
 
 
.editorconfig
.editorconfig
 
 
.gitattributes
.gitattributes
 
 
.gitignore
.gitignore
 
 
.mocharc.yml
.mocharc.yml
 
 
.nvmrc
.nvmrc
 
 
.nycrc.yml
.nycrc.yml
 
 
.prettierignore
.prettierignore
 
 
.prettierrc
.prettierrc
 
 
404.md
404.md
 
 
CHANGELOG.md
CHANGELOG.md
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
SECURITY.md
SECURITY.md
 
 
_config.yml
_config.yml
 
 
eslint.config.mjs
eslint.config.mjs
 
 
karma.conf.js
karma.conf.js
 
 
package.json
package.json
 
 
pnpm-lock.yaml
pnpm-lock.yaml
 
 
pnpm-workspace.yaml
pnpm-workspace.yaml
 
 

Repository files navigation

Swagger 2.0 and OpenAPI 3.0 parser/validator

Build Status Coverage Status Tested on APIs.guru

npm Dependencies License Buy us a tree

OS and Browser Compatibility

Features

  • Parses Swagger specs in JSON or YAML format
  • Validates against the Swagger 2.0 schema or OpenAPI 3.0 Schema
  • Resolves all $ref pointers, including external files and URLs
  • Can bundle all your Swagger files into a single file that only has internal $ref pointers
  • Can dereference all $ref pointers, giving you a normal JavaScript object that's easy to work with
  • Tested in Node.js and all modern web browsers on Mac, Windows, and Linux
  • Tested on over 1,500 real-world APIs from Google, Microsoft, Facebook, Spotify, etc.
  • Supports circular references, nested references, back-references, and cross-references
  • Maintains object reference equality — $ref pointers to the same value always resolve to the same object instance

Related Projects

  • Swagger CLI
  • Swagger Express Middleware

Example

SwaggerParser.validate(myAPI, (err, api) => {
  if (err) {
    console.error(err);
  } else {
    console.log("API name: %s, Version: %s", api.info.title, api.info.version);
  }
});

Or use async/await or Promise syntax instead. The following example is the same as above:

try {
  let api = await SwaggerParser.validate(myAPI);
  console.log("API name: %s, Version: %s", api.info.title, api.info.version);
} catch (err) {
  console.error(err);
}

For more detailed examples, please see the API Documentation

Installation

Install using npm:

npm install @apidevtools/swagger-parser

Node.js 22.19 or later is required.

Usage

When using Swagger Parser in Node.js apps, you'll probably want to use CommonJS syntax:

const SwaggerParser = require("@apidevtools/swagger-parser");

When using a transpiler such as Babel or TypeScript, or a bundler such as Webpack or Rollup, you can use ECMAScript modules syntax instead:

import * as SwaggerParser from "@apidevtools/swagger-parser";

Browser support

Swagger Parser supports recent versions of every major web browser. Older browsers may require Babel and/or polyfills.

To use Swagger Parser in a browser, you'll need to use a bundling tool such as Webpack, Rollup, Parcel, or Browserify. Some bundlers may require a bit of configuration, such as setting browser: true in rollup-plugin-resolve.

API Documentation

Full API documentation is available right here

Security

The library, by default, attempts to resolve any files referenced using $ref, without considering file extensions or the location of the files. This can result in Local File Inclusion (LFI), thus, potentially sensitive information disclosure. Developers must be cautious when working with documents from untrusted sources. See here for more details and information on how to mitigate LFI.

Contributing

I welcome any contributions, enhancements, and bug-fixes. Open an issue on GitHub and submit a pull request.

Use the current Node.js LTS release for development. TypeScript tests use the TypeScript 7 compiler, while ESLint uses the TypeScript 6 compatibility API via Microsoft's recommended package aliases.

To test the project locally on your computer:

  1. Clone this repo
    git clone https://github.com/APIDevTools/swagger-parser.git

  2. Install dependencies
    pnpm install

  3. Run the tests
    pnpm test

  4. Check the code coverage
    pnpm run coverage

License

Swagger Parser is 100% free and open-source, under the MIT license. Use it however you want.

This package is Treeware. If you use it in production, then we ask that you buy the world a tree to thank us for our work.

Big Thanks To

Thanks to these awesome companies for their support of Open Source developers ❤

GitHub NPM Coveralls

About

Swagger 2.0 and OpenAPI 3.0 parser/validator

apidevtools.com/swagger-parser/

Topics

javascriptjson-schemanodejsopenapiopenapi3parserresolverrest-apiswaggeruniversal-javascriptvalidationvalidator

Resources

Readme
MIT license

Security policy

Security policy
Activity
Custom properties

Stars

1.2k stars

Watchers

19 watching

Forks

170 forks
Report repository

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.