openapi-backend
openapi-backend copied to clipboard
Fix query coercion issue
Fixed #554
Note that query parameters are coerced just fine by Ajv validators. But parameters.query
is never assigned back to original request that is passed down to handlers.
However, this might be not desirable behaviour by default. Maybe it is better to add additional option on OpenAPIBackend initialization to allow modifying data during validation like this:
const api = new OpenAPIBackend({
definition: "./open-api-spec.json",
validate: true,
**modifyReqData: true**,
ajvOpts: {
coerceTypes: true
}
...
})
Pls let me know what you think.
@sabeslamidze I agree it'd be better to put this behind an option flag. 👍 Generally the less processing we make to the passed request object the better IMO.
@anttiviljami don't you think if your schema says it must be a number
, your code should receive it as a number? Why would I need to parse numbers (and to other types) manually in every handler?
@sabeslamidze @anttiviljami @ziflex I understand that you want to keep original request as is. However, having a field of type number in code and then in run-time it is a string is not ok. AJV has an option called 'coerceTypes'. You can support that option and that will solve the issue, no? When can I expect this to be merged?
@ydayagi no, I meant that I want this library to parse numbers for me. I do not want to parse params in every handler.