orval icon indicating copy to clipboard operation
orval copied to clipboard

String array in query appends [] to the query variable name

Open gunnartorfis opened this issue 3 years ago • 3 comments

What are the steps to reproduce this issue?

  1. Describe a GET request with query parameter that is an array of strings
  2. Inspect Orval client will send the request with name[]=value instead of name=value in the query

What happens?

Request will be with incorrect query param.

What were you expecting to happen?

The query param name shouldn't be appended with [].

What versions are you using?

Operating System: macOS Big Sur 11.6 Package Version: Always latest, running in CI pipeline Browser Version: Safari 15.0

gunnartorfis avatar Jan 08 '22 12:01 gunnartorfis

Seems like it's by design: https://github.com/anymaniax/orval/blob/f3b2d4f6cead82a15e1486c03ab1533d5de716ea/src/core/getters/array.ts#L27

May I ask why? The documentation we're using doesn't generate the query param with [], neither does our Golang API server stub generator.

gunnartorfis avatar Jan 11 '22 10:01 gunnartorfis

Dealing with the same issue :/

fr3fou avatar Mar 12 '22 17:03 fr3fou

I managed to find a solution using axios' paramsSerializer config field

import qs from "qs"
...
{
    paramsSerializer: (params) =>
          qs.stringify(params, { arrayFormat: "comma", indices: false }),
}

fr3fou avatar Mar 12 '22 19:03 fr3fou

Is there any update on this improvement? I have followed @fr3fou approach so far. Please note that today, paramsSerializer is an object and the function is performed as follows:

paramsSerializer: {
        serialize: (params) => {
            return qs.stringify(...)
        }
      }

Mistes974 avatar Feb 08 '23 06:02 Mistes974

Also having the same issue, any updates? Would love to get this fixed as I'm working with over 100 API endpoints and multiple require array parameters.

katerinatiddy avatar Sep 28 '23 20:09 katerinatiddy