You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the scenario above cases 1, 2 and 3 work as expected. However, case 4 demonstrates the issue we would like a solution to. We need to be able to strip out unknown object keys while also validating the values of array items rather than stripping them from the array.
The resolution proposed in #615 was to add a new option flag.
I would argue that the least surprising behavior for an option named stripUnknown would be strip unknown keys but NOT strip items in an array which don't conform to the schema for items of that array. The term "unknown" is specifically misleading in this case because nothing is "unknown" about the invalid email value above.
"when true, unknown keys are deleted (only when value is an object or an array). Defaults to false."
as it only references removing keys not array members.
However, as highlighted in #615 there is disagreement about that that particular option. We can agree to disagree.
Assuming that modifying the behavior of stripUnknown is off the table, I believe the best solution is to add an option named stripUnknownKeys which ONLY strips unknown object keys and still returns validation errors for items in an array which simply have invalid values. The correct behavior for this option would be to remove unknown keys from objects in the array but not the entire objects themselves.
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.
lockbot
locked as resolved and limited conversation to collaborators
Jan 9, 2020
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Context
What I am trying to achieve
Several users want the ability to strip unknown object keys without also stripping array items which do not conform to the valid schema type.
This has been highlighted in #615 as well as #903
Example Scenario:
The result I had
What I expected
In the scenario above cases 1, 2 and 3 work as expected. However, case 4 demonstrates the issue we would like a solution to. We need to be able to strip out unknown object keys while also validating the values of array items rather than stripping them from the array.
The resolution proposed in #615 was to add a new option flag.
I would argue that the least surprising behavior for an option named stripUnknown would be strip unknown keys but NOT strip items in an array which don't conform to the schema for items of that array. The term "unknown" is specifically misleading in this case because nothing is "unknown" about the invalid email value above.
The documentation is also misleading: https://github.com/hapijs/joi/blame/v9.0.0-2/API.md#L142
as it only references removing keys not array members.
However, as highlighted in #615 there is disagreement about that that particular option. We can agree to disagree.
Assuming that modifying the behavior of
stripUnknown
is off the table, I believe the best solution is to add an option namedstripUnknownKeys
which ONLY strips unknown object keys and still returns validation errors for items in an array which simply have invalid values. The correct behavior for this option would be to remove unknown keys from objects in the array but not the entire objects themselves.Desired behavior would look something like:
Output:
Happy to discuss more and help with implementation if this proposal or something similar is accepted.
The text was updated successfully, but these errors were encountered: