1.1.0 • Published 6 years ago

koa-oai-router-correction v1.1.0

Weekly downloads
1
License
MIT
Repository
-
Last release
6 years ago

Koa-OAI-Router-Correction

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

Request form correction plugin for koa-oai-router.

Installation

npm i koa-oai-router-correction --save

Info

fieldtypeinfo
namestringcorrection
evoked fieldsstringparameters
evoked valueobjectOpenApi parameter object
optionsobjectcollectionFormat

Usage

collectionFormat

Determines the format of the array if type array is used. Possible values are:

  • csv - comma separated values foo,bar.
  • ssv - space separated values foo bar.
  • tsv - tab separated values foo\tbar.
  • pipes - pipe separated values foo|bar.
  • multi - corresponds to multiple parameter instances instead of multiple values for a single instance foo=bar&foo=baz. This is valid only for parameters in "query" or "formData".

Simple code:

const Koa = require('koa');
const Router = require('koa-oai-router');
const middlewareLoader = require('koa-oai-router-middleware');
const correctionHandler = require('koa-oai-router-correction');

const app = new Koa();
const router = new Router({
  apiDoc: './api',
});

router.moount();

router.mount(middlewareLoader('./controllers'));
router.mount(correctionHandler({collectionFormat: true}));

app.use(bodyParser());
app.use(router.routes());
> curl -X GET http://localhost:3000/api/pets?tags=a,b,c
> {tags: ["a", "b", "c"]}
>
> curl -X GET http://localhost:3000/api/pets?tags=a|b|c
> {tags: ["a", "b", "c"]}
>
> curl -X GET http://localhost:3000/api/pets?tags=a b c
> {tags: ["a", "b", "c"]}
>
> curl -X GET http://localhost:3000/api/pets?tags=a\b\c
> {tags: ["a", "b", "c"]}