Skip to content
Advertisement

Nested object in Joi schema

I’ve defined validation schema via Joi with nested object in AWS value:

JavaScript

Then I put my schema to config module

JavaScript

I’ve added inside .env file the next value for AWS variable:

JavaScript

but I got the next error message after starting nest:

JavaScript

typeof process.env.AWS returns a string and Joi doesn’t understand that he should parse it, maybe I need to add some in validationOptions or I miss something. How can I solve it?

Advertisement

Answer

As of Joi v16.0.0, object and array string coercion is no longer available as a built-in option.

You can replicate this functionality by extending Joi. For example:

JavaScript

Then use JoiCustom in your schema:

JavaScript
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement