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
It seems that when having polymorphic types that contain attribute that are of polymorphic type themselves the generated docs bail on describing it with the oneOf schema.
Given the structure
Seems to generate the correct definitions if the AbstractChild class is used in the controller directly but it doesn't generate a ref to be used in ParentType1.
Seems different from #2575 since after downgrading to 2.3.0 the behaviour is the same.
To Reproduce
Steps to reproduce the behaviour:
Using
org.springframework.boot:3.2.5
org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0
Have a abstract class parent that has two implementation. If one the the implementations uses an abstract child class field The definition for the Child class will not show it polymorphic but only as the base class with the field from the base class only.
Assuming the abstract base class is named AbstractChild and it's implementation are ChildType1 and ChildType2 I get the output:
If verified that this is indeed a bug, I am willing to propose a solution.
While digging through the code, I found that this is because io.swagger.v3.core.jackson.ModelResolver#resolveSubtypes in ModelResolver:1542 does create the AnnotatedType with (implicitly) resolveAsRef=false.
Thus the ref is never set and thus resolvedSchema.get$ref() == null is false in PolymorphicModelConverter.java:79 and no oneOfs are resolved as expected.
An easy fix would be:
if (type.getParent() != null) {
type.setResolveAsRef(true);
}
at the start of PolymorphicModelConverter#resolve.
Thanks for your investigation.
The workaround creates regressions for test on spring-boot-starter-hateoas andspring-boot-starter-data-rest.
You can run the tests to double check.
I have added a fix for it, let's see how it goes :)
Hello
Describe the bug
It seems that when having polymorphic types that contain attribute that are of polymorphic type themselves the generated docs bail on describing it with the oneOf schema.
Given the structure
Seems to generate the correct definitions if the AbstractChild class is used in the controller directly but it doesn't generate a ref to be used in ParentType1.
Here is a sample repo showcasing the issue: https://github.com/rsescu/springdoc-nested-oneof-issue
Seems different from #2575 since after downgrading to 2.3.0 the behaviour is the same.
To Reproduce
Steps to reproduce the behaviour:
Using
org.springframework.boot:3.2.5
org.springdoc:springdoc-openapi-starter-webmvc-ui:2.5.0
Have a abstract class parent that has two implementation. If one the the implementations uses an abstract child class field The definition for the Child class will not show it polymorphic but only as the base class with the field from the base class only.
Assuming the abstract base class is named AbstractChild and it's implementation are ChildType1 and ChildType2 I get the output:
Expected behavior
I would expect the output for the nested child to have a oneOf schema definition. It just contains a reference to the base class definition now.
Repo https://github.com/rsescu/springdoc-nested-oneof-issue
The text was updated successfully, but these errors were encountered: