-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Description
When created specification for polymorph class model structure there is unnecessary "type: object" property preceding "allOf" in all subclasses (Text and Video in following example):
"schemas": {
"Message": {
"required": [
"type"
],
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": [
"Text",
"Video"
]
}
},
"discriminator": {
"propertyName": "type",
"mapping": {
"Text": "#/components/schemas/Text",
"Video": "#/components/schemas/Video"
}
}
},
"Text": {
"required": [
"text",
"type"
],
"type": "object", # redundant
"allOf": [
{
"$ref": "#/components/schemas/Message"
},
{
"type": "object",
"properties": {
"text": {
"type": "string"
}
}
}
]
},
"Video": {
"required": [
"previewUrl",
"type",
"videoUrl"
],
"type": "object", # redundant
"allOf": [
{
"$ref": "#/components/schemas/Message"
},
{
"type": "object",
"properties": {
"videoUrl": {
"type": "string"
},
"previewUrl": {
"type": "string"
},
"text": {
"type": "string"
}
}
}
]
}
}
OpenApi spec contains no such property for subclasses.
This extra property leads to errors on api client generation with SwagGen tool.
Sample test controller used:
package test.org.springdoc.api.app5
import com.fasterxml.jackson.annotation.JsonSubTypes
import com.fasterxml.jackson.annotation.JsonTypeInfo
import io.swagger.v3.oas.annotations.media.DiscriminatorMapping
import io.swagger.v3.oas.annotations.media.Schema
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController
enum class MessageType {
Text, Video
}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
@JsonSubTypes(
JsonSubTypes.Type(value = Text::class, name = "Text")
,JsonSubTypes.Type(value = Video::class, name = "Video")
)
@Schema(
discriminatorMapping = [
DiscriminatorMapping(value = "Text", schema = Text::class),
DiscriminatorMapping(value = "Video", schema = Video::class)
]
)
abstract class Message(val type: MessageType)
data class Text(
val text: String
): Message(MessageType.Text)
data class Video(
val videoUrl: String,
val previewUrl: String,
val text: String?
): Message(MessageType.Video)
@RestController
@RequestMapping("/test")
class HelloController {
@GetMapping
fun index(): Message? = null
}
moved from springdoc/springdoc-openapi#452
soberich, miensol, DEPE3A, benjaminbillet, MaksAleks and 7 morebkz7abc, DEPE3A, MaksAleks, sumitsarkar and julia-afk
Metadata
Metadata
Assignees
Labels
No labels