express-openapi-validator
express-openapi-validator copied to clipboard
The validation process modify the original request
Describe the bug When it validate a query parameter that in the openapi we defined it as an array structured like this:
name: param
in: query
explode: false
schema:
type: array
items:
type: number
example: 11,22,33
allowReserved: true
It converts the query parameters from a string to an array of string, so from 'val1,val2,val3' to ['val1', 'val2', 'val3']. Even if this can be considered useful there are a some situation in which the use of validation middleware should be transparent to the rest of the project.
To Reproduce Express server implementation:
const app = express()
app.use(
OpenApiValidator.middleware({
apiSpec: './openapi.yaml',
}),
)
app.get('/test', (req:Request,res:Response,next:NextFunction)=>{
console.log(req.query)
res.status(204).send()
})
Openapi definition:
/test:
get:
parameters:
- name: param
in: query
explode: false
schema:
type: array
items:
type: number
example: 11,22,33
allowReserved: true
responses:
'204':
description: No Content
Sending a GET to the endpoint <host>/test?param=101,102,103 would result in the console log of { param: [ 101, 102, 103 ] }, instead if we remove the OpenApiValidator.middleware we obtain the log { param: '101,102,103' }.
Actual behavior The request is modified by the validator.
Expected behavior The validator should validate that the string represent a valid array but without changing it in the original request. Or at least should exist an option (that i have not found in the documentation) to get this behaviour.