Description
Describe the bug
If a controller returning a response containing an interface or class that is annotated with:
@JsonTypeInfo(include= JsonTypeInfo.As.WRAPPER_OBJECT, use=JsonTypeInfo.Id.NAME)
@JsonSubTypes({
@JsonSubTypes.Type(value = Dog.class, name = "dog"),
})
Then, the documentation generated does not contain the schemas of child classes.
How to reproduce
git clone https://github.com/didjoman/springdoc-polymorphism-issue-v1.6.10
Run the application (spring boot).
Run curl --location --request GET 'http://localhost:8080/doc' --header 'Content-Type: application/json'
Expected behavior
The json representation of the Cat and Dog (subtypes of Animal class) schemas should be returned:
{
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition",
"version": "v0"
},
"servers": [
{
"url": "http://localh",
"description": "Generated server url"
}
],
"paths": {
"/test": {
"get": {
"tags": [
"basic-controller"
],
"summary": "get",
"description": "Provides an animal.",
"operationId": "get",
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/Cat"
},
{
"$ref": "#/components/schemas/Dog"
}
]
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Animal": {
"type": "object",
"description": "Represents an Animal class."
},
"Cat": {
"type": "object",
"description": "Represents a Cat class.",
"allOf": [
{
"$ref": "#/components/schemas/Animal"
},
{
"type": "object",
"properties": {
"speed": {
"type": "integer",
"format": "int32"
}
}
}
]
},
"Dog": {
"type": "object",
"description": "Represents a Dog class.",
"allOf": [
{
"$ref": "#/components/schemas/Animal"
},
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer",
"format": "int32"
}
}
}
]
}
}
}
}
Actual behavior
Only the Animal (parent class) schema is described:
{
"openapi": "3.0.1",
"info": {
"title": "OpenAPI definition",
"version": "v0"
},
"servers": [
{
"url": "http://localh",
"description": "Generated server url"
}
],
"paths": {
"/test": {
"get": {
"tags": [
"basic-controller"
],
"summary": "get",
"description": "Provides an animal.",
"operationId": "get",
"responses": {
"200": {
"description": "OK",
"content": {
"*/*": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/Cat"
},
{
"$ref": "#/components/schemas/Dog"
}
]
}
}
}
}
}
}
}
},
"components": {
"schemas": {
"Animal": {
"type": "object",
"description": "Represents an Animal class."
},
"Cat": {
"type": "object",
"description": "Represents a Cat class.",
"allOf": [
{
"$ref": "#/components/schemas/Animal"
},
{
"type": "object",
"properties": {
"speed": {
"type": "integer",
"format": "int32"
}
}
}
]
},
"Dog": {
"type": "object",
"description": "Represents a Dog class.",
"allOf": [
{
"$ref": "#/components/schemas/Animal"
},
{
"type": "object",
"properties": {
"name": {
"type": "string"
},
"age": {
"type": "integer",
"format": "int32"
}
}
}
]
}
}
}
}
Additional context
The issue started to occur from version 1.5.8 onwards. From 1.5.8 to 1.6.9 (inlcuded) there was a nullPointer in the logs.
Since 1.6.10, the NullPointerException is fixed, but the documentation is still incorrect (not generating subtypes documentation).
See also the same demo using SpringDoc 1.5.7 that worked: https://github.com/didjoman/springdoc-no-polymorphism-issue-v1.5.7