How to check either both limit and offset are provided or none of them
limit: Joi.number().integer(),
offset: Joi.when('limit' ,{is: Joi.exist(),
then: Joi.number().integer().required()}),
//This is working if limit is provided check for offset
Try with:
limit: Joi.when('offset', {
is: Joi.exist(),
then: Joi.number().integer().required()
}),
offset: Joi.when('limit', {
is: Joi.exist(),
then: Joi.number().integer().required()
})
Doing this, both fields will be required at the same time.
limit: Joi.number().integer(),
offset: Joi.when('limit', {
is: Joi.exist(),
then: Joi.number().integer().required(),
otherwise: Joi.any().forbidden().error(new Error("need limit and offset both"))
}),
This is working
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.