AndrewKeig / express-validation

express-validation is an express middleware that validates a request and returns a response with errors; if any of the configured validation rules fail.
MIT License
393 stars 85 forks source link

Pass joi's options when validating schema #128

Closed YonatanKiron closed 1 year ago

YonatanKiron commented 4 years ago

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

asafel commented 4 years ago

This is really needed! Thanks @YonatanKiron

YonatanKiron commented 4 years ago

@AndrewKeig Any update?

papandreou commented 2 years ago

~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 commented 2 years ago

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

papandreou commented 1 year ago

I guess this isn't really going anywhere, so I'll close it. Feel free to reopen if you get back to it!