swagger-api / swagger-api/swagger-codegen
[JAVA] [Jersey2] Erroneous conflict detection with grand-parent in generated model
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
- 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
- Conflict detection: https://github.com/swagger-api/swagger-codegen/blob/8e4adef5053d5390a3e10fb0fe77384541a85d4c/modules/swagger-codegen/src/main/java/io/swagger/codegen/languages/AbstractJavaCodegen.java#L1050-L1051
parentModelassignment: https://github.com/swagger-api/swagger-codegen-generators/blob/64abd533b25358e403afd544121d5115ed8f822b/src/main/java/io/swagger/codegen/v3/generators/DefaultCodegenConfig.java#L290
Could it be that the issue is that the parentModel assignment should loop up the class hierarchy?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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