swagger-api / swagger-api/swagger-codegen

[SPRING][SPRING-MVC] Bug - Wrong SubType generated field name + not match @JsonProperty name

Open
#12,172 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

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.