-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
breaking changesChange that can breaking existing codeChange that can breaking existing codebugBug or defectBug or defect
Milestone
Description
Hello...
I'm having a difficult time trying to validate an array which includes an object of nested properties. Should this work?
I've looked through the Joi tests for this case where Jo.array().includes(nested object), but can not see an example there.
https://github.com/hapijs/joi/blob/v5.1.0/test/array.js#L93
https://github.com/hapijs/joi/blob/v5.1.0/test/array.js#L109
https://github.com/hapijs/joi/blob/v5.1.0/test/array.js#L301
None of the tests seem to test a nested object included in an array ... so perhaps this should not work?
var objectSchema = {
prop1: Joi.string().required(),
prop2: Joi.string().required(),
prop3: Joi.object({
nestprop1: Joi.string().required(),
nestprop2: Joi.string().required()
}).required()
}
var arraySchema = Joi.array().includes(Joi.object(objectSchema))
var value = [{
prop1: 'test1',
prop2: 'test2',
prop3: {
nestprop1: 'nesttest1',
nestprop2: 'nesttest2'
}
}]
Joi.validate(value, arraySchema, function (err, value) {
*results in ... error* = array at position 0 fails because prop3 is not allowed
})
Strangely Joi is reporting 'prop3' is not allowed, when in the schema it's defined as required.
Thank you
-M
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
breaking changesChange that can breaking existing codeChange that can breaking existing codebugBug or defectBug or defect