OpenAPITools / OpenAPITools/openapi-generator
[BUG][Go] bug generating key named "type" into: var type_ TYPE = "default value"
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- [ X] Have you provided a full/minimal spec to reproduce the issue?
- [ X] Have you validated the input using an OpenAPI validator (example)?
- [ X] Have you tested with the latest master to confirm the issue still exists?
- [ X] Have you searched for related issues/PRs?
- [ X] What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
While using generator 7.11.0 i ran into an compile issue. After some investigation openapi-generator 7.11.0 generates go code as:
model_openapi_generator_issue_demo.go: var type_ TYPE = "AA"
while it should have been (or similar):
model_openapi_generator_issue_demo.go: var type_ string = "AA"
openapi-generator version
7.11.0 7.0.0 6.0.0 5.0.0 have the issue, basically i think all of versions from 5.0.0 and up.
Also tried 4.2.1, 4.3.0 and 4.3.1 which do not have the issue (but also don't try to set the default)
OpenAPI declaration file content or url
Generation Details
openapi-generator generate -g go -i "minimal_issue_type_TYPE_20250127.json" -o issue/
Steps to reproduce
Just generate the library, as soon you want to use it and compile against go code it will error on this.
Related issues/PRs
I don't have that info right now, is new issue for me. With testing various versions it seems to show up on any version after 5.0.0.
4.3.1, 4.2.1 do not have the issue (but also do not try to set the default)
Suggest a fix
I tested by replacing the keyword "type" by slightly different word, and then has same issue, see next line.
If i'm change the "type" keyword to "ttype" the folowing code is produced:
var ttype TTYPE = "AA"
again the TTYPE had to be the word "string" (at least to my logic, and compiles with that)
either set the type("string" in this case) directly, or define new TYPE with actual type as "string" in this case.
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 by running the documented openapi-generator command with minimal_issue_type_TYPE_20250127.json and inspect the generated model_openapi_generator_issue_demo.go. Compare the generated declaration for the enum property named type with the expected string type, then verify that the generated Go code compiles. Done means the default value is retained without producing an invalid TYPE declaration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100