express-validation icon indicating copy to clipboard operation
express-validation copied to clipboard

Pass joi's options when validating schema

Open YonatanKiron opened this issue 5 years ago • 4 comments

Alternatively to https://github.com/AndrewKeig/express-validation/pull/127

The issue is that when you overload the req object with an extra property you will get ValidationError.

E.g.,

Joi.assert(
  Joi.object({body: {}, foo: {}}), 
  Joi.object(parameters.reduce((result, item) => ({ ...result, [item]: Joi.object() }), {})).required().min(1)
)

Will fail.

While:

Joi.assert(
  Joi.object({body: {}, foo: {}}), 
  Joi.object(parameters.reduce((result, item) => ({ ...result, [item]: Joi.object() }), {})).required().min(1),
  {allowUnknown: true}
)

Will success

YonatanKiron avatar Oct 27 '20 12:10 YonatanKiron

This is really needed! Thanks @YonatanKiron

asafel avatar Oct 27 '20 12:10 asafel

@AndrewKeig Any update?

YonatanKiron avatar Nov 05 '20 08:11 YonatanKiron

~Is this addressing the same need as https://github.com/AndrewKeig/express-validation/pull/127?~ Edit: Sorry, you did specify that :sweat_smile:

Please include a test.

papandreou avatar Apr 08 '22 21:04 papandreou

I have to admit that I'm not really a fan of dual-purposing the joi parameter.

papandreou avatar Apr 09 '22 10:04 papandreou