express-openapi-validator
express-openapi-validator copied to clipboard
Coerce types by default for multipart
Is your feature request related to a problem? Please describe. Per validateRequests.coerceTypes we automatically always coerce request query, path params, headers, and cookies.
When we use multipart request body, properties are always sent in string format, thus, without coerceTypes=true, values defines in schema as integers or booleans fail validation.
Describe the solution you'd like Two possible solutions:
- always coerce for multipart request bodies (same as query params and others), because they are always strings
- split
coerceTypesintocoerceTypesandcoerceTypesForMultipart
Describe alternatives you've considered
Setting coerceTypes=true solves the problem, but it affects other request bodies, which I'd want to avoid.
I'd be happy to prepare PR depending on which solution you think is better (and where is the best place to start). Also, is there a workaround to keep coerceTypes only for a particular route?
@aviskase thanks for this issue.
please submit a PR. that will be super helpful. Let's take a variation of approach 2. modify coerceTypes to take an array as an alternative to the boolean. e.g.
coerceTypes: [ 'multipart' ]
coerceTypes: true will continue to have current behavior, that is coerce all request bodies.
similarly, coerceTypes: false will disable this behavior
finally, coerceTypes: [ 'multipart' ] will enable coercion for multiple bodies only