fix: Add Ajv type coercion for Express 5 query parameter compatibility#1388
Conversation
f8d5bcc to
f21fc58
Compare
JamieMagee
left a comment
There was a problem hiding this comment.
LGTM!
If you want, I think you can also simplify some of the defensive code. definitions-1.0.0.js can be simplified from const force = req.query.force === true || req.query.force === 'true' to const force = req.query.force === true and definitions.js can be simplified from const matchCasing = !(request.query.matchCasing === 'false' || request.query.matchCasing === false) to const matchCasing = request.query.matchCasing === true
f21fc58 to
d6d4868
Compare
Primitives like null, numbers, and booleans are now coerced to strings, so tests need to use objects/arrays to trigger type validation errors.
|
Fixed the failing tests. With |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Description
This PR addresses query parameter type handling changes introduced by Express 5. (see #1340)
Express 5 introduced a breaking change where req.query is now a read-only getter instead of a writable property. This means that custom middleware can no longer reassign
req.queryto convert types, causing schema validation to fail when expecting any type but a string.The solution uses Ajv's built-in
coerceTypesfeature to handle type conversion during schema validation.Changes made
1 - Enabled Ajv type coercion: allows for automatic type conversion of query string values;
2 - Removed custom querystring middleware and its tests: no longer needed since Ajv handles type coercion;