OpenAPITools / OpenAPITools/openapi-generator

[Bug] Golang generator should use tags as package names

Open
#9,500 2 comments 0 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

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

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

Generation Details
openapi-generator-cli generate -i openapi.json -g go --package-name srsdata -p="generateInterfaces=true" -o ./api
Steps to reproduce
  1. Generate API from spec
  2. 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:

I'm happy contribute this change considering it is something that is valid for golang and openapi gen community.

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

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.