koa-oai-router-parameters
v1.1.3
Published
parameters validator plugin for koa-oai-router
Downloads
37
Maintainers
Readme
Koa-OAI-Router-Parameters
Parameters validator plugin for koa-oai-router.
Installation
npm i koa-oai-router-parameters --save
Info
|field|type|info|
|---|---|---|
|name|string
|parameters
|
|evoked fields|string
| parameters
|
|evoked value|object
| OpenApi parameter object|
|options|object
| header
,path
,query
,formData
,body
,ajv
,handler
|
options
{object}
header
{boolean}
Enable header validator. defaulttrue
path
{boolean}
Enable path validator. defaulttrue
query
{boolean}
Enable query validator. defaulttrue
formData
{boolean}
Enable formData validator. defaulttrue
body
{boolean}
Enable body validator. defaulttrue
ajv
{object|function}
object
is options of Ajv.function
is a factory with arguments(Ajv)
and must return a ajv instance.handler
{function}
Response handler when validate fail. Having arguments(ctx, next, {errors, endpoint, field, fieldValue, operation, operationValue})
. Default handler response Ajv Error to body. e.g.[{ "keyword":"type", "dataPath":".size", "schemaPath":"#/properties/size/type", "params":{ "type":"number" }, "message":"should be number" }]
Simple code:
const Koa = require('koa');
const Router = require('koa-oai-router');
const middlewareLoader = require('koa-oai-router-middleware');
const parametersHandler = require('koa-oai-router-parameters');
const app = new Koa();
const router = new Router({
apiDoc: './api',
});
router.mount(middlewareLoader('./controllers'));
router.mount(parametersHandler());
app.use(bodyParser());
app.use(router.routes());