Joi validation does not support modification of existing object keys.
I am using Joi validation for parent and child classes. The validation for the parent is the base validation for all children, but each child has specific restrictions or additional fields. I want to be able to just take my parent Joi object and be able to modify existing keys to fit certain restrictions.
//Declare base class with an array at most 10 elements
const parent = {
myArray: Joi.array().max(10)
}
//Now declare child with minimum 1 array value
const child = parent.append({
foo: Joi.string(),
myArray: Joi.array().min(1).required()
})
The above code works as expected - meaning the child object does not keep the .limit(10) restriction applied to the parent. But, I want it such that it does. I'm sure append is not the right function to use here, but I am not sure of how to do this. I want my resulting child validation to look like:
const child = {
foo: Joi.string(),
myArray: Joi.array().max(10).min(1).required()
}