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

.without(), runs before .empty() #947

Closed
anderson-tyler opened this issue Jul 14, 2016 · 2 comments
Closed

.without(), runs before .empty() #947

anderson-tyler opened this issue Jul 14, 2016 · 2 comments
Assignees
Labels
bug Bug or defect support Questions, discussions, and general support
Milestone

Comments

@anderson-tyler
Copy link

anderson-tyler commented Jul 14, 2016

  • 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);
    }
});

@Marsup
Copy link
Collaborator

Marsup commented Jul 24, 2016

I have no idea what you're trying to accomplish here. The keys you specified in the without are not even defined.

@Marsup Marsup added the support Questions, discussions, and general support label Jul 24, 2016
@Marsup Marsup self-assigned this Jul 24, 2016
@anderson-tyler
Copy link
Author

It should make more sense now. I edited my original comment to fix the typo.

@Marsup Marsup added the bug Bug or defect label Jul 24, 2016
@Marsup Marsup added this to the 9.0.4 milestone Jul 24, 2016
@Marsup Marsup closed this as completed in 4d10dd2 Jul 24, 2016
@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 support Questions, discussions, and general support
Projects
None yet
Development

No branches or pull requests

2 participants