openapi-middleware

0.3.1 • Public • Published

Sequelize logo

openapi-middleware

This is a wrapper for express that turns an openapi 3.0 document into a working api server. It sets up the endpoints, validates inputs, outputs, authentication and more.

Node.js CI License: MIT Codacy Badge Codacy Badge contributors npm version JSDocs Automation Release Automation

⚠️ Important: WIP!

This is pre-release code that is not stable yet and does not fully meet open api 3.0 standards. You're more than welcome to contribute to this repo to increase the velocity of the development effort.

📖 Resources

💻 Getting Started

You can install this fork via npm:

npm i openapi-middleware

Sample usage with express:

import openapiMiddleware from 'openapi-middleware';
import express from 'express';
import bodyParser from 'body-parser';
import {resolve} from "path";

const config = {
  definition: resolve('./tests/helpers/openapi-sample-v3.yaml'),
  controllers: resolve('./tests/helpers/controllers'),
  securitySchemes: {
    basicAuth: (req, res, next) => {
      // sample security callback for basicAuth security scheme
      next();
    }
  },
  enforceResponseValidation: false,
};

const app = express();

new openapiMiddleware.ExpressMiddleware(config)
  .on('ready', (router) => {
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: true }));
    app.use(router);
    app.listen(2020, () => console.log('server is running!'));
  })
  .on('invalidResponse', (error) => {
    console.error('silently failed on invalid response', error);
  })
  .on('error', (error) => {
    console.error('startup error', error);
  });

Package Sidebar

Install

npm i openapi-middleware

Weekly Downloads

12

Version

0.3.1

License

MIT

Unpacked Size

107 kB

Total Files

40

Last publish

Collaborators

  • danielg6666