0.3.1 • Published 10 months ago

openapi-middleware v0.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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

11 months ago

0.3.0

10 months ago

0.2.1

10 months ago

0.2.0

10 months ago

0.1.1

11 months ago

0.3.1

10 months ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago