OpenAPITools / openapi-generator

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (v2, v3)
https://openapi-generator.tech
Apache License 2.0
22.03k stars 6.6k forks source link

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

Open ctreatma opened 3 months ago

ctreatma commented 3 months ago

Bug Report Checklist

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 https://github.com/OpenAPITools/openapi-generator/pull/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
wing328 commented 3 months ago

in java (and properly php) abstract codegen, we need to call https://github.com/OpenAPITools/openapi-generator/blob/master/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java#L1256 (a new function) to have better handling of default value in array (e.g. array of enum string)

we may need to leverage the same function in the abstract go codegen.