express-openapi-router
Module to define your ExpressJS routes using operationId in an OpenAPI 3.0 spec file
Last updated 2 years ago by mathieumaes .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install express-openapi-router 
SYNC missed versions from official npm registry.

express-openapi-router Build Status codecov

This router will allow you to route controllers based on the operationId inside your OpenAPI 3.0 spec file. The usage is very similar to the default Express JS Router.

Install

$ npm install express-openapi-router

Usage

Tests and examples use the official Petstore example spec: https://github.com/OAI/OpenAPI-Specification/blob/master/examples/v3.0/petstore.yaml

Notice the operationId attribute of the endpoint definition inside the spec file:

paths:
  /pets:
    get:
      summary: List all pets
      operationId: listPets

Create a routes.js file that defines your controllers for each operationId in your OpenAPI spec:

const OpenApiRouter = require('express-openapi-router');

const api = new OpenApiRouter(require("path/to/your/openapi.json"));
api.use("listPets", (req, res) => {
   res.send("Here are your pets!");
});

module.exports = api.router; // this attribute contains the actual ExpressJS Router

In your app.js:

const routes = require("routes.js");

app.use(routes);

MIT © Zimmo.be

Current Tags

  • 0.0.2                                ...           latest (2 years ago)

2 Versions

  • 0.0.2                                ...           2 years ago
  • 0.0.1                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 1
Dependencies (1)
Dev Dependencies (4)
Dependents (0)
None

Copyright 2014 - 2017 © taobao.org |