![Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack](https://cdn.sanity.io/images/cgdhsj6q/production/6af25114feaaac7179b18127c83327568ff592d1-1024x1024.webp?w=800&fit=max&auto=format)
Security News
Namecheap Takes Down Polyfill.io Service Following Supply Chain Attack
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
swagger-tools
Advanced tools
Readme
The project provides various tools for integrating and interacting with Swagger. This project is in its infancy but what is within the repository should be fully tested and reusable. Please visit the issue tracker to see what issues we are aware of and what features/enhancements we are working on.
consumes
value(s)swagger-tools is distributed via NPM so installation is the usual: npm install swagger-tools --save
The swagger-tools module currently exposes one property: v1_2
. This is a reference to an object that has the
following structure:
docsUrl
: This is a link to the Swagger documentation for the corresponding specification versionschemasUrl
: This is a link to the Swagger JSON Schema files for the corresponding specification versionversion
: This is the Swagger specification versionschemas
: This is an object where the keys are the Swagger JSON Schema file names and the object is the loaded schema
contentsvalidate
: This is a function used to validate a Swagger document, as a JavaScript object, against a Swagger schema
filevalidateApi
: This is a function used to validate a "full API" of Swagger documents including a resource listing and
an array of API declarationsHere is an example showing how to use both versions of the validate
function (For more details, the sources are
documented):
var spec = require('swagger-tools').v1_2;
var petJson = require('./samples/1.2/pet.json');
var rlJson = require('./samples/1.2/resource-listing.json');
var petResults = spec.validate(petJson); // The default schema used is 'apiDeclaration.json'
var rlResults = spec.validate(rlJson, 'resourceListing.json');
var apiResults = spec.validateApi(rlJson, [petJson]);
Here is an example of using the Swagger middleware for validating requests based on your Swagger resource documents:
var connect = require('connect');
var petJson = require('./samples/1.2/pet.json');
var resourceListing = require('./samples/1.2/resource-listing.json');
var storeJson = require('./samples/1.2/user.json');
var userJson = require('./samples/1.2/store.json');
var swaggerMetadata = require('swagger-tools/middleware/swagger-metadata');
var swaggerRouter = require('swagger-tools/middleware/swagger-router');
var swaggerValidator = require('swagger-tools/middleware/swagger-validator');
var app = connect();
// Interpret Swagger resources and attach metadata to request - must be first in swagger-tools middleware chain
app.use(swaggerMetadata(resourceListing, [petJson, storeJson, userJson]));
// Validate Swagger requests
app.use(swaggerValidator());
// Route validated requests to appropriate controller
app.use(swaggerRouter({useStubs: true, controllers: './controllers'}));
// ...
This project uses Gulp for building so npm install -g gulp
once you clone this project. Running gulp
in the
project root will lint check the source code and run the unit tests.
FAQs
Various tools for using and integrating with Swagger.
The npm package swagger-tools receives a total of 40,561 weekly downloads. As such, swagger-tools popularity was classified as popular.
We found that swagger-tools demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.
Security News
A JavaScript library maintainer is under fire after merging a controversial PR to support legacy versions of Node.js.