Koa-OAI-Router-Middleware
Middleware loader plugin koa-oai-router
Installation
npm i koa-oai-router-middleware --save
Info
field | type | info |
---|---|---|
plugin class | string |
MiddlewarePlugin |
plugin name | string |
middleware |
evoked fields | string |[string ] |
x-oai-middleware , x-middleware , x-oai-controller , x-controller |
evoked fileds value | [{file,handler}] |
file is relative file path of middleware , handler is name of middleware exported |
options | string |object |
if options is string , effect same as object contains dir , middlewareDir and middleware . |
Usage
In this example, we will load middlewares from ./controllers
directory and recognize the value of x-oai-middleware
then bind them to a api.
const Koa = ;const Router = ;const MiddlewarePlugin = ; const app = ;const router = apiDoc: './api' options: middleware: './controllers' // OR MiddlewarePlugin: './controllers' ; router; app;app;
# ./api/paths/pets.yaml /pets: get: description: "Returns all pets from the system that the user has access to" x-oai-middleware: - file: pets handler: get parameters: - name: "tags" in: "query" description: "tags to filter by" required: false type: "array" items: type: "string" collectionFormat: "csv" - name: "limit" in: "query" description: "maximum number of results to return" required: false type: "integer" format: "int32" responses: "200": description: "pet response" schema: type: "array" items: $ref: "#/definitions/Pet"