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
What are you trying to achieve or the steps to reproduce ?
When setting a value to be treated as empty (such as null) and setting the required flag, the empty value is not caught by the required validator. The required check in 'Any' only checks explicitly for 'undefined' and does not check any set empty values.
The main goal is to treat null as if it was undefined.
I don't think that's quite the same solution though. Here's my scenario.
I have a list of empty resources where any key that does not have a value is preset to null. So I want to treat null as if it was undefined, so I used the extend method to overwrite a specific type like this:
So this should work according the documentation for empty.
"Considers anything that matches the schema to be empty (undefined)"
If I were to make null invalid I would have to do this everywhere I wanted to make a key required.
Joi.string().invalid(null).required()
I think anything that qualifies as empty should be treated the exact same way as if it was undefined as per the documentation. If not then the documentation should be updated to reflect this scenario.
Context
What are you trying to achieve or the steps to reproduce ?
When setting a value to be treated as empty (such as null) and setting the required flag, the empty value is not caught by the required validator. The required check in 'Any' only checks explicitly for 'undefined' and does not check any set empty values.
The main goal is to treat null as if it was undefined.
Which result you had ?
Returns with no errors.
What did you expect ?
Expected 'myKey' to be treated as an empty value the same as 'undefined'
The text was updated successfully, but these errors were encountered: