express-openapi-validator icon indicating copy to clipboard operation
express-openapi-validator copied to clipboard

[Query] How to incorporate custom validations

Open ericxinzhang opened this issue 4 years ago • 0 comments

Is your feature request related to a problem? Please describe.

openapi-validator is doing a great job on request validation against the openapi spec file. However there are validations rules cannot be defined in the spec file. For example, there are two query string parameter min and max and we want to validate that min <= max.

Of course I can do such validation separately, throw error and handle in the error handler, but then the validation errors won't be merged into openapi validation and return in one go.

Describe the solution you'd like

When initialised, the validator allows an array of customer validators to be specified. The customer validator implements some interface like (req: Request) => ValidationErrorItem.

Describe alternatives you've considered Nil

Additional context

Even if the feature is accepted it will take time to implement, but I do need to implement such cross field validation immediately. Any suggestions are appreciated. Thank you.

ericxinzhang avatar May 10 '21 08:05 ericxinzhang