Hemera-joi package
This is a plugin to use Joi for request/response validation.
Usage
const hemera = natshemera
Request validation
The primary purpose of joi is to validate the incoming request. You can define your validation schema with the joi$
property or inline.
let Joi = hemerajoi // inlinehemera // with `joi$` propertyhemera
Response validation
You can validate the response payload as well if you use the postJoi$
property. Response error isn't validated but must be from type Error
.
Missing fields
If a field is present in the schema (and is not required) but it is not present in the object to validate, joi will not write it in the final payload.
let Joi = hemerajoi hemera
Joi settings
You can modify the joi validation settings with the pre
and post
plugin options.
const hemera = natshemera
Base schemas
You can define base schemas which enrich your existing pre/post schemas. In that way you can ensure that a specific property is always send or if you want to
set the joi property allowUnknown
to false
.
hemera
Plugin decorators
- .joi