OpenAPITools / OpenAPITools/openapi-generator

[BUG] [Go] [Java] [Python] Duplicate models generated when there are circular references between specs

Open
#6,926 2 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Go Client: Java Client: Python 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?
    Yes
  • Have you validated the input using an OpenAPI validator (example)?
    Yes. Spec is valid.
  • What's the version of OpenAPI Generator used?
    5.0.0 SNAPSHOT and 4.3.1
  • Have you search for related issues/PRs?
    https://github.com/OpenAPITools/openapi-generator/issues/2701
  • What's the actual output vs expected output?
    Duplicate models with _2 suffix generated in go, 2 suffix in java. I have tested this in java and python and found the same issue.
Description

Models generated twice with same content when there are circular references between 2 specs
Issue occurs in Go, Java and Python languages.
Eg: model_complex_node_slice.go and model_complex_node_slice_2.go
ComplexNodeSlice.java and ComplexNodeSlice2.java

openapi-generator version

4.3.1 and 5.0.0 SNAPSHOT

OpenAPI declaration file content or url

https://gist.github.com/shylasrinivas/af9312c27f6c2a2d99d91c4c2c0323a1

Command line used for generation

openapi-generator generate -g go -i ~/testyamls/linked_list.yaml -o ~/testyamls/test

Related issues/PRs

https://github.com/OpenAPITools/openapi-generator/issues/2701

Suggest a fix

Based on https://github.com/OpenAPITools/openapi-generator/issues/2701 it seems the latest swagger parser should have fixed the issue. However, even with 5.0.0 SNAPSHOT version of openapi-generator which is using a newer swagger parser version (2.0.20) I am still seeing this issue. Any help is appreciated.

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 with the linked OpenAPI declaration at the provided gist and reproduce the issue using the shown openapi-generator command, checking Go, Java, and Python output. Compare the duplicate model files and review related issue #2701. Done means circular references between the two specs no longer generate duplicate models or suffixed names.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, java, openapi, python
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.