-
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
Joi valid fails, when ref is used with a stripped key. #831
Comments
This is the expected behavior, I can't remember anyone needing this use case, I'll wait see if more people need this. |
Hello there, I just run into this strange "issue" in a similar context when using ScenarioA port range numbers needs to be validated, so let's call them
In order to check So the validation object will look as follows. var Joi = require('joi');
function portValidation () {
return Joi.number().integer().min(1).max(65535);
}
var schema = Joi.object().keys({
port: portValidation().required(),
portmin: portValidation().strip(),
portend: portValidation().greater(Joi.ref('portmin'))
});
console.log(schema.validate(
{ port: "1234", portmin: "1233", portend: "1234" },
{ convert: true }
)); In this scenario Obviously, this scenario can be achieved using the IssueWhen using Number values works OK. { error: null, value: { port: 1234, portend: 1234 } } The issue comes up when the port's properties are String based values. By default, { error:
{ ValidationError: child "portend" fails because ["portend" references "portmin" which is not a number]
at Object.exports.process (/Users/enric/Workspace/testing/joi/node_modules/joi/lib/errors.js:154:19)
at Object._validateWithOptions (/Users/enric/Workspace/testing/joi/node_modules/joi/lib/any.js:629:31)
at Object.validate (/Users/enric/Workspace/testing/joi/node_modules/joi/lib/any.js:644:21)
at Object.<anonymous> (/Users/enric/Workspace/testing/joi/joi-validations.js:13:20)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
at tryModuleLoad (module.js:447:12)
at Function.Module._load (module.js:439:3)
at Module.runMain (module.js:605:10)
isJoi: true,
name: 'ValidationError',
details: [ [Object] ],
_object: { port: '1234', portmin: '1233', portend: '1234' },
annotate: [Function] },
value: { port: 1234, portmin: '1233', portend: '1234' } } But if the var schema = Joi.object().keys({
port: portValidation().required(),
portmin: portValidation(),
portend: portValidation().greater(Joi.ref('portmin'))
}); Another "issue" involves when var schema = Joi.object().keys({
port: portValidation().required(),
portend: portValidation().greater(Joi.ref('portmin')),
portmin: portValidation()
}); Expected ResultNo matter Number or String values are used, the expected behavior should be the same. |
@emoriarty Thanks for the report, but in the future please create your own issue instead of reviving closed ones. |
This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions. |
Joi valid fails, when ref is used with a stripped key. Maybe this is the expected behaviour. I'll let you decide.
What are you trying to achieve or the steps to reproduce ?
Which result you had ?
What did you expect ?
No error, and "a" should have been stripped. Value: { b: 1 }
The text was updated successfully, but these errors were encountered: