Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Express 5 req.query immutable #969

Open
MarcelHoogesteger opened this issue Sep 11, 2024 · 1 comment
Open

Express 5 req.query immutable #969

MarcelHoogesteger opened this issue Sep 11, 2024 · 1 comment

Comments

@MarcelHoogesteger
Copy link

The request parameter mutator is broken when express 5 is used

When you have a query parameter definition for array values, the req.query[key] could not be updated because it is immutable in express 5.

The req.query key values are not parsed by its query parameter definitions in the OpenApi 3 specs

The req.query parameters should be parsed like defined in the OpenApi 3 schema for the query parameter

Example sort query parameter definition:
name: sort
in: query
description: Sort parameter
required: false
style: pipeDelimited
explode: false
schema:
type: array
items:
type: string

req.query = { sort: "name|date"} should be having an array value after parsing: req.query = { sort: ["name", "date"]}, but it remains the same value req.query = { sort: "name|date"}

@jacobshirley
Copy link

+1.

I've implemented an ugly workaround for it by making query mutable:

app.use((req, res, next) => {
        if (req.query)
            Object.defineProperty(req, 'query', {
                writable: true,
                value: { ...req.query },
            })

        next()
 })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants