Skip to content

[BUG][Go] Invalid code generated for default values of array parameters #19394

@ctreatma

Description

@ctreatma

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?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

Given a parameter of type array with a default value defined, the Go generator produces invalid code:

else {
    var defaultValue []string = [port, virtual_network]
    r.include = &defaultValue
}

A valid form of the above code would look like this:

else {
    var defaultValue []string = []string{"port", "virtual_network"}
    r.include = &defaultValue
}
openapi-generator version

v7.8.0, but this issue was introduced by #15127 and has existed since roughly v7.0.1.

OpenAPI declaration file content or url
  - in: query
    name: include
    schema:
      default:
      - port
      - virtual_network
      items:
        type: string
      type: array
    style: form
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix

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