GithubHelp home page GithubHelp logo

macyabbey-okta / express-openapi-validator Goto Github PK

View Code? Open in Web Editor NEW

This project forked from cdimascio/express-openapi-validator

0.0 0.0 0.0 8.13 MB

๐Ÿฆ‹ Auto-validates api requests, responses, and securities using ExpressJS and an OpenAPI 3.x specification

License: MIT License

Shell 0.05% JavaScript 0.65% TypeScript 99.30%

express-openapi-validator's Introduction

๐Ÿฆ‹ express-openapi-validator

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 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 express-openapi-validator

## latest beta
npm install [email protected]

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.

See the wiki for complete documenation

License

MIT

Buy Me A Coffee

express-openapi-validator's People

Contributors

ahilke avatar allcontributors[bot] avatar benblack86 avatar cdimascio avatar ckeboss avatar comino avatar dependabot[bot] avatar efabris avatar foway0 avatar frankcalise avatar greenkeeper[bot] avatar hugomario avatar jacobley avatar jakubskopal avatar jordandobrev avatar jy95 avatar kikyomits avatar mdwheele avatar medolino avatar milo526 avatar mirekgw avatar nampas avatar ownagedj avatar pilerou avatar rowanc1 avatar sheldhur avatar snyk-bot avatar spencerlawrencebrown avatar trebler avatar zzgab avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.