swagger-api / swagger-api/swagger-codegen

[JAVA] [Jersey2] Erroneous conflict detection with grand-parent in generated model

Open
#11,873 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Mustache
Stars
17.8k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Description

The conflict detection defined in JavaClientCodeGen (could also apply to other libraries) does not consider grand-parent models initially which causes inconsistent naming of class fields.

With the example provided further down, the output java files have the following two field definitions:

From the generated src/main/java/io/swagger/client/model/CallbackBody.java

  @JsonProperty("fieldDefinedOnChildAndGrandParent")
  private String fieldDefinedOnChildAndGrandParent = null;

From the generated src/main/java/io/swagger/client/model/AnotherCallbackBody.java

  @JsonProperty("fieldDefinedOnChildAndGrandParent")
  private String anotherCallbackBodyFieldDefinedOnChildAndGrandParent = null;
Swagger-codegen version

1.0.35 (swagger-codegen-generators-1.0.35-20220726.195331-5.jar)

Swagger declaration file content or url

See gist here: https://gist.github.com/cooltea713705/d4c6c1cd59447e9ebb11555b24812b15

Command line used for generation

From IDE with the 64e27b7b9734ab87b985350886f408d66f3f3fcd version of io.swagger.codegen.v3.cli.SwaggerCodegen with arguments: generate -l java --library jersey2

Steps to reproduce
  1. Generate code with the command line provided above.
Related issues/PRs

N/A (could not find an issue with the mention of grandparent which matched the issue described here).

Suggest a fix/enhancement

Could it be that the issue is that the parentModel assignment should loop up the class hierarchy?

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

Read the conflict-detection code in modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java and the parentModel assignment in swagger-codegen-generators/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java. Reproduce the issue with the linked gist using the Java Jersey2 generation command, then verify that generated CallbackBody.java and AnotherCallbackBody.java use consistent field naming across the grand-parent hierarchy.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.