JSPM

express-openapi-validator

6.0.0-alpha.9
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 381820
  • Score
    100M100P100Q189489F
  • License MIT

Automatically validate API requests and responses with OpenAPI 3 and Express.

Package Exports

  • express-openapi-validator
  • express-openapi-validator/dist/framework/index
  • express-openapi-validator/dist/framework/index.js
  • express-openapi-validator/dist/framework/openapi.context
  • express-openapi-validator/dist/framework/openapi.context.js
  • express-openapi-validator/dist/framework/openapi.spec.loader
  • express-openapi-validator/dist/framework/openapi.spec.loader.js
  • express-openapi-validator/dist/framework/types
  • express-openapi-validator/dist/framework/types.js
  • express-openapi-validator/dist/index.js
  • express-openapi-validator/dist/middlewares
  • express-openapi-validator/dist/middlewares/index.js
  • express-openapi-validator/dist/openapi.validator
  • express-openapi-validator/dist/openapi.validator.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (express-openapi-validator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

๐Ÿฆ‹ express-openapi-validator

build workflow All Contributors Coverage Status Codacy Badge Gitpod Ready-to-Code

An OpenApi validator for ExpressJS that automatically validates API requests and responses using an OpenAPI 3 specification.

๐Ÿฆ‹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.

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 5 support is in progress--a subset of functionality is working. Try it out and provide feedback!

Express 5 support: (5 tests fail, 438 pass). Please contribute fixes to the express-5-support branch.

Docs:

GitHub stars Twitter URL

NestJS Koa and Fastify now available! ๐Ÿš€ OAS 3.1 (beta) is available in >=v5.4.0!

Install

npm install express-openapi-validator

# for v6.0.0-alpha (for express-5 support)
npm install express-openapi-validator@alpha

Usage

  1. Require/import the openapi validator
const OpenApiValidator = require('express-openapi-validator');

or

import * as OpenApiValidator from 'express-openapi-validator';
  1. Install the middleware
app.use(
  OpenApiValidator.middleware({
    apiSpec: './openapi.yaml',
    validateRequests: true, // (default)
    validateResponses: true, // false by default
  }),
);
  1. Register an error handler
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.

Documentation

See the doc for complete documenation

deprecated legacy doc

License

MIT

Buy Me A Coffee