OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
22.01k stars 6.6k forks source link

[REQ] Typescript-axios : Serialize array/multivalue parameters as repeat params, not CSV #18367

Open TheGeekPharaoh opened 7 months ago

TheGeekPharaoh commented 7 months ago

Is your feature request related to a problem? Please describe.

I have a defined OpenApi spec with a PUT method that takes an array of Strings as one of its request body parameters. The server that is accepting the request expects the parameters to be passed like:

param=Value1&param=Value2&param=Value3

The typescript-axios generator, however, serializes the request body parameters for an Array to a CSV format. As a result, the server receives a value like:

param=Value1%2CValue2%2CValue3

As a result, the parameters are not being deserialized and read properly on the server side

Describe the solution you'd like

A configuration parameter that would allow the Array to be serializes as a multi-valued parameter for both query parameters or form body parameters

Halu89 commented 6 months ago

Hi, if I'm not mistaken, you should be able to accomplish this behavior via the axios configuration, specifically via the paramsSerializer option:

axios.get('/myController/myAction', {
  params: { storeIds: [1,2,3] },
  paramsSerializer: {
    indexes: null, // no brackets at all
  }
)
// /myController/myAction?storeIds=1&storeIds=2&storeIds=3

Source: https://stackoverflow.com/a/76517213

darkbasic commented 3 months ago

That's not true: paramsSerializer works with axios but not with the typescript-axios generator (despite passing an axios instance with paramsSerializer).

darkbasic commented 3 months ago

What you're looking for is the explode parameter: https://swagger.io/docs/specification/serialization/