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
Currently, Joi only allows validating the unknown keys of an object using a regexp. While a good solution, it does adapt to more complex use-cases that would be better served by a Joi object.
For example, for email or uuid-like keys, I need to put a regex. This is sad as native validation already exists in Joi for these use-cases.
I would propose accepting as first argument a Joi string validator, while keeping the current behavior for compatibility.
The result would be: Joi.object().pattern(Joi.string().email(), Joi.any())
The text was updated successfully, but these errors were encountered:
I've been thinking about doing this for a long while now. While less efficient than a regexp, it would be more legible.
Although I would say it doesn't necessarily need to be a string, like in many other cases in joi, anything that validates without error could be considered a match.
Although I would say it doesn't necessarily need to be a string
Yeah, within an object you could have a key that is a number for example, there's also the question of things like Map and Set with how the key could be something like an object or array instead of just a primitive.
Currently, Joi only allows validating the unknown keys of an object using a regexp. While a good solution, it does adapt to more complex use-cases that would be better served by a Joi object.
For example, for email or uuid-like keys, I need to put a regex. This is sad as native validation already exists in Joi for these use-cases.
I would propose accepting as first argument a Joi string validator, while keeping the current behavior for compatibility.
The result would be:
Joi.object().pattern(Joi.string().email(), Joi.any())
The text was updated successfully, but these errors were encountered: