When trying to validate a json response of this type
{
this_is_an_array : [
{
id : 1234,
name : abcd
},
{
id : 1243
name : bacd
}
]
}
The corresponding schema fails for version13.1.2 but passes for 9.0.0.
module.exports={
schema : joi.object().keys({
this_is_an_array : joi.array([{
id : joi.number().required(),
name : joi.string().required()
}])
})
}
8.6.013.1.21.5.0Define the schema.
Match API response against the defined schema.
Describe your issue here, include schemas and inputs you are validating if needed.
The schema defined above (and below) fails for version 13.1.2 but successfully validates for 9.0.0. Is there any change regarding how the validation of an array of objects is done?
Joi.array() does not allows arguments
The schema should successfully validate against the given response.
It wasn't checked before but was completely ignored. I'm not sure if your issue is a feature request or a bug report.
More like a bug @Marsup . It would have been a feature request if it would have been completely removed. But I see that between two versions, there is a dis-similarity between how things are accomplished.
Well no. You were wrong passing an argument to that function in the 1st place, it didn't accomplish anything, all the new joi does is prevent that.
So, now I cannot pass any arguments to the joi.array() method? If so, am I wrong in using the schema that worked with version 9.0.0 ? We have a couple of other projects using the same thing - having schema structure like that (I actually referred their code).
It never worked, it was strictly equivalent to just having joi.array(), now is not different. You have to provide it to items() for it to work, in 9 and 13 equally.
Ah. Thanks for clearing up. How do I create a valid schema for this json then?
Use Joi.array().items(), found here.
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.
Most helpful comment
Use
Joi.array().items(), found here.