Skip to content

[BUG] [GOLANG] Generating client with array query parameters with defaults #21077

Open
@gwd

Description

@gwd

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator (example)?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

I've got some query parameters that are arrays of strings, and have default values listed:

         {
            "description": "Data to include in response",
            "explode": false,
            "in": "query",
            "name": "include",
            "schema": {
              "default": [
                "userstats"
              ],
              "description": "Data to include in response",
              "items": {
                "enum": [
                  "word",
                  "userstats"
                ],
                "type": "string"
              },
              "type": [
                "array",
                "null"
              ]
            }
          }
        {
            "description": "Data to include in response.  'analysis' requires a userid to be specified.",
            "explode": false,
            "in": "query",
            "name": "include",
            "schema": {
              "default": [
                "title",
                "text"
              ],
              "description": "Data to include in response.  'analysis' requires a userid to be specified.",
              "items": {
                "enum": [
                  "cguid",
                  "title",
                  "text",
                  "analysis"
                ],
                "type": "string"
              },
              "type": [
                "array",
                "null"
              ]
            }
          },

I would think "default values" means "values that the server will use if nothing is provided"; but the generator seems to try to fill in these values. Unfortunately it generates syntactically invalid Go code:

	if r.include != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "include", r.include, "form", "csv")
	} else {
		var defaultValue []string = [userstats] // BUG: Should be {"userstats"}
		r.include = &defaultValue
	}
	if r.include != nil {
		parameterAddToHeaderOrQuery(localVarQueryParams, "include", r.include, "form", "csv")
	} else {
		var defaultValue []string = ["title","text"] // BUG: Should be {"title","text"}
		r.include = &defaultValue
	}
openapi-generator version
$ openapi-generator version
7.12.0
OpenAPI declaration file content or url

https://api-dev.laleolanguage.com/openapi.json

Generation Details
openapi-generator generate -i https://api-dev.laleolanguage.com/openapi.json -g go -o apiclient
Steps to reproduce

Run the above command; the resulting code will not compile.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions