-
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
Extending a schema #710
Comments
FYI, if the object is top level, you can use a regular object as opposed to a Joi.object() But this looks like a bug. I would think the desired behavior is what @bsiddiqui is looking for
|
test case it('alters existing keys', function (done) {
var a = Joi.object({ a: 1 });
var b = a.keys({ a: 2 });
b.validate({ a: 1 }, function (err, value) {
expect(err).to.exist();
b.validate({ a: 2 }, function (err2, value2) {
expect(err2).to.not.exist();
done();
});
});
}); |
Or alternatively, it should give an error when trying to alter the key |
Is there a question here ? Looks like you put the question and answers in the same post. |
@Marsup I put what I'd expect the result to be but that's now how Joi is working for me var base = Joi.object().keys({
a: Joi.number(),
b: Joi.string()
});
var extended = base.keys({
a: Joi.string()
});
Joi.validate({ a: 'hello' }, extended)
// => ValidationError: child "a" fails because ["a" must be a number] I would expect |
Is there a way to overwrite a key in the schema or add to the validation parameter?
Overwrite a key:
Add a parameter:
The text was updated successfully, but these errors were encountered: