OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Golang] Enum names collide
Nobody has claimed this yet.
- 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?
- 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 EDIT: enumClassPrefix helps. PR #21897 adds a testcase for it to proof it workingMachineState 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).
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)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the OpenAPI declaration and testcase referenced in PR #21897, then inspect how the Go generator handles inline and non-inline enum names. Confirm the duplicate constants reproduce a compilation failure and compare the result with the existing enumClassPrefix behavior; done means generated Go code compiles without redeclaration errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100