swagger-api / swagger-api/swagger-codegen
[SPRING][SPRING-MVC] Bug - Wrong SubType generated field name + not match @JsonProperty name
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Description
When using allOf, and SubType and parent type has a field with same name, the field name is generated wrong.
Swagger-codegen version
It is a regression, was working OK until 3.0.34.
Since 3.0.35 the field name is concatenation of the SubType name + field name.
Swagger declaration file content or url
`
schemas:
Animal:
type: object
properties:
name:
type: string
legs:
type: integer
age:
type: integer
Cat:
allOf:
- $ref: "#/components/schemas/Animal"
- type: object
properties:
name:
type: string
`
Generated java code is Animal:
`public class Animal implements Serializable {
private static final long serialVersionUID = 1L;
@JsonProperty("name")
private String name = null;
@JsonProperty("legs")
private Integer legs = null;
@JsonProperty("age")
private Integer age = null;
...`
Generate java code Cat:
`public class Cat extends Animal implements Serializable {
private static final long serialVersionUID = 1L;
@JsonProperty("name")
private String catName = null;
public Cat catName(String catName) {
this.catName = catName;
return this;
}
...`
Command line used for generation
mvn clean generate-sources
Steps to reproduce
mvn clean generate-sources
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
Start by running mvn clean generate-sources with the Animal and Cat schema from the issue, then compare the generated Java classes between versions 3.0.34 and 3.0.35. Trace the model-name generation path responsible for Cat's catName field; done means the field name matches @JsonProperty("name") without breaking the inherited Animal field.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100