Код: Выделить всё
RequestDTOКод: Выделить всё
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes({@JsonSubTypes.Type(value = ARequestDTO.class, name = "A")})
@Schema(oneOf = {ARequestDTO.class})
public sealed interface RequestDTO permits ARequestDTO {
String type();
}
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "subType")
@JsonSubTypes({
@JsonSubTypes.Type(value = DRequestDTO.class, name = "D"),
@JsonSubTypes.Type(value = CRequestDTO.class, name = "C")
})
@Schema(oneOf = {CRequestDTO.class, DRequestDTO.class})
sealed interface ARequestDTO extends RequestDTO permits CRequestDTO, DRequestDTO {
String type();
String subType();
}
record CRequestDTO(String type, String subType) implements ARequestDTO {}
record DRequestDTO(String type, String userId, String subType) implements ARequestDTO {}
Код: Выделить всё
{
"paths": {
"/private/api/v1/test/as": {
"post": {
"requestBody": {
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/RequestDTO"
}
]
}
}
},
"required": true
}
}
}
},
"components": {
"schemas": {
"ARequestDTO": {
"required": [
"subType"
],
"type": "object",
"discriminator": {
"propertyName": "subType"
},
"allOf": [
{
"$ref": "#/components/schemas/RequestDTO"
},
{
"type": "object",
"properties": {
"subType": {
"type": "string"
}
}
}
],
"oneOf": [
{
"$ref": "#/components/schemas/CRequestDTO"
},
{
"$ref": "#/components/schemas/DRequestDTO"
}
]
},
"CRequestDTO": {
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/ARequestDTO"
},
{
"type": "object",
"properties": {
"type": {
"type": "string"
},
"subType": {
"type": "string"
}
}
}
]
},
"DRequestDTO": {
"type": "object",
"allOf": [
{
"$ref": "#/components/schemas/ARequestDTO"
},
{
"type": "object",
"properties": {
"type": {
"type": "string"
},
"userId": {
"type": "string"
},
"subType": {
"type": "string"
}
}
}
]
},
"RequestDTO": {
"required": [
"type"
],
"type": "object",
"properties": {
"type": {
"type": "string"
}
},
"discriminator": {
"propertyName": "type"
},
"oneOf": [
{
"$ref": "#/components/schemas/ARequestDTO"
}
]
}
}
}
}
Подробнее здесь: https://stackoverflow.com/questions/790 ... ic-api-doc