Skip to content

Commit

Permalink
test(kafka-example): add polymorphism with oneOf to VehicleBase (#1152)
Browse files Browse the repository at this point in the history
  • Loading branch information
sam0r040 authored Jan 17, 2025
1 parent 2d4e611 commit ef4e47a
Show file tree
Hide file tree
Showing 5 changed files with 367 additions and 30 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// SPDX-License-Identifier: Apache-2.0
package io.github.springwolf.examples.kafka.dtos.discriminator;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@NoArgsConstructor
@Data
@AllArgsConstructor
public class EnginePower {
private int hp;
private int torque;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
@JsonSubTypes.Type(value = VehicleGasolinePayloadDto.class, name = "VehicleGasolinePayloadDto"),
})
@Schema(
oneOf = {VehicleElectricPayloadDto.class, VehicleGasolinePayloadDto.class},
subTypes = {VehicleElectricPayloadDto.class, VehicleGasolinePayloadDto.class},
discriminatorProperty = "vehicleType",
discriminatorMapping = {
Expand All @@ -30,4 +31,6 @@ public abstract class VehicleBase {

private String powerSource;
private int topSpeed;

private EnginePower enginePower;
}
Original file line number Diff line number Diff line change
Expand Up @@ -1269,11 +1269,46 @@
"type": "string"
}
},
"io.github.springwolf.examples.kafka.dtos.discriminator.EnginePower": {
"title": "EnginePower",
"type": "object",
"properties": {
"hp": {
"type": "integer",
"format": "int32"
},
"torque": {
"type": "integer",
"format": "int32"
}
},
"examples": [
{
"hp": 0,
"torque": 0
}
],
"x-json-schema": {
"$schema": "https://json-schema.org/draft-04/schema#",
"properties": {
"hp": {
"format": "int32",
"type": "integer"
},
"torque": { }
},
"title": "EnginePower",
"type": "object"
}
},
"io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase": {
"discriminator": "vehicleType",
"title": "VehicleBase",
"type": "object",
"properties": {
"enginePower": {
"$ref": "#/components/schemas/io.github.springwolf.examples.kafka.dtos.discriminator.EnginePower"
},
"powerSource": {
"type": "string"
},
Expand All @@ -1288,22 +1323,73 @@
"description": "Demonstrates the use of discriminator for polymorphic deserialization (not publishable)",
"examples": [
{
"batteryCapacity": 0,
"chargeTime": 0,
"enginePower": {
"hp": 0,
"torque": 0
},
"powerSource": "string",
"topSpeed": 0,
"vehicleType": "string"
}
],
"oneOf": [
{
"$ref": "#/components/schemas/io.github.springwolf.examples.kafka.dtos.discriminator.VehicleElectricPayloadDto"
},
{
"$ref": "#/components/schemas/io.github.springwolf.examples.kafka.dtos.discriminator.VehicleGasolinePayloadDto"
}
],
"x-json-schema": {
"$schema": "https://json-schema.org/draft-04/schema#",
"description": "Demonstrates the use of discriminator for polymorphic deserialization (not publishable)",
"oneOf": [
{
"allOf": [
{ },
{
"properties": {
"batteryCapacity": { },
"chargeTime": {
"format": "int32",
"type": "integer"
}
},
"type": "object"
}
],
"description": "Electric vehicle implementation of VehicleBase",
"type": "object"
},
{
"allOf": [
{ },
{
"properties": {
"fuelCapacity": { }
},
"type": "object"
}
],
"description": "Gasoline vehicle implementation of VehicleBase",
"type": "object"
}
],
"properties": {
"enginePower": {
"properties": {
"hp": { },
"torque": { }
},
"title": "EnginePower",
"type": "object"
},
"powerSource": {
"type": "string"
},
"topSpeed": {
"format": "int32",
"type": "integer"
},
"topSpeed": { },
"vehicleType": { }
},
"title": "VehicleBase",
Expand All @@ -1317,6 +1403,10 @@
{
"batteryCapacity": 0,
"chargeTime": 0,
"enginePower": {
"hp": 0,
"torque": 0
},
"powerSource": "string",
"topSpeed": 0,
"vehicleType": "string"
Expand Down Expand Up @@ -1345,14 +1435,38 @@
"allOf": [
{
"description": "Demonstrates the use of discriminator for polymorphic deserialization (not publishable)",
"oneOf": [
{ },
{
"allOf": [
{ },
{
"properties": {
"fuelCapacity": {
"format": "int32",
"type": "integer"
}
},
"type": "object"
}
],
"description": "Gasoline vehicle implementation of VehicleBase",
"type": "object"
}
],
"properties": {
"enginePower": {
"properties": {
"hp": { },
"torque": { }
},
"title": "EnginePower",
"type": "object"
},
"powerSource": {
"type": "string"
},
"topSpeed": {
"format": "int32",
"type": "integer"
},
"topSpeed": { },
"vehicleType": { }
},
"title": "VehicleBase",
Expand All @@ -1375,6 +1489,10 @@
"description": "Gasoline vehicle implementation of VehicleBase",
"examples": [
{
"enginePower": {
"hp": 0,
"torque": 0
},
"fuelCapacity": 0,
"powerSource": "string",
"topSpeed": 0,
Expand All @@ -1400,14 +1518,39 @@
"allOf": [
{
"description": "Demonstrates the use of discriminator for polymorphic deserialization (not publishable)",
"oneOf": [
{
"allOf": [
{ },
{
"properties": {
"batteryCapacity": { },
"chargeTime": {
"format": "int32",
"type": "integer"
}
},
"type": "object"
}
],
"description": "Electric vehicle implementation of VehicleBase",
"type": "object"
},
{ }
],
"properties": {
"enginePower": {
"properties": {
"hp": { },
"torque": { }
},
"title": "EnginePower",
"type": "object"
},
"powerSource": {
"type": "string"
},
"topSpeed": {
"format": "int32",
"type": "integer"
},
"topSpeed": { },
"vehicleType": { }
},
"title": "VehicleBase",
Expand Down Expand Up @@ -2004,4 +2147,4 @@
]
}
}
}
}
Loading

0 comments on commit ef4e47a

Please sign in to comment.