https://github.com/cdimascio/express-openapi-validator
🦋 Auto-validates api requests, responses, and securities using ExpressJS and an OpenAPI 3.1.x or 3.0.x specification
https://github.com/cdimascio/express-openapi-validator
connect-middleware express express-middleware expressjs hacktoberfest middleware nodejs openapi openapi-validator openapi3 request-validation rest-api
Last synced: about 22 hours ago
JSON representation
🦋 Auto-validates api requests, responses, and securities using ExpressJS and an OpenAPI 3.1.x or 3.0.x specification
- Host: GitHub
- URL: https://github.com/cdimascio/express-openapi-validator
- Owner: cdimascio
- License: mit
- Created: 2019-03-19T19:08:05.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-05-11T19:47:54.000Z (1 day ago)
- Last Synced: 2025-05-11T20:27:43.635Z (1 day ago)
- Topics: connect-middleware, express, express-middleware, expressjs, hacktoberfest, middleware, nodejs, openapi, openapi-validator, openapi3, request-validation, rest-api
- Language: TypeScript
- Homepage:
- Size: 10.4 MB
- Stars: 948
- Watchers: 18
- Forks: 219
- Open Issues: 182
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGE_HISTORY.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
- Support: .github/SUPPORT.md
Awesome Lists containing this project
README
# 🦋 express-openapi-validator
[](#) [](https://www.npmjs.com/package/express-openapi-validator) [](https://www.npmjs.com/package/express-openapi-validator) [](#contributors) [](https://coveralls.io/github/cdimascio/express-openapi-validator?branch=master) [](https://www.codacy.com/manual/cdimascio/express-openapi-validator?utm_source=github.com&utm_medium=referral&utm_content=cdimascio/express-openapi-validator&utm_campaign=Badge_Grade) [](https://gitter.im/cdimascio-oss/community) [](https://gitpod.io/#https://github.com/cdimascio/express-openapi-validator) [](https://cdimascio.github.io/express-openapi-validator-documentation/) [](#license)**An OpenApi validator for ExpressJS** that automatically validates **API** _**requests**_ and _**responses**_ using an **OpenAPI 3** specification.
![]()
[🦋express-openapi-validator](https://github.com/cdimascio/express-openapi-validator) is an unopinionated library that integrates with new and existing API applications. express-openapi-validator lets you write code the way you want; it does not impose any coding convention or project layout. Simply, install the validator onto your express app, point it to your **OpenAPI 3.0.x** or **3.1.x** specification, then define and implement routes the way you prefer. See an [example](https://cdimascio.github.io/express-openapi-validator-documentation/guide-standard/).
**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
- ✏️ OpenAPI 3.0.x and 3.1.x spec support
- ✨ Express 4 and 5 support**Docs:**
- 📖 [documentation](https://cdimascio.github.io/express-openapi-validator-documentation/)[](https://GitHub.com/cdimascio/express-openapi-validator/stargazers/) [](https://twitter.com/intent/tweet?text=Check%20out%20express-openapi-validator%20by%20%40CarmineDiMascio%20https%3A%2F%2Fgithub.com%2Fcdimascio%2Fexpress-openapi-validator%20%F0%9F%91%8D)
[OAS 3.1](https://github.com/cdimascio/express-openapi-validator/pull/882) support available in `>=v5.4.0`!
[Express 5](https://expressjs.com/en/5x/api.html) support available in `>=v5.5.0`!_
[NestJS](https://github.com/cdimascio/express-openapi-validator/tree/master/examples/9-nestjs)
[Koa](https://github.com/cdimascio/express-openapi-validator/tree/lerna-fastify/packages/koa-openapi-validator) and [Fastify](https://github.com/cdimascio/express-openapi-validator/tree/lerna-fastify/packages/fastify-openapi-validator) now available! 🚀## Install
```shell
npm install express-openapi-validator
```## Usage
1. Require/import the openapi validator
```javascript
const OpenApiValidator = require('express-openapi-validator');
```or
```javascript
import * as OpenApiValidator from 'express-openapi-validator';
```2. Install the middleware
```javascript
app.use(
OpenApiValidator.middleware({
apiSpec: './openapi.yaml',
validateRequests: true, // (default)
validateResponses: true, // false by default
}),
);
```3. Register an error handler
```javascript
app.use((err, req, res, next) => {
// format error
res.status(err.status || 500).json({
message: err.message,
errors: err.errors,
});
});
```_**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](#example-express-api-server)_.
## [Documentation](https://cdimascio.github.io/express-openapi-validator-documentation/)
See the [doc](https://cdimascio.github.io/express-openapi-validator-documentation/) for complete documenation
_deprecated_ [legacy doc](https://github.com/cdimascio/express-openapi-validator/wiki)
## License
[MIT](LICENSE)