9.0.1 • Published 3 months ago

swagger-parser v9.0.1

Weekly downloads
524,843
License
MIT
Repository
github
Last release
3 months ago

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

Online Demo

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, Instagram, 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

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

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 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

Contributing

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

Building/Testing

To build/test the project locally on your computer:

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

  2. Install dependencies npm install

  3. Run the build script npm run build

  4. Run the tests npm test

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. By contributing to the Treeware forest you’ll be creating employment for local families and restoring wildlife habitats.

Big Thanks To

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

Travis CI SauceLabs Coveralls

@ballerina/api-designer@axway/openapi-utils@barchart/documentation-generatorskyway@chenalan/azuresdksmart-api-booking-servicesmashing-dev-toolsn-swagger-express-middlewareschema2ts@apielements/openapi2-parserstatic-api-docs@byu-oit/ts-oas-vue-router-genlambda-serverless-api@chnn/oatssn-mocker@chiaoti/automatesp-api-server@comet-cli/core@comet-cli/parser-open-apinode-swagger-generatorngx-swagger-client-generatormy_rai_utmxd-swaggermb-swagger-genmorphlingjsmashery-toolbeltmy-classroom-apinode-red-contrib-flowgennobelnicassa-generatornode-camelnode-red-contrib-belimo-cloud-connectormission.climock-server-swaggerrotanoavoberon-importersnubity-es-clientnu-open-clientoverjoy-swagopenapi-sdk-generatoropenapi-supportopenapi-swagger-codegenopenapi2slateopenapicmdopenapi-tsopenapi2apigeeopenapi2aspidaopenapi-copopenapi-cop-proxyopenapi-diffopenapi-2-kongopenapi-apigw-mockopenapi-backendopenapi-client-axiosopenapi-client-axios-typegenopenapi-express-middlewareopenapi-frontendopenapi-io-tsopenapi-jsdocopenapi-lintopenapi-micro-mergeopenapi-mock-generatoropenapi-reference-compilerreact-redux-api-generatorrevelio-openapi99voices_npm_tyk_client@36node/swagen@4geit/swg-chance-user-helperredfishrepotestrest-openapi-generatorrest2tsrest-tool-commonsaasify-openapi-utilssaasify-utils-testsails-routes-swagger@aot/hal-to-graphqlswaggerize-content-type-validated-routesswaggerize-docsswagger2apiswagger2codeswagmockswagmock-allofswagmock-specificswagqlswagvaliswaggerqlswaggerbankswagger-watcherswaxios@echelon-solutions/s4-coreswagger-combineswagger-comment-parserswagger-data-genswagger-data-generatorswagger-http-routerswagger-js-codegen-purvarswagger-definerswagger-diffswagger-ejs
9.0.1

3 months ago

9.0.0

3 months ago

8.0.4

5 months ago

8.0.3

7 months ago

8.0.2

8 months ago

8.0.1

9 months ago

8.0.0

12 months ago

7.0.1

12 months ago

7.0.0

12 months ago

6.0.5

1 year ago

6.0.3

1 year ago

6.0.2

2 years ago

6.0.1

2 years ago

6.0.0

2 years ago

5.0.6

2 years ago

5.0.5

2 years ago

5.0.4

2 years ago

5.0.2

2 years ago

5.0.1

2 years ago

5.0.0

2 years ago

4.1.0

2 years ago

4.0.2

2 years ago

4.0.1

3 years ago

4.0.0

3 years ago

3.4.2

3 years ago

4.0.0-beta.2

4 years ago

3.4.1

4 years ago

4.0.0-beta.1

4 years ago

3.4.0

4 years ago

3.3.0

5 years ago

3.2.1

5 years ago

3.2.0

5 years ago

3.1.0

5 years ago

3.0.1

5 years ago

3.0.0

5 years ago

3.0.0-alpha.9

5 years ago

3.0.0-alpha.8

5 years ago

3.0.0-alpha.7

5 years ago

3.0.0-alpha.6

5 years ago

3.0.0-alpha.5

5 years ago

3.0.0-alpha.4

5 years ago

3.0.0-alpha.3

5 years ago

3.0.0-alpha.2

5 years ago

2.5.0

5 years ago

2.4.3

5 years ago

2.4.2

5 years ago

2.4.1

5 years ago

2.4.0

5 years ago

2.3.3

5 years ago

2.3.2

5 years ago

2.3.1

5 years ago

2.3.0

5 years ago

2.2.9

5 years ago

2.2.8

5 years ago

2.2.5

5 years ago

2.2.4

5 years ago

2.2.3

5 years ago

2.2.2

5 years ago

2.2.1

5 years ago

2.1.3

5 years ago

2.1.2

5 years ago

2.1.1

5 years ago

2.1.0

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.9

5 years ago

1.0.8

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

6 years ago

1.0.0

6 years ago