You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
Given the Attached YAML file which is an OAS3 schema with:
a schema Animal of type object which may be oneOf Cat or Dog
Animal having 2 properties, one for Genus and one for Species
Animal having a discriminator on a propertyName of AnimalType
Animal having a property named AnimalType for the discriminator
The AnimalType discriminator having a mapping for both Cat and Dog
The AnimalType property within Animal being defined with an enumeration for CAT and DOG
Cat being an Animal has an allOf reference back to Animal
Dog being an Animal has an allOf reference back to Animal
When using the openapi code generator to create Java code
Then the openapi generator encounters a StackOverflowError:
Exception in thread "main" java.lang.StackOverflowError
at org.apache.commons.lang3.StringUtils.isBlank(StringUtils.java:298)
at org.apache.commons.lang3.StringUtils.isNotBlank(StringUtils.java:327)
at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2957)
at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2934)
at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2959)
at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2944)
Due to not excluding child/parent references which have already been touched during code generation.
In this case the generator identifies the following:
Create an Animal which is of type Cat.
Cat is an Animal so we must include all of Animal
-- Animal is one of Cat or Dog. Start with Cat
--- Cat is an Animal so we must include all of Animal
---- ...
Instead, the OneOf should be effectively ignored in favor of the allOf references.
The oneOf delaration identifies a downward view of polymorphism where we are looking from a parent to a child. AllOf reverses that view and looks from the child to the parent.
Using oneOf would be sufficient if oneOf caused all properties defined on the "parent" to be inherited by the child (i.e. the child is generated to extend the parent). Reading the spec implies (at least to me) that this is not the expected behavior.
Using allOf would be sufficient if the spec did not require the oneOf and a discriminator to properly deserialize requests into the API based on the discriminator property.
openapi-generator version
This has been identified in the 4.3 and 5.0 family of code generators.
Bug Report Checklist
Description
Given the Attached YAML file which is an OAS3 schema with:
When using the openapi code generator to create Java code
Then the openapi generator encounters a StackOverflowError:
Exception in thread "main" java.lang.StackOverflowError
at org.apache.commons.lang3.StringUtils.isBlank(StringUtils.java:298)
at org.apache.commons.lang3.StringUtils.isNotBlank(StringUtils.java:327)
at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2957)
at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2934)
at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2959)
at org.openapitools.codegen.DefaultCodegen.addProperties(DefaultCodegen.java:2944)
Due to not excluding child/parent references which have already been touched during code generation.
In this case the generator identifies the following:
Create an Animal which is of type Cat.
-- Animal is one of Cat or Dog. Start with Cat
--- Cat is an Animal so we must include all of Animal
---- ...
Instead, the OneOf should be effectively ignored in favor of the allOf references.
The oneOf delaration identifies a downward view of polymorphism where we are looking from a parent to a child. AllOf reverses that view and looks from the child to the parent.
Using oneOf would be sufficient if oneOf caused all properties defined on the "parent" to be inherited by the child (i.e. the child is generated to extend the parent). Reading the spec implies (at least to me) that this is not the expected behavior.
Using allOf would be sufficient if the spec did not require the oneOf and a discriminator to properly deserialize requests into the API based on the discriminator property.
openapi-generator version
This has been identified in the 4.3 and 5.0 family of code generators.
OpenAPI declaration file content or url
see: https://gist.github.com/polydectes/b64c7ea89d391b8f003193082304717e for example YAML file
This Gist has been linted by the latest release of the OpenAPI SwaggerEditor.
Generation Details
generated using Maven plugin
using generic moustache templates.
Steps to reproduce
calling "mvn clean compile" will cause the generation failure.
Related issues/PRs
Possible associated issue: #7414
Suggest a fix
The code generator for Java should either:
or
The text was updated successfully, but these errors were encountered: