-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Conditional rule based on value of another key #194
Comments
I propose the following syntax: Example var schema = {
a: Joi.string(),
b: Joi.any().when('a', Joi.string().regex(/^value$/), Joi.required())
}; If the value of |
👍 I really would love this for schema "tables" /cc @nvcexploder |
When do you evaluate 'a'? Before or after 'a' itself is evaluated? What if 'a' is '5' and you want it to be a number? should conversion rules apply? This is hard. |
My thought was to evaluate 'a' twice. In the schema itself var schema = {
a: Joi.string().regex(/^value$/)
}; If that does not return null, then add |
Add it to |
Partially covered by #260 |
Woot! Thanks! |
Reopening this since the fix didn't address neither #166 nor #188 var Joi = require('joi');
var schema = {
a: Joi.any().when('b', { is: 5, then: Joi.required(), otherwise: Joi.optional() }),
b: Joi.any()
};
var thing = {
b: 5
};
var validate = Joi.validate(thing, schema);
// returns
{
error: null,
value: {
b: 5
}
} I expected an error saying that |
No description provided.
The text was updated successfully, but these errors were encountered: