orval icon indicating copy to clipboard operation
orval copied to clipboard

Add support for CSV/explode=false query parameters "styles"

Open ashb opened this issue 1 year ago • 3 comments
trafficstars

There is a feature of OpenAPI 3 that lets you change the style of how repeated parameters are specified https://spec.openapis.org/oas/v3.0.3#parameterStyle and https://spec.openapis.org/oas/v3.0.3#style-examples

The particular use case I have is to set explode=false to have CSV parameters rather than multiple query params.

Minimal spec file:

{
  "info": {
    "title": "My API",
    "version": "1.0.0"
  },
  "openapi": "3.0.3",
  "paths": {
    "/test/": {
      "get": {
        "parameters": [
          {
            "in": "query",
            "explode": false,
            "name": "parameter",
            "required": true,
            "schema": {
              "items": {
                "type": "string"
              },
              "type": "array"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  }
}

When called with multiple params this should result in ?parameter=a,b,c but it always/only produces ?parameter=a&parameter=b&parameter=c.

Tested with version 6.25.0

ashb avatar Mar 27 '24 11:03 ashb

Note there also how arrays should be handled according to OpenApi spec

color=blue&color=black&color=brown

But Orval will do

color[]=blue&color[]=black&color[]=brown

Which I've never seen mentioned in the OpenApi spec. Which I guess is fine if we could just turn it off.

programm-ingovals avatar Jun 11 '24 15:06 programm-ingovals

@programm-ingovals that is an axios feature that can be configured by adding the request key to the options parameter or the output override object:

request: {
    paramsSerializer: {
      indexes: null
    }
  }

austin-agronick avatar Jun 27 '24 00:06 austin-agronick

@programm-ingovals that is an axios feature that can be configured by adding the request key to the options parameter or the output override object:

request: {
    paramsSerializer: {
      indexes: null
    }
  }

Thanks, will check that out.

programm-ingovals avatar Jun 27 '24 08:06 programm-ingovals

i think fix by #1580 so related.

soartec-lab avatar Aug 30 '24 03:08 soartec-lab

I close this issue. When you use axios as a client, use paramsSerializer. and when you use fetch as a client, it can be controlled by the explode property in OpenAPI.

soartec-lab avatar Sep 01 '24 08:09 soartec-lab