swagger-route-validator
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

logo
Swagger Route Validator



  • Extremely fast and >10x more efficient than sway, the next fastest alternative
  • Zero dependencies
  • Battle-tested by Fortune 500 companies
  • Supports most OpenAPI 3.0 features like $ref, $not, $anyOf, $allOf, $oneOf, etc.
  • Supports most common data formats like emails, ips, uuids, dates, etc.

Usage

This is an example of an express middleware, which you could easily implement if you have your routes' swagger definitions.

import validate from 'swagger-route-validator';

// Pass in the swagger spec for that route and return an express middleware
export default (routeSpec) => function validateRequest(req, res, next) {
    // Check validation errors
    const errors = validate(routeSpec, req);
    if (errors.length > 0) return res.status(400).json(errors);

    next();
};

If you don't know in advance what route definition to use on an inbound request, you can follow this example

Running tests

npm run test

License

Apache 2.0 - Frederic Charette

Package Sidebar

Install

npm i swagger-route-validator

Weekly Downloads

65

Version

2.0.1

License

Apache-2.0

Unpacked Size

20 kB

Total Files

8

Last publish

Collaborators

  • fed135