๐ฆ express-openapi-validator
An OpenApi validator for ExpressJS that automatically validates API requests and responses using an OpenAPI 3 specification.
Features:
โ๏ธ request validationโ๏ธ response validation (json only)๐ฎ security validation / custom security functions๐ฝ 3rd party / custom formats / custom data serialization-deserialization๐งต optionally auto-map OpenAPI endpoints to Express handler functionsโ๏ธ $ref support; split specs over multiple files๐ file upload
Docs:
๐ documenation
NestJS
Koa and Fastify now available!
Install
npm install express-openapi-validator
## latest beta
npm install express-openapi-validator@4.14.0-beta.1
Usage
- Require/import the openapi validator
const OpenApiValidator = require('express-openapi-validator');
or
import * as OpenApiValidator from 'express-openapi-validator';
- Install the middleware
app.use(
OpenApiValidator.middleware({
apiSpec: './openapi.yaml',
validateRequests: true, // (default)
validateResponses: true, // false by default
}),
);
- Register an error handler
Important: Ensure express is configured with all relevant body parsers. Body parser middleware functions must be specified prior to any validated routes. See an example.
Documentation
See the wiki for complete documenation