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 · 4 comments
Open

Express 5 req.query immutable #969

MarcelHoogesteger opened this issue Sep 11, 2024 · 4 comments

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()
 })

@SophieDel
Copy link

SophieDel commented Dec 10, 2024

+1

I am facing the same problem. I have remarked that req.query does not inherit from Object.prototype anymore ([Object: null prototype]), I dunno whether or not it can be useful to fix this problem.

Is it planned to fix this bug...?

Thank you !

@cdimascio
Copy link
Owner

cdimascio commented Dec 28, 2024

thanks all. i've started a new branch express-5-support to tackle support for express 5.
Without any changes 63 of 414 unit tests fail. with @jacobshirley workaround in place, there are 29 remaining tests to resolve.

seeking community to help resolve the remaining issues

@SF97
Copy link
Contributor

SF97 commented Dec 30, 2024

Hello

With #1036 the number goes down to 15, due to a fix I've made in some tests.

With the routing syntax changes, I don't think there's an easy way to have tests that guarantee both express 4 and express 5 compatibility, but we can think of that after all the tests route have its matching syntax fixed. Right now, I still haven't found a way to have the same wildcard tests for express 5

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

5 participants