koa-oai-router-responses
v1.2.0
Published
responses validator and filter plugin for koa-oai-router
Downloads
21
Maintainers
Readme
Koa-OAI-Router-Responses
Responses validator plugin for koa-oai-router.
Installation
npm i koa-oai-router-responses --save
Info
|field|type|info|
|---|---|---|
|name|string
|responses
|
|evoked fields|string
| responses
|
|evoked value|object
| OpenApi responses object|
|options|object
| ajv
, before
, after
|
options
{object}
enable
{boolean}
Enable or disable ajv validator.ajv
{object|function}
object
Options of Ajv.function
is a factory with arguments(Ajv)
and must return a ajv instance.before
{function}
Before validte. Having arguments(ctx, {catched, data, validRet, validErrs, endpoint, field, fieldValue, operation, operationValue})
.catched
{boolean}
unexpected error.data
{any}
response body or error.validRet
{boolean}
valid result.validErrs
{[object]}
valid errors.endpoint
{string}
field
{string}
fieldValue
{object}
operation
{string}
operationValue
{object}
after
{function}
After validte.
Simple code:
const Koa = require('koa');
const Router = require('koa-oai-router');
const middlewareLoader = require('koa-oai-router-middleware');
const responsesHandler = require('koa-oai-router-responses');
const app = new Koa();
const router = new Router({
apiDoc: './api',
});
router.mount(middlewareLoader('./controllers'));
router.mount(responsesHandler());
app.use(bodyParser());
app.use(router.routes());