We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
It looks like stripUnknown doesn't works for nested object when the nested object has invalid fields.
stripUnknown
const schema = Joi.object({ foo: Joi.string(), nested: Joi.object({ bar: Joi.string(), }) }) const options = { abortEarly: false, allowUnknown: true, presence: 'required', stripUnknown: true, } const input = { foo: null, // invalid value unknown: 'unknown', nested: { bar: null, // invalid value unknown: 'unknown', } } const { value } = schema.validate(input, options) // { foo: null, nested: { bar: null, unknown: 'unknown' } }
nested.unknow is still present
nested.unknow
It should have been "stripped"
The text was updated successfully, but these errors were encountered:
If validation fails, joi will just stop what it was doing and return an error.
Sorry, something went wrong.
unless the abortEarly option has been set to false.
abortEarly
false
In this case everything work as expected, the validation fail but continue and strip unknown fields
const Joi = require('joi'); const schema = Joi.object({ foo: Joi.string(), nested: Joi.object({ bar: Joi.string(), }) }) const options = { abortEarly: false, allowUnknown: true, presence: 'required', stripUnknown: true, } const input = { foo: null, // invalid value unknown: 'unknown', nested: { bar: 'bar', // valid value unknown: 'unknown', } } const { value } = schema.validate(input, options) // { foo: null, nested: { bar: 'bar' } }
There is definitely an inconsistent behavior with nested objects and stripUnknown when abortEarly is false. Please re-open @hueniverse
hueniverse
Successfully merging a pull request may close this issue.
Support plan
Context
What are you trying to achieve or the steps to reproduce?
It looks like
stripUnknown
doesn't works for nested object when the nested object has invalid fields.What was the result you got?
nested.unknow
is still presentWhat result did you expect?
It should have been "stripped"
The text was updated successfully, but these errors were encountered: