Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix
Description
When creating request parameter with exploded form style, the expectation is to have multiple query parameters with the same name, each with a separate value. This is described here:
OAS 3.0
Arrays can be serialized as:
form
–/products?color=blue,green,red
or/products?color=blue&color=green
, depending on theexplode
keyword
OAS 2.0
collectionFormat:
multi
Description : Multiple parameter instances rather than multiple values. This is only supported for thein: query
andin: formData
parameters.
Example:foo=value&foo=another_value
openapi-generator version
4.0.3-SNAPSHOT, 4.1.0-SNAPSHOT
OpenAPI declaration file content or url
This is an issue using a 3.0 and a 2.0 spec but it seems only 3.0 is clear about implementation.
Below are both 3.0 and 2.0 specs. Both validate.
Example 3.0 spec:
- name: user_ids[]
in: query
description: tags to filter by
required: false
style: form
explode: true
schema:
type: array
items:
type: string
2.0.0 spec:
{
"name": "user_ids[]",
"description": "List of user id as team members.",
"in": "query",
"type": "array",
"collectionFormat": "multi",
"required": false,
"items": {
"type": "string"
}
}
Command line used for generation
java -jar openapi-generator-cli.jar generate -i openapi-spec_v3.0.0.yaml -g go -o engagedigital -D packageName=engagedigital
See more here:
Steps to reproduce
- Build SDK
- Examine
CreateTeam
function
The function has a single line for adding the property user_ids[]
instead of using a loop over the array.
if localVarOptionals != nil && localVarOptionals.UserIds.IsSet() {
localVarQueryParams.Add("user_ids[]", parameterToString(localVarOptionals.UserIds.Value(), "multi"))
}
Related issues/PRs
This bug exists in PHP as well: #2292
Suggest a fix
Collection format multi
doesn't do anything when passed to parameterToString()
in the auto-generated path function. It should be handled in the auto-generated path function to check if the variable is a slice, and, if so, call localVarQueryParams.Add()
in a loop for every element of the slice.