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

Usage of "when" for conditional validations #60

Open
ManuSevenval opened this issue Nov 9, 2018 · 2 comments
Open

Usage of "when" for conditional validations #60

ManuSevenval opened this issue Nov 9, 2018 · 2 comments
Labels

Comments

@ManuSevenval
Copy link

Thanks for your great library!

I am wondering if it would be possible to define conditional validation rules in a json schema, since I used this feature a lot with Joi.

Taken from their examples page:

const schema = {
    a: Joi.valid('a', 'b', 'other'),
    other: Joi.string()
        .when('a', { is: 'other', then: Joi.required() }),
};

Can such conditional validation rules be expressed via a static schema with enjoi?

Thanks!

@tlivings
Copy link
Owner

You should be able to do this with custom types.

@ManuSevenval
Copy link
Author

@tlivings
could you please give me a short code example how to accomplish this by using custom types with enjoi? thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants