OpenAPITools / OpenAPITools/openapi-generator
[Bug] Golang generator should use tags as package names
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 (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
Golang generator should generate multiple packages similar to java operator.
Package should be based on the tags:
Currently generating open API for golang will end up with errors related to duplicates.
For example generating this API will create +30 errors in methods and structs duplication:
https://github.com/Apicurio/apicurio-registry/blob/2.0.0.Final/app/src/main/resources-unfiltered/META-INF/resources/api-specifications/registry/v2/openapi.json#L2952-L2983
openapi-generator version
master and 5.1.1
OpenAPI declaration file content or url
Generation Details
openapi-generator-cli generate -i openapi.json -g go --package-name srsdata -p="generateInterfaces=true" -o ./api
Steps to reproduce
- Generate API from spec
- Generated code will not compile because of many duplicated elements
Suggest a fix
After checking implementation I think there is reasonable way to fix it:
- Work on merging model placement https://github.com/OpenAPITools/openapi-generator/issues/2752
- When tags are present (non default tags) their names should be used as package names to prevent duplicates.
I'm happy contribute this change considering it is something that is valid for golang and openapi gen community.
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
Use the linked OpenAPI declaration and the provided openapi-generator command as the reproduction entry point. Inspect the Go generator and the context of issue #2752; done means the generated API uses tag-based packages and compiles without duplicate methods or structs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100