-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
[BUG][JAVA] Generator does not generate inheritance when first element of allOf is not a ref #3523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think you have the wrong project. The code looks to be generated using swagger-codegen, not openapi-generator. |
You're right, I updated the post with a snippet of the openapi-codegen generated class (same problem though). |
It looks like inheritance is broken for several languages with 4.0.3. |
Whilst the spec states that the 'allOf' relationship does not imply a hierarchy: > While composition offers model extensibility, it does not imply a hierarchy between the models. > To support polymorphism, the OpenAPI Specification adds the discriminator field. Unfortunately this does not make sense for many existing use cases, that were supported by older versions of the generator. Therefore, I've restored the older behavior, specifically in the case that only a single possible parent schema is present. I think a more complete solution would generate interfaces for the composed schemas, and mark the generated class as implementing these. fixes issue 2845, and fixes issue OpenAPITools#3523
…ts (#3771) Whilst the spec states that the 'allOf' relationship does not imply a hierarchy: > While composition offers model extensibility, it does not imply a hierarchy between the models. > To support polymorphism, the OpenAPI Specification adds the discriminator field. Unfortunately this does not make sense for many existing use cases, that were supported by older versions of the generator. Therefore, I've restored the older behavior, specifically in the case that only a single possible parent schema is present. I think a more complete solution would generate interfaces for the composed schemas, and mark the generated class as implementing these. fixes issue 2845, and fixes issue #3523
Bug Report Checklist
Description
When declaring a schema as a composition of classes using allOf, having the first element of the allOf (which is meant to be the main inherited class extended in my Java subclass) not being a reference to a pre-existing class, it is simply ignored by the generator.
openapi-generator version
Swagger-editor and openapi-codegen 4.1.0
OpenAPI declaration file content or url
The Swagger-editor generated Example2 class writes:
The openapi-codegen generated Example2 class writes:
Expected output would have been (from openapi-codegen):
Command line used for generation
"C:\Program Files\Java\jdk1.8.0_72\bin\java" -jar swagger-codegen-cli.jar generate -i myDefs.yml -l java --library resttemplate -DsupportJava6=true -DdateLibrary=legacy -o out2/myproject --api-package com.my.project.client.api --model-package com.my.project.client.model -DhideGenerationTimestamp=true -DdisableApiModelAnnotations=true
Suggest a fix
Having the same behaviour as when the non pre-existing class is set as more than the first occurrence in the allOf and is generated as an interface, that is copying the attributes of the non pre-existing class in the subclass.
The text was updated successfully, but these errors were encountered: