Question on relationship between child/parent properties.
I'm probably missing something very obvious, but I'm trying to validate a structure that looks roughly like this:
{
...
type: Joi.string().valid(['FOO', 'BAR', 'BAZ', 'QUX']).required(),
source: Joi.object().keys({
uri: Joi.string(),
search: Joi.string(),
username: Joi.string(),
password: Joi.string()
})
.and('username', 'password')
.when('type', { is: 'QUX', then: Joi.forbidden(), otherwise: Joi.required() })
...
}
There are relationships that I haven't been able to figure out how to describe between the source object and type:
- If type is
FOO, thenuriis required andsearchis forbidden - If type is
BARorBAZ, thensearchis required anduriis forbidden.
Pointing me in the right direction on above would be greatly appreciated. I've been turning in circles and can't get it to work quite right.
See the docs about refs for the parent/child explanation.
Until I can get the when to behave better, I think you're better off with multiple alternatives, that's not very DRY but that'll get the work done until I can find time to figure out better ways.
thanks. i was able to get it to work with multiple alternatives.