OpenAPITools / OpenAPITools/openapi-generator

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

Open
#19,394 3 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

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)?
  • 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 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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Go generator and the supplied OpenAPI YAML parameter definition, then reproduce generation using the reported v7.8.0 behavior. Trace how array default values become Go declarations. Done means the generated default uses valid Go slice syntax with the string values preserved, with regression coverage for this specification.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.