-
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
Context
- node version: 6.11.5
- joi version: 13.0.1
- environment: browser
- used with: webpack 3 and joi-browser 13.0.1
What are you trying to achieve or the steps to reproduce ?
I'm using custom labels for error messages using the following schema
schema = Joi.object().keys({
a: Joi.boolean(),
b: Joi.when('a', {
is: true,
then: Joi.string().empty('').allow(null),
}).label('Label b'),
c: Joi.when('a', {
is: true,
then: Joi.string().empty('').allow(null),
}).label('Label c'),
d: Joi.when('a', {
is: true,
then: Joi.string().empty('').allow(null),
}).label('Label d'),
})
.or('b', 'c', 'd');
schema.validate({a: true, b: 1})Which result you had ?
"child "Label b" fails because ["b" must be a string]"What did you expect ?
"child "Label b" fails because ["Label b" must be a string]"If I want the label to be correct either in the Joi.string() validation or in the .or() validation I need to override twice the key name for each child.
schema = Joi.object().keys({
a: Joi.boolean(),
b: Joi.when('a', {
is: true,
then: Joi.string().empty('').allow(null).label('Label b'),
}).label('Label b'),
c: Joi.when('a', {
is: true,
then: Joi.string().empty('').allow(null).label('Label c'),
}).label('Label c'),
d: Joi.when('a', {
is: true,
then: Joi.string().empty('').allow(null).label('Label d'),
}).label('Label d'),
})
.or('b', 'c', 'd');Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
breaking changesChange that can breaking existing codeChange that can breaking existing codebugBug or defectBug or defect