Skip to content

[BUG][Golang][Client] Serialize exploded query params array of type string-array of style form #3386

Description

@grokify

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 the explode keyword

OAS 2.0

collectionFormat: multi
Description : Multiple parameter instances rather than multiple values. This is only supported for the in: query and in: 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:

https://github.com/grokify/go-ringcentral-engage/blob/ad3dfa7513aa494f340b4d8fdac8480fa5191eca/codegen/openapi-spec_v3.0.0.yaml

        - 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:

https://raw.githubusercontent.com/grokify/go-ringcentral-engage/b25d808890958ba5264ace3514878bc00ea8f292/codegen/partial-specs_v2.0.0/openapi-spec_teams.json

          {
            "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:

https://github.com/grokify/go-ringcentral-engage/blob/ad3dfa7513aa494f340b4d8fdac8480fa5191eca/codegen/openapi-generator_command.sh

Steps to reproduce
  1. Build SDK
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions