-
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
Concat'ing arrays of primitive types: (OK)
var s1 = Joi.array().includes(Joi.number());
var s2 = Joi.array().includes(Joi.string());
var schema = s1.concat(s2);
Joi.validate([1,"a"], schema);
// works fine. allow array of mixed of number and stringConcat'ing arrays of objects: (OK)
var s1 = Joi.array().includes(Joi.object().keys({
"x": Joi.any()
}));
var s2 = Joi.array().includes(Joi.object().keys({
"y": Joi.any()
}));
var schema = s1.concat(s2);
Joi.validate([{
"x":1,
"y":2
}], schema);
// works fine. allow array of objects that contain both "x" and "y" propertiesConcat'ing objects of arrays of objects: (not OK)
var s1 = Joi.object().keys({
"prop": Joi.array().includes(Joi.object().keys({
"x": Joi.any()
}))
});
var s2 = Joi.object().keys({
"prop": Joi.array().includes(Joi.object().keys({
"y": Joi.any()
}))
});
var schema = s1.concat(s2);
Joi.validate([{
"prop": []
}], schema);
// works fine
Joi.validate([{
"prop": [{
"x": 1
}]
}], schema);
// Uh-oh, prop at position 0 fails because x is not allowedI can work around it by concat'ing the inner object first then include it into a schema of arrays
Is there a way to deep concat like this using built-in Joi.concat?
Thanks
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
breaking changesChange that can breaking existing codeChange that can breaking existing codebugBug or defectBug or defect