Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
swagger-parser
Advanced tools
swagger-parser is a powerful npm package that allows you to parse, validate, and dereference Swagger (OpenAPI) definitions. It helps in ensuring that your API definitions are correct and can be used to resolve $ref pointers to simplify the API documentation.
Parse
This feature allows you to parse a Swagger (OpenAPI) definition file. The code sample demonstrates how to parse a Swagger file and log the API name and version.
const SwaggerParser = require('swagger-parser');
SwaggerParser.parse('path/to/your/swagger.yaml')
.then(api => {
console.log('API name: %s, Version: %s', api.info.title, api.info.version);
})
.catch(err => {
console.error(err);
});
Validate
This feature allows you to validate a Swagger (OpenAPI) definition file. The code sample demonstrates how to validate a Swagger file and log whether the API is valid or not.
const SwaggerParser = require('swagger-parser');
SwaggerParser.validate('path/to/your/swagger.yaml')
.then(api => {
console.log('API is valid:', api);
})
.catch(err => {
console.error('API is invalid:', err);
});
Dereference
This feature allows you to dereference $ref pointers in a Swagger (OpenAPI) definition file. The code sample demonstrates how to dereference a Swagger file and log the dereferenced API.
const SwaggerParser = require('swagger-parser');
SwaggerParser.dereference('path/to/your/swagger.yaml')
.then(api => {
console.log('Dereferenced API:', api);
})
.catch(err => {
console.error(err);
});
Bundle
This feature allows you to bundle all external $ref pointers into a single file. The code sample demonstrates how to bundle a Swagger file and log the bundled API.
const SwaggerParser = require('swagger-parser');
SwaggerParser.bundle('path/to/your/swagger.yaml')
.then(api => {
console.log('Bundled API:', api);
})
.catch(err => {
console.error(err);
});
openapi-schema-validator is a package that validates OpenAPI 3.0 schemas. It focuses on schema validation and does not provide parsing or dereferencing functionalities like swagger-parser.
swagger-jsdoc is a package that generates Swagger (OpenAPI) definitions from JSDoc comments in your code. It is more focused on generating documentation from code comments rather than parsing and validating existing Swagger files.
swagger-client is a package that provides a JavaScript client for interacting with Swagger (OpenAPI) APIs. It includes functionalities for making API requests and handling responses, but it does not focus on parsing or validating Swagger definitions.
The next major release of Swagger Parser will include support for OpenAPI v3.0. Swagger v2.0 will still be supported as well. More details and an alpha version will be released soon.
$ref
pointers, including external files and URLs$ref
pointers$ref
pointers, giving you a normal JavaScript object that's easy to work with$ref
pointers to the same value always resolve to the same object instanceSwaggerParser.validate(myAPI, function(err, api) {
if (err) {
console.error(err);
}
else {
console.log("API name: %s, Version: %s", api.info.title, api.info.version);
}
});
Or use Promises syntax instead. The following example is the same as above:
SwaggerParser.validate(myAPI)
.then(function(api) {
console.log("API name: %s, Version: %s", api.info.title, api.info.version);
})
.catch(function(err) {
console.error(err);
});
For more detailed examples, please see the API Documentation
Install using npm:
npm install swagger-parser
Then require it in your code:
var SwaggerParser = require('swagger-parser');
Install using bower:
bower install swagger-parser
Then reference swagger-parser.js
or swagger-parser.min.js
in your HTML:
<script src="bower_components/swagger-parser/dist/swagger-parser.js"></script>
Or, if you're using AMD (Require.js), then import it into your module:
define(["swagger-parser"], function(SwaggerParser) { /* your module's code */ })
Full API documentation is available right here
I welcome any contributions, enhancements, and bug-fixes. File an issue on GitHub and submit a pull request.
To build/test the project locally on your computer:
Clone this repo
git clone https://github.com/bigstickcarpet/swagger-parser.git
Install dependencies
npm install
Run the build script
npm run build
Run the tests
npm run mocha
(test in Node)
npm run karma
(test in web browsers)
npm test
(test in Node and browsers, and report code coverage)
Start the local web server
npm start
(then browse to http://localhost:8080/www/index.html or http://localhost:8080/test/index.html)
Swagger Parser is 100% free and open-source, under the MIT license. Use it however you want.
FAQs
Swagger 2.0 and OpenAPI 3.0 parser and validator for Node and browsers
The npm package swagger-parser receives a total of 563,547 weekly downloads. As such, swagger-parser popularity was classified as popular.
We found that swagger-parser demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.