I want to validate that my notes are either null or an array and if it's an array I want to validate the object attributes in the array.
Here's an example of what I want to validate
"notes" : [
{
"description" : "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed bibendum egestas erat facilisis convallis. Aliquam a libero erat. Quisque aliquet."
}
]
How can I validate that if notes is an array, validate that notes.description is a string. Otherwise if notes is null, do not validate notes.description?
Here's what I have started, but i think it's way off:
notes: [Joi.array(), Joi.allow(null)]
notes.description: ???
notes: Joi.array().includes(Joi.object({ description: Joi.string().required() })).allow(null)
Most helpful comment
notes: Joi.array().includes(Joi.object({ description: Joi.string().required() })).allow(null)