I’m using Joi to validate an environment variable that can be either ‘true’ or ‘false’ as strings. The variable is optional, and if it is undefined, I want to set it to ‘true’ by default. Here is the Joi rule I wrote:
Joi.string().valid('true', 'false').default('true')
but validation fails when ENV is missing with this error:
must be one of [true, false]
How can I modify the Joi schema to accept the environment variable as either ‘true’ or ‘false’, and default to ‘true’ if it is not provided?