OpenAPITools / OpenAPITools/openapi-generator
[BUG][Java][Spring Boot] inheritance not working as in Openapi specification described.
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
- What's the version of OpenAPI Generator used?
- Have you search for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Bounty to sponsor the fix
Description
I try to use the Open API specification 3.0.2 to generate an API that uses inheritance.
My reference is inheritance and I try to make use of the Polymorphism.
When I do it as described the reference to the parent type is not used and a non-existing class is referenced.
Additional there are unused classes generated DogAllOf.java and CatAllOf.java that are never used.
openapi-generator version
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>4.3.0</version>
</plugin>
OpenAPI declaration file content or url
Command line used for generation
./mvn clean generate-sources
Steps to reproduce
Executed with AdoptOpenJDK11.0.4
git clone git@github.com:viesure/openapi-generator-inheritance.git
cd openapi-generator-inheritance
./mvnw clean compile
To see the compile error.
I created the workaround branch that uses only the parent type as a reference and this seems to work, but I could not find a definition in the Open API specification that you should do this.
Related issues/PRs
https://github.com/OpenAPITools/openapi-generator/issues/1685
This is the one that came closest to my problem. But is using a different approach to Add the model to the API.
Suggest a fix
Depending on if it is a spec definition example on my side, giving a better example spec for an inheritance? I was not to find one within the generator.
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 reproduction repository and its src/main/resources/api/openapi.yaml, then run ./mvnw clean compile to inspect the generated Java compilation error. Compare the generated inheritance model classes, including DogAllOf.java and CatAllOf.java, with the OpenAPI inheritance example; done means the generated project compiles without references to nonexistent classes and does not contain unused inheritance classes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi, spring-boot
- Domain
- api, backend-api-design
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100