I'm using Joi to validate the headers on a HTTP request. I have two headers. If FOO is present then BAR is required, otherwise BAR is optional. This works:
'FOO': Joi.string().optional(),
'BAR': Joi.string().when('FOO', { is: Joi.not(''), then: Joi.required() })
If I want FOO to be a numeric value then this works:
'FOO': Joi.number().integer().default(0).optional(),
'BAR': Joi.string().when('FOO', { is: Joi.number().min(1), then: Joi.required() })
However if I omit the default(0) then Joi thinks that BAR is required when FOO is not present. Is that correct behavior? Is there a better way to handle this?