@devtea2027/harum-nesciunt-corporis-id

2.1.21 • Public • Published

🦋 @devtea2027/harum-nesciunt-corporis-id

docs.

example 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.

🦋@devtea2027/harum-nesciunt-corporis-id is an unopinionated library that integrates with new and existing API applications. @devtea2027/harum-nesciunt-corporis-id 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 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

Docs:

GitHub stars Twitter URL

NestJS Koa and Fastify now available! 🚀

Install

npm install @devtea2027/harum-nesciunt-corporis-id

## latest beta
npm install @devtea2027/harum-nesciunt-corporis-id@4.14.0-beta.1

Usage

  1. Require/import the openapi validator
const OpenApiValidator = require('@devtea2027/harum-nesciunt-corporis-id');

or

import * as OpenApiValidator from '@devtea2027/harum-nesciunt-corporis-id';
  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.

See the doc for complete documenation

deprecated legacy doc

License

MIT

Buy Me A Coffee

Readme

Keywords

Package Sidebar

Install

npm i @devtea2027/harum-nesciunt-corporis-id

Weekly Downloads

9

Version

2.1.21

License

MIT

Unpacked Size

19.1 kB

Total Files

10

Last publish

Collaborators

  • ibforusficrystal