koa-oai-router-parameters

1.1.3 • Public • Published

Koa-OAI-Router-Parameters

License Node Version NPM Version Build Status Test Coverage Downloads Dependency Status

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. default true
    • path {boolean} Enable path validator. default true
    • query {boolean} Enable query validator. default true
    • formData {boolean} Enable formData validator. default true
    • body {boolean} Enable body validator. default true
    • 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());

Package Sidebar

Install

npm i koa-oai-router-parameters

Weekly Downloads

16

Version

1.1.3

License

MIT

Unpacked Size

10.9 kB

Total Files

10

Last publish

Collaborators

  • bitebit