-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Context
const schema = Joi.object({
Strengths: Joi.object().pattern(
Joi.string().valid(Joi.ref('$StrengthOptions')),
Joi.number().integer().greator(0).allow(0)
).default({})
})What are you trying to achieve or the steps to reproduce ?
Trying to validate that an object only has keys from a specific set. However the set is dynamic. The valid function works if just using a static list i.e ['coding', 'reviewing'].
const strengthNames: string[] = *Call to get names of possible strengths*
const options: Joi.ValidationOptions = {
abortEarly: false,
convert: true,
allowUnknown: false,
context: {
StrengthOptions: strengthNames
}
}
Joi.validate(
someObj,
schema,
options,
(errors: ValidationError, value:any) => {
if(errors){
console.log(error);
}
}
);Which result you had ?
{
message: '"coding" is not allowed',
path: [ 'Strengths', 'coding' ],
type: 'object.allowUnknown',
context: { child: 'coding', value: 3, key: 'coding', label: 'coding' }
}
What did you expect ?
"coding" should be allowed it is in the strengthNames array.
context of the error should also contatin valids: [ array ]
type of error should be 'any.allowOnly'
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugBug or defectBug or defect