Skip to content

Latest commit

 

History

History
72 lines (62 loc) · 4.13 KB

File metadata and controls

72 lines (62 loc) · 4.13 KB

Sequelize logo

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);
  });