Koa-OAI-Router-Correction
Request form correction plugin for koa-oai-router.
Installation
npm i koa-oai-router-correction --save
Info
field | type | info |
---|---|---|
name | string |
correction |
evoked fields | string |
parameters |
evoked value | object |
OpenApi parameter object |
options | object |
collectionFormat |
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"]}