koa-oai-router-autoloader
v1.0.3
Published
Auto route middleware generator for koa-oai-router
Downloads
3
Maintainers
Readme
koa-oai-router-autoloader
Autoloader middleware plugin for koa-oai-router
Installation
npm
npm i --save koa-oai-router-autoloader
yarn
yarn add koa-oai-router-autoloader
Options
|field|type|info|
|---|---|---|
|path|string
| Relative or absolute path to the route modules |
Usage
In this example, we will load middlewares from ./controllers
directory.
const Koa = require('koa');
const Router = require('koa-oai-router');
const autoLoaderPlugin = require('koa-oai-router-autoloader');
const app = new Koa();
const router = new Router({
apiDoc: './api'
});
router.mount(autoLoaderPlugin, {
path: './controllers'
});
app.use(router.routes());
// ./controllers/pets.js
module.exports = {
get: (ctx) => {
ctx.body = {};
}
};
# ./api/paths/pets.yaml
/pets:
get:
description: "Returns all pets from the system that the user has access to"
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"