Skip to content

[BUG] [Golang] Enum names collide #21895

@sruehl

Description

@sruehl

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • 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

When generating enums in golang the values of the enums are put in a global context (see #21623 for reference). To give a better understanding look like it works in Java for example: Suppose we have two enums MachineState and PetState. If both of those have a enum called SOLD this will work in Java just fine as those dodge each other as they are contained within their enums. In Golang it dumps those 2 context in the global context and you get a compile issue (redeclaration). EDIT: enumClassPrefix helps. PR #21897 adds a testcase for it to proof it working

openapi-generator version

master branch

OpenAPI declaration file content or url

contained in PR #21897

Generation Details
  • Inline enums in PR but is the same for normal non inline enums
Steps to reproduce

define two enums using the same constants

Related issues/PRs

#21623
#21897

Suggest a fix

implement a option prefix_enums which will put the model name in front (e.g. MachineSold, PetSold)

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