Skip to content

Commit

Permalink
reproduce: springwolfGH-730: reproduce json object with inheritance (…
Browse files Browse the repository at this point in the history
…option 2)
  • Loading branch information
timonback committed May 3, 2024
1 parent d6690f9 commit ad1b171
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,11 @@
description = "LMS payload model",
type = "LearningEvent",
defaultValue = "test",
additionalProperties = Schema.AdditionalPropertiesValue.TRUE
additionalProperties = Schema.AdditionalPropertiesValue.TRUE,
// discriminatorProperty = "eventKey" // does not matter

// Option 2:
// allOf = {ParentEventDto.class}
)
allOf = {ParentEventDto.class})
@NoArgsConstructor
@Data
@EqualsAndHashCode(callSuper = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "eventKey", visible = true)
@JsonSubTypes({@JsonSubTypes.Type(value = LearningEvent.class, name = "LearningEvent") // ,
// @JsonSubTypes.Type(value = ExamplePayloadDto.class, name = "ExamplePayloadDto") // omitted in demo
/*,@JsonSubTypes.Type(value = ParentEventDto.class, name = "events") */ // omitted in demo
/*,@JsonSubTypes.Type(value = ParentEventDto.class, name = "events") */
// omitted in demo
})
@JsonIgnoreProperties(ignoreUnknown = true)
@Schema(
Expand All @@ -33,10 +34,10 @@
@JsonDeserialize()
public class ParentEventDto {
// Option 1: with extra property: eventKey
@Schema(
description = "this is the eventKey used as JsonTypeInfo and discriminatorProperty with visible=true",
requiredMode = NOT_REQUIRED)
private String eventKey;
// @Schema(
// description = "this is the eventKey used as JsonTypeInfo and discriminatorProperty with visible=true",
// requiredMode = NOT_REQUIRED)
// private String eventKey;

@Schema(description = "this is event type", example = "event Type", requiredMode = NOT_REQUIRED)
private String eventType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -668,17 +668,81 @@
},
"io.github.springwolf.examples.kafka.consumers.LearningEvent": {
"type": "object",
"properties": {
"courseType": {
"type": "string",
"description": "the course type",
"examples": [
"ILT"
]
"description": "LMS payload model",
"examples": [
{
"courseType": "ILT",
"eventKey": "string",
"eventType": "event Type",
"firstName": "test"
}
],
"required": [
"courseType"
],
"allOf": [
{
"$ref": "#/components/schemas/io.github.springwolf.examples.kafka.consumers.ParentEventDto"
},
{
"type": "object",
"properties": {
"courseType": {
"type": "string",
"description": "the course type",
"examples": [
"ILT"
]
}
}
}
],
"x-json-schema": {
"$schema": "https://json-schema.org/draft-04/schema#",
"allOf": [
{
"description": "parent Event DTO",
"properties": {
"eventKey": {
"type": "string"
},
"eventType": {
"description": "this is event type",
"type": "string"
},
"firstName": {
"description": "the first name of the candidate",
"type": "string"
}
},
"required": [
"eventKey"
],
"type": "object"
},
{
"properties": {
"courseType": {
"description": "the course type",
"type": "string"
}
},
"type": "object"
}
],
"description": "LMS payload model",
"required": [
"courseType"
],
"type": "object"
}
},
"io.github.springwolf.examples.kafka.consumers.ParentEventDto": {
"discriminator": "eventKey",
"type": "object",
"properties": {
"eventKey": {
"type": "string",
"description": "this is the eventKey used as JsonTypeInfo and discriminatorProperty with visible=true"
"type": "string"
},
"eventType": {
"type": "string",
Expand All @@ -695,28 +759,22 @@
]
}
},
"description": "LMS payload model",
"description": "parent Event DTO",
"examples": [
{
"courseType": "ILT",
"eventKey": "string",
"eventType": "event Type",
"firstName": "test"
}
],
"required": [
"courseType"
"eventKey"
],
"x-json-schema": {
"$schema": "https://json-schema.org/draft-04/schema#",
"description": "LMS payload model",
"description": "parent Event DTO",
"properties": {
"courseType": {
"description": "the course type",
"type": "string"
},
"eventKey": {
"description": "this is the eventKey used as JsonTypeInfo and discriminatorProperty with visible=true",
"type": "string"
},
"eventType": {
Expand All @@ -729,7 +787,7 @@
}
},
"required": [
"courseType"
"eventKey"
],
"type": "object"
}
Expand Down

0 comments on commit ad1b171

Please sign in to comment.