OpenAPITools / OpenAPITools/openapi-generator

[BUG][GO] Generated client code creates duplicate type names & anonymous interfaces rather than types

Open
#14,235 9 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

Description

I am unable to generate golang client bindings for the lichess public api (https://lichess.org/api). The generated code fails to compile due to duplicate type names being generated. Secondly, in many cases the generated code employs anonymous interface{} for many objects which should instead be defined & named types based on the input description.

Input was validated with https://apidevtools.org/swagger-parser/online

openapi-generator version

6.2.0

OpenAPI declaration file content or url

https://github.com/mikeb26/lichess-go-sdk/blob/285cd412550179208649530859434e3b812cf231/openapi.json

Generation Details
java -jar ./openapi-generator-cli.jar generate -g go -o ./openapi --git-host github.com --git-user-id mikeb26 --git-repo-id lichess-go-sdk -i openapi.json
Steps to reproduce
git clone https://raw.githubusercontent.com/mikeb26/lichess-go-sdk
cd lichess-go-sdk
git checkout 285cd412
rm -rf openapi
make
Related issues/PRs

could not find related PRs

Suggest a fix

It appears there are 2 problems:

  1. in a couple of cases the input re-uses the same type across different api endpoints. an easy fix would be to have the generator prefix the generated type names with the api name. (i did this manually by manually editing the generated code).
  2. the generated code is returning responses with anonymous interface{} types rather than defining a type based on the spec. the input spec. I don't have a guess as to why this is occurring.

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

Reproduce the issue with the referenced openapi.json, the Go generator, and the listed clone, checkout, cleanup, and make commands. Inspect the generated openapi output for duplicate type names and anonymous interface{} responses. Done means the generated Go client compiles and the affected objects have distinct named types.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, openapi
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.