orval
orval copied to clipboard
String array in query appends [] to the query variable name
What are the steps to reproduce this issue?
- Describe a GET request with query parameter that is an array of strings
- Inspect Orval client will send the request with
name[]=value
instead ofname=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
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.
Dealing with the same issue :/
I managed to find a solution using axios' paramsSerializer
config field
import qs from "qs"
...
{
paramsSerializer: (params) =>
qs.stringify(params, { arrayFormat: "comma", indices: false }),
}
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(...)
}
}
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.