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 = ; const api = ;api; moduleexports = apirouter; // this attribute contains the actual ExpressJS Router
In your app.js
:
const routes = ; app;
MIT © Zimmo.be