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
{{ message }}
Repository navigation
Polymorphic fields on polymorphic parents don't get correct oneOf docs generatedΒ #2597
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 :)
Activity
aykborstelmann commentedon Jun 5, 2024
As already mentioned in #2614:
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#resolveSubtypesinModelResolver:1542does create theAnnotatedTypewith (implicitly)resolveAsRef=false.Thus the ref is never set and thus
resolvedSchema.get$ref() == nullisfalseinPolymorphicModelConverter.java:79and nooneOfsare resolved as expected.An easy fix would be:
at the start of PolymorphicModelConverter#resolve.
bnasslahsen commentedon Jun 16, 2024
@aykborstelmann,
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 :)
Polymorphic fields on polymorphic parents don't get correct oneOf docβ¦
Polymorphic fields on polymorphic parents don't get correct oneOf docβ¦