-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Labels
bugBug or defectBug or defectsupportQuestions, discussions, and general supportQuestions, discussions, and general support
Milestone
Description
- node version: 6.3.0
- joi version:8.4.2
I am trying to validate two keys that cannot appear together. Both keys are optional, and are set to be empty when they are empty strings. I am currently using .without() to forbid one key when the other is present, but when the reference key is an empty string, the validation fails with the following error:
" "person" conflict with forbidden peer "group" "
It seems as if the .without() check is happening before the .empty(''), and is registering the reference key as an empty string instead of undefined.
Is there a better way to handle this, or do you have any suggestions?
var jsonApiInput = {
person: '',
group: 1,
active: true
};
var schema = Joi.object().keys({
person: Joi.number().integer().empty(''),
group: Joi.number().integer().empty(''),
active: Joi.boolean().empty('')
}).required().without('person', ['group']);
//output: " "person" conflict with forbidden peer "group" "
//expected: {
group: 1,
active: true
}
schema.validate( jsonApiInput, schema, function (err, result) {
if (!err) {
console.log(result);
} else {
console.log(err);
}
});
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugBug or defectBug or defectsupportQuestions, discussions, and general supportQuestions, discussions, and general support