Installations
npm install swagger-parser
Developer
Developer Guide
Module System
CommonJS
Min. Node Version
>=10
Typescript Support
No
Node Version
10.24.1
NPM Version
6.14.12
Statistics
1,108 Stars
689 Commits
156 Forks
19 Watching
6 Branches
28 Contributors
Updated on 14 Nov 2024
Languages
JavaScript (91.02%)
SCSS (3.51%)
HTML (2.88%)
TypeScript (2.59%)
Total Downloads
Cumulative downloads
Total Downloads
203,506,762
Last day
-20.7%
170,178
Compared to previous day
Last week
-1.1%
971,638
Compared to previous week
Last month
10.5%
4,153,851
Compared to previous month
Last year
7.5%
40,466,254
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Swagger 2.0 and OpenAPI 3.0 parser/validator
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
Example
1SwaggerParser.validate(myAPI, (err, api) => { 2 if (err) { 3 console.error(err); 4 } 5 else { 6 console.log("API name: %s, Version: %s", api.info.title, api.info.version); 7 } 8});
Or use async
/await
or Promise syntax instead. The following example is the same as above:
1try { 2 let api = await SwaggerParser.validate(myAPI); 3 console.log("API name: %s, Version: %s", api.info.title, api.info.version); 4} 5catch(err) { 6 console.error(err); 7}
For more detailed examples, please see the API Documentation
Installation
Install using npm:
1npm install @apidevtools/swagger-parser
Usage
When using Swagger Parser in Node.js apps, you'll probably want to use CommonJS syntax:
1const 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:
1import * 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
Contributing
I welcome any contributions, enhancements, and bug-fixes. Open an issue on GitHub and submit a pull request.
Building/Testing
To build/test the project locally on your computer:
-
Clone this repo
git clone https://github.com/APIDevTools/swagger-parser.git
-
Install dependencies
npm install
-
Run the build script
npm run build
-
Run the tests
npm test
-
Check the code coverage
npm 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. 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 ❤
No vulnerabilities found.
Reason
15 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
2 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-pfrx-2q88-qq97
Reason
Found 5/11 approved changesets -- score normalized to 4
Reason
dependency not pinned by hash detected -- score normalized to 3
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI-CD.yaml:29: update your workflow using https://app.stepsecurity.io/secureworkflow/APIDevTools/swagger-parser/CI-CD.yaml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI-CD.yaml:32: update your workflow using https://app.stepsecurity.io/secureworkflow/APIDevTools/swagger-parser/CI-CD.yaml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI-CD.yaml:50: update your workflow using https://app.stepsecurity.io/secureworkflow/APIDevTools/swagger-parser/CI-CD.yaml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI-CD.yaml:64: update your workflow using https://app.stepsecurity.io/secureworkflow/APIDevTools/swagger-parser/CI-CD.yaml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI-CD.yaml:79: update your workflow using https://app.stepsecurity.io/secureworkflow/APIDevTools/swagger-parser/CI-CD.yaml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI-CD.yaml:82: update your workflow using https://app.stepsecurity.io/secureworkflow/APIDevTools/swagger-parser/CI-CD.yaml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI-CD.yaml:91: update your workflow using https://app.stepsecurity.io/secureworkflow/APIDevTools/swagger-parser/CI-CD.yaml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/CI-CD.yaml:102: update your workflow using https://app.stepsecurity.io/secureworkflow/APIDevTools/swagger-parser/CI-CD.yaml/main?enable=pin
- Info: 0 out of 4 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 4 third-party GitHubAction dependencies pinned
- Info: 2 out of 2 npmCommand dependencies pinned
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/CI-CD.yaml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 25 are checked with a SAST tool
Score
5.2
/10
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to swagger-parser
@apidevtools/swagger-parser
Swagger 2.0 and OpenAPI 3.0 parser and validator for Node and browsers
@buda.com/openapi-resolver-github-cli
A resolver for swagger-parser
@swagger-api/apidom-parser-adapter-api-design-systems-json
Parser adapter for parsing JSON documents into API Design Systems namespace.
@swagger-api/apidom-parser-adapter-openapi-json-3-1
Parser adapter for parsing JSON documents into OpenAPI 3.1.x namespace.