Skip to content

Swagger 3.0 middleware for common api frameworks (pre-release version!)

License

Notifications You must be signed in to change notification settings

danielgolub/openapi-middleware

Repository files navigation

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

About

Swagger 3.0 middleware for common api frameworks (pre-release version!)

Topics

Resources

License

Stars

Watchers

Forks