openapi-generator icon indicating copy to clipboard operation
openapi-generator copied to clipboard

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

Open TheGeekPharaoh opened this issue 1 year ago • 3 comments

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

TheGeekPharaoh avatar Apr 11 '24 21:04 TheGeekPharaoh

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

Halu89 avatar Jun 02 '24 16:06 Halu89

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

darkbasic avatar Aug 04 '24 10:08 darkbasic

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

darkbasic avatar Aug 04 '24 12:08 darkbasic