README
openapi-validator-middleware
This package provides data validation within an Express, Koa or Fastify app according to a Swagger/OpenAPI definition. It uses Ajv under the hood for validation.
NOTICE: As this package gone through a long way, as we added support for OpenAPI definitions, while also adding support for more frameworks such as Koa and Fastify, we finally took the step of changing express-ajv-swagger-validation name to something that describes it better. As of now we'll be using the name openapi-validator-middleware instead.
There are no code changes in openapi-validator-middleware@2.0.0
compared to express-ajv-swagger-validation@1.2.0
apart from the name change.
Table of Contents
- openapi-validator-middleware
Installation
Install using the node package registry:
npm install --save openapi-validator-middleware
Then import the module in your code:
const swaggerValidation = require('openapi-validator-middleware');
API
openapi-validator-middleware.validate(fastifyOptions)
This middleware function validates the request body, headers, path parameters and query parameters according to the paths definition of the swagger file. Make sure to use this middleware inside a route definition in order to have req.route.path
assigned to the most accurate express route.
fastifyOptions
: Only applicable forfastify
framework. See below.
fastifyOptions
skiplist
: Endpoint paths for which validation should not be applied. An array of strings in RegExp format, e. g.['^/pets