Skip to content

oaijs/koa-oai-router-responses

Repository files navigation

Koa-OAI-Router-Responses

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

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

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

Releases

No releases published

Packages

No packages published