-
-
Notifications
You must be signed in to change notification settings - Fork 505
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
@JsonSubTypes annotation conflicts with @Schema and anyOf #2872
Comments
My understanding is that the allOf annotation comes from swagger-core resolving the Json-annotations https://github.com/swagger-api/swagger-core/blob/master/modules/swagger-core/src/main/java/io/swagger/v3/core/jackson/ModelResolver.java#L1637. I.e., they have implemented it so that the Json-annotation is enough to yield a proper polymorphic OpenAPI schema (but adding a custom Schema annotation is not treated as an override, but they are both rather considered at the same time, which produces an invalid recursive specification). But I definitely see the usecase for letting only the Schema annotation decide the OpenAPI format, and that the Json-annotation is only used to guide the deserialization. This issue looks to ask the same question swagger-api/swagger-core#3677 |
@Mattias-Sehlstedt This is very interesting, thank you for that info. If I leave the The schema still doesn't specify the possible classes though. I updated my sample code to remove the schema annotation and just rely on the json sub type annotations. For the following screenshots, I only changed the spring doc version from 2.6.0 to 2.8.3. Is there something else I'm missing, or is this the new behavior of version 2.8.3? Actual implementation classes listed in schema with version 2.6.0: Array index instead of class name with version 2.8.3: |
The reason for the visualization I have covered in this comment #2867 (comment), and in a later comment in that discussion I given the solution for how you can retain the old way of visualizing while still keeping the springdoc-openapi version update (do note that "the old way of visualizing" in this context implies that you expose a 3.0 OpenAPI specification instead of a 3.1 specification). |
Describe the bug
When I use
@JsonSubTypes
and@Schema(oneOf = {...})
on an interface that has at least one implementation, I get an error when loading the SpringDoc UI and expanding the schema definition for the interface. The schema definition for the implementation also shows anallOf
property even though I haven't configured the schema for any of the implementations.If I remove the
@JsonSubTypes
annotation, everything works.This is similar to #2655.
To Reproduce
I created a simple application:
https://github.com/erbrecht/spring-doc-json-subtypes/tree/master
To reproduce, uncomment the
@JsonSubTypes
annotation inhttps://github.com/erbrecht/spring-doc-json-subtypes/blob/master/src/main/java/org/example/springdocjsonsubtypes/dto/TermDto.java#L8
Expected behavior
I would expect no errors to show up in the spring doc ui.
I would also expect my implementation class NOT to have the
allOf
property defined in the swagger definition.Screenshots
Errors:
"Bad" schema:
"Good" schema:
Additional context
I'm also not seeing a specific class for the implementations in the schema definition. I just see an array index. I do see these defined in previous versions of spring doc, eg 2.6.0. I'm not sure if this is related, but it seemed worth mentioning.
spring doc 2.6.0, no
@JsonSubType
annotation:spring doc 2.6.0, WITH
@JsonSubType
annotation:spring doc 2.8.3, no
@JsonSubType
annotations:spring doc 2.8.3, WITH
@JsonSubType
annotations:The text was updated successfully, but these errors were encountered: