Skip to content

oaijs/koa-oai-router-parameters

Repository files navigation

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(parametersHandler());
router.mount(middlewareLoader('./controllers'));

app.use(bodyParser());
app.use(router.routes());

About

Parameters validator plugin for koa-oai-router.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published