OpenAPITools / OpenAPITools/openapi-generator
[BUG][Spring] fields are duplicated in parallel subclasses if schema-mapping is used
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
My model uses inheritence. I have a base-class "DemoRoot" which has two derived subclasses "DemoSubclass1" and "DemoSubclass2". These classes have one common field "type" (the discriminator) and one specific field - "unwantedProperty" in "DemoSubclass1" and "subclass2_property" for "DemoSubclass2".
However, my real API has more fields and classes, but I was able to track it down to a minimum example which is also attached to the problem report.
So far everything is right. The problem arises as I need to use schemaMapping as I need a hand-written version of DemoSubclass1. Now - as required - no java-File for DemoSubclass1 is produced, but suddenly you find all the fields on DemoSubclass1 (which is "unwantedProperty") in all the paralled subclasses (DemoSubclass2 in my case).
This is definitely wrong. I tried to remove the schema-mapping rule from the pom-file, then the code is right. (But as I said: I definitly need schema-mapping.)
openapi-generator version
version 7.6.0
OpenAPI declaration file content or url
Generation Details
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 with the attached problem-demo.tar.gz and its pom-file schemaMapping rule, then inspect the generated DemoSubclass1 and DemoSubclass2 classes for the duplicated fields. Compare generation with and without schemaMapping; done means DemoSubclass2 contains only its own fields while the handwritten DemoSubclass1 remains unmapped.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100