Is there a way to check the dynamic key names in the Joi schema?
1 answer
You will want to use the method Joi
object().pattern()
. This is specifically for checking objects with unknown keys.
To match one or more datatypes on the same key, you will need alternatives().try()
(or just pass an array of Joi
types).
So the rule that suits your needs would be:
Joi.object().pattern(/^/, Joi.alternatives().try(Joi.string(), Joi.number(), Joi.boolean()))
+3
source to share