Open Marsup opened 3 years ago
Hmm… yeah, this does seem strange for hapi to expose Validate
for run-time validations. Eg. there is no way to localize the generated error.
Ideally, hapi would use the passed validator. Maybe the correct solution is to allow validators to provide a "nothing-allowed" schema method? Maybe registered something like this?
server.validator(Joi, {
empty: Joi({}).allow(null)
});
Eg. there is no way to localize the generated error.
keep the false as it is and do some special treatment during the validation, but it has imho one major drawback, it's going to be hard to throw joi-compatible errors
I wonder if this drawback can be addressed by users using their validator rather than the convenient false
shorthand, if it's important to them. If that is the case, then I think the second option ("keep the false as it is and do some special treatment") would be a nice way to handle it. We may be able to go a step further and give some basic guarantees about the error format for this case.
Support plan
Context
How can we help?
I'm starting an issue here, but I don't really know if it's up to hapi or hapi-swagger to fix the issue, I'd say hapi, but you may disagree. There is currently an error thrown from hapi-swagger that looks like this:
The root cause is coming from this line. When hapi-swagger is checking that all the schemas are joi objects, this one is not, so the throw is totally expected.
Now I see 2 solutions to that :
allow(null)
part if we're not sure that we're getting a joi object back from the validatorWhat do you think?