Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Alternatives based on a type with only otherwise take precedence over any following one #1151

Closed
Marsup opened this issue Apr 6, 2017 · 0 comments
Assignees
Labels
bug Bug or defect
Milestone

Comments

@Marsup
Copy link
Collaborator

Marsup commented Apr 6, 2017

Context

  • node version: 6.x
  • joi version: 10.4.1
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information:

What are you trying to achieve or the steps to reproduce ?

const schema = Joi.object({
    a: Joi.number(),
    b: Joi.number(),
    c: Joi.number()
        .when('a', { is: 1, otherwise: Joi.number().min(1) })
        .when('b', { is: 1, then: Joi.number().min(1) })
})

schema.validate({
    a: 1,
    b: 1,
    c: 0
});

Which result you had ?

{ error: null, value: { a: 1, b: 1, c: 0 } }

What did you expect ?

An error with child "c" fails because ["c" must be larger than or equal to 1]

@Marsup Marsup added the bug Bug or defect label Apr 6, 2017
@Marsup Marsup self-assigned this Jun 15, 2017
@Marsup Marsup added this to the 10.4.2 milestone Jun 15, 2017
@Marsup Marsup closed this as completed Jun 15, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Bug or defect
Projects
None yet
Development

No branches or pull requests

1 participant