Details
-
Task
-
Resolution: Unresolved
-
P2: Important
-
None
-
None
-
None
-
21
-
Foundation Sprint 129, Foundation Sprint 130
Description
In OpenAPI 2.0, multi-value query parameters were supported using the type: array and the collectionFormat property. For example:
parameters: - name: param in: query type: array collectionFormat: pipes items: type: string
However, collectionFormat was deprecated in OpenAPI 3.0 and and the newer logic revolves around style and explode properties.
See https://swagger.io/specification/#style-values for reference.
For example:
- collectionFormat: csv → style: form, explode: false
- collectionFormat: multi → style: form, explode: true
- collectionFormat: pipes → style: pipeDelimited
- collectionFormat: ssv → style: spaceDelimited
- collectionFormat: tsv ** does not have an alternative anymore.
Note: OAPI 2.0 collectionFormat value is still set in DefaultCodegen.java in openapi-generator-cli-7.12.0 based on isExplode ans style values.
Support for style and explode was added by the openapi team https://github.com/OpenAPITools/openapi-generator/commit/578420cfa93c98c8f590f1154a620c8f4a1b5b45
But the current implementation still relies on the OpenAPI 2.0 collectionFormat value, which is not applicable to OpenAPI 3.0 specifications. This leads to incorrect generated code when using newer serialization styles.
For example, the following OpenAPI 3.1 parameter:
parameters: - in: query name: my_param required: false style: deepObject explode: true # default value is false schema: type: array items: type: string
The default value of collectionFormat is "csv" when not explicitly set in OpenAPI 3.1. As a result the following condition evaluates to true:
} else if (QString("{{collectionFormat}}").indexOf("csv") == 0) {
and this one to false
} else if (QString("{{collectionFormat}}").indexOf("deepObject") == 0) {
This causes the csv block to be executed instead of deepObject block, which leads to incorrect query parameter formatting.
To do: Adjust query parameter generation in api-body.mustache file based on the style and explode values instead of collectionFormat.