Koa JSONSchema
A Koa middleware for validate JSONSchema
Installation
$ npm install --save koa-bodyparser@3 koa-jsonschema
Usage
const bodyParser = ;const schema = ;const koa = ; const app = ;app;app;app;app; app;
If you're still using koa@1
, use .legacy
for koa 1.0 middleware.
const schema = legacy;
schema
function arguments
schema
Object
Refer to JSONSchema documentation for made schema.
validator
The JSONSchema validator
Can be null, it means you can customize it. (see this example)
It will validate ctx.request.body
, so you should use koa-bodyparser
middleware.
If validation errors, errors will store in ctx.schemaErrors
.
pass
Boolean
Ignore the error and pass middleware.