I have a post call which can take the payload as a single JS
object as well as array of objects to save it to the db. How to write a schema to validate against such payload ?
JS object
{
label: 'label',
key: 'key',
help_text: 'text'
}
Or
[
{
label: 'label1',
key: 'key1',
help_text:'text1'
},
{
label: 'label2',
key: 'key2',
help_text:'text2'
}
]
You can accomplish this using Joi.alternatives(). Here is a working example: