I am using Joi for my project server side validation.
I have an array which is populate from database for eg:
let s = ['a','b','c'];
Now I need to check if for a given field the values is within the array s
only. like this:
Joi.object({
value: Joi.string().valid(...s).required()
});
I used Nodejs - Joi Check if string is in a given list as reference, but I keep getting this error:
TypeError: Joi.string(...).valid is not iterable (cannot read property Symbol(Symbol.iterator))
However, when the values are hardcoded, it works perfectly:
Joi.object({
value: Joi.string().valid('a','b','c').required()
});
Any idea how to solve this?