simonplend / express-json-validator-middleware

Express middleware for validating requests against JSON schema

Home Page:https://npm.im/express-json-validator-middleware

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stop on first error

vacekj opened this issue · comments

commented

Originating from #15
While it may provide a performance benefit (not having to validate after the first error is found), from my experience the user usually wants to work with errors from all req properties.

If we implement this feature, I would like to make it configurable by introducing an options object for the Validator instance, and also make it off by default.

Thoughts?

I agree. This should be configurable. The current behavior should remain as the default. This will be an opt-in feature.

(I prefer exiting as early as possible. I prefer assuming that once the user investigates the error, they will ensure their API call provides correct input, as stated in the relevant docs.)

This is configurable by passing an Ajv options object when initialising the middleware:

const validator = new Validator(ajvOptionsObject);

The allErrors option allows you to configure Ajv to return all validation errors. By default this option is false, meaning that Ajv will return after the first error is encountered.

Closing this issue as by my understanding it is now the default behaviour.