swagger-api / swagger-api/swagger-codegen
Regression: Swagger CodeGen generates duplicate fields in child DTOs
Nobody has claimed this yet.
- Dominant language
- Mustache
- Stars
- 17.8k
- Forks
- 6k
- PR merge metrics
- No merged PRs in 30d
Description
Regression v2.3.1 to v2.4.41
Problem
-
In v2.3.1 when Swagger CodeGen generates a child Java DTO class that inherits the fields of a parent class, the child class does not contain new fields. Instead it re-uses the existing fields inherited from the parent. This is the correct behaviour.
-
In v2.4.41 when Swagger CodeGen generates a child Java DTO class that inherits the fields of a parent class, the child class contains extra fields that duplicate the existing fields of the parent. This is incorrect behaviour. It causes JSON (de-)serializers to throw an exception due to duplicate fields having the same name.
Background
In OpenHAB one of its 450 odd third party integrations uses Swagger CodeGen to convert an API YAML file to respective Java API DTOs. We were using CodeGen v2.3.1 but we recently attempted to upgrade to CodeGen v2.4.41 -- but failed.
The API and the respective YAML have API fields name 'type' and CodeGen v2.3.1 creates them them in the DTO and applies the @SerializedName("type") annotation to them. When attemting to use CodeGen v2.4.41 we started seeing GSON exceptions that the DTO "declares multiple JSON fields named 'type'".
I am wondering what happened, and how to fix it?
See this https://github.com/openhab/openhab-addons/issues/16779 for more..
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
No source file or test is named. Start by reproducing Swagger CodeGen 2.4.41 with the API YAML and compare the generated child Java DTO with the 2.3.1 output, then review the linked OpenHAB issue for context. Done means inherited parent fields are not emitted again and the generated DTO can be serialized without duplicate JSON field errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100