koa-request-schema
koa-request-schema
implements request data validation using jsonschema. If data does not pass validation, the server returns a 400 Bad Request
error. In non production environments, the response body is populated with the validation errors.
Usage
const schema = ; router;
The error includes the following properties on schema validation error. The validationErrors
property is the errors
property returned by jsonschema
on validation.
Options
Options may be passed as the second argument to koa-request-schema
; additionally require('koa-request-schema').create({ ... })
will return a function with options you pass it as defaults.
displayErrors
[default=true
in non-production environments]: Include validationErrors in the error.coerceTypes
[default=true
]: Convert string values for date, integer, number, boolean, and object types to their respective type.validator
: Override the jsonschema Validator instance used.strict
[default=true
]: Do not permit unknown properties in params, query, or body unless the schema defines its ownadditionalProperties
value. (Default cannot be changed)
Koa 2 Support
To use koa-request-schema
with koa@2
, please use:
npm install --save koa-request-schema@next