OpenAPITools / OpenAPITools/openapi-generator

[REQ] [go-gin-server] place models in different package to prevent circular package references

Open
#2,752 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Enhancement: Feature Server: Go
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Golang doesn't allow packages to have circular references. Currently, the go-gin-server implementation places the model and api definition code in the same package. This makes using models generated from OpenAPI difficult to use outside of the package.

Currently, for example, you can't have the API call a separate database package with a model object as a parameter, because it requires making circular package references.

Describe the solution you'd like

Ideally, there would be the option of having a separate model package from an API package.

Describe alternatives you've considered

The current workaround is either putting all your database code in the generated API objects or replicating the model objects within a separate package (duplicating code).

Additional context

The openapi generator libraries seem to allow for separate package and API names but those parameters are ignored by the go-gin-server generator.

#1931 also discusses this a similar issue

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

Start by inspecting the go-gin-server generator and how its separate package and API name parameters are handled; compare the related discussion in #1931. Done means the generator can place models and API definitions in separate packages so generated code can use external model or database packages without circular references.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, openapi
Domain
api, backend-api-design
Issue type
Feature
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.