Skip to content

Commit ef4e47a

Browse files
authored
test(kafka-example): add polymorphism with oneOf to VehicleBase (#1152)
1 parent 2d4e611 commit ef4e47a

File tree

5 files changed

+367
-30
lines changed

5 files changed

+367
-30
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
package io.github.springwolf.examples.kafka.dtos.discriminator;
3+
4+
import lombok.AllArgsConstructor;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
8+
@NoArgsConstructor
9+
@Data
10+
@AllArgsConstructor
11+
public class EnginePower {
12+
private int hp;
13+
private int torque;
14+
}

springwolf-examples/springwolf-kafka-example/src/main/java/io/github/springwolf/examples/kafka/dtos/discriminator/VehicleBase.java

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
@JsonSubTypes.Type(value = VehicleGasolinePayloadDto.class, name = "VehicleGasolinePayloadDto"),
1616
})
1717
@Schema(
18+
oneOf = {VehicleElectricPayloadDto.class, VehicleGasolinePayloadDto.class},
1819
subTypes = {VehicleElectricPayloadDto.class, VehicleGasolinePayloadDto.class},
1920
discriminatorProperty = "vehicleType",
2021
discriminatorMapping = {
@@ -30,4 +31,6 @@ public abstract class VehicleBase {
3031

3132
private String powerSource;
3233
private int topSpeed;
34+
35+
private EnginePower enginePower;
3336
}

springwolf-examples/springwolf-kafka-example/src/test/resources/asyncapi.json

+156-13
Original file line numberDiff line numberDiff line change
@@ -1269,11 +1269,46 @@
12691269
"type": "string"
12701270
}
12711271
},
1272+
"io.github.springwolf.examples.kafka.dtos.discriminator.EnginePower": {
1273+
"title": "EnginePower",
1274+
"type": "object",
1275+
"properties": {
1276+
"hp": {
1277+
"type": "integer",
1278+
"format": "int32"
1279+
},
1280+
"torque": {
1281+
"type": "integer",
1282+
"format": "int32"
1283+
}
1284+
},
1285+
"examples": [
1286+
{
1287+
"hp": 0,
1288+
"torque": 0
1289+
}
1290+
],
1291+
"x-json-schema": {
1292+
"$schema": "https://json-schema.org/draft-04/schema#",
1293+
"properties": {
1294+
"hp": {
1295+
"format": "int32",
1296+
"type": "integer"
1297+
},
1298+
"torque": { }
1299+
},
1300+
"title": "EnginePower",
1301+
"type": "object"
1302+
}
1303+
},
12721304
"io.github.springwolf.examples.kafka.dtos.discriminator.VehicleBase": {
12731305
"discriminator": "vehicleType",
12741306
"title": "VehicleBase",
12751307
"type": "object",
12761308
"properties": {
1309+
"enginePower": {
1310+
"$ref": "#/components/schemas/io.github.springwolf.examples.kafka.dtos.discriminator.EnginePower"
1311+
},
12771312
"powerSource": {
12781313
"type": "string"
12791314
},
@@ -1288,22 +1323,73 @@
12881323
"description": "Demonstrates the use of discriminator for polymorphic deserialization (not publishable)",
12891324
"examples": [
12901325
{
1326+
"batteryCapacity": 0,
1327+
"chargeTime": 0,
1328+
"enginePower": {
1329+
"hp": 0,
1330+
"torque": 0
1331+
},
12911332
"powerSource": "string",
12921333
"topSpeed": 0,
12931334
"vehicleType": "string"
12941335
}
12951336
],
1337+
"oneOf": [
1338+
{
1339+
"$ref": "#/components/schemas/io.github.springwolf.examples.kafka.dtos.discriminator.VehicleElectricPayloadDto"
1340+
},
1341+
{
1342+
"$ref": "#/components/schemas/io.github.springwolf.examples.kafka.dtos.discriminator.VehicleGasolinePayloadDto"
1343+
}
1344+
],
12961345
"x-json-schema": {
12971346
"$schema": "https://json-schema.org/draft-04/schema#",
12981347
"description": "Demonstrates the use of discriminator for polymorphic deserialization (not publishable)",
1348+
"oneOf": [
1349+
{
1350+
"allOf": [
1351+
{ },
1352+
{
1353+
"properties": {
1354+
"batteryCapacity": { },
1355+
"chargeTime": {
1356+
"format": "int32",
1357+
"type": "integer"
1358+
}
1359+
},
1360+
"type": "object"
1361+
}
1362+
],
1363+
"description": "Electric vehicle implementation of VehicleBase",
1364+
"type": "object"
1365+
},
1366+
{
1367+
"allOf": [
1368+
{ },
1369+
{
1370+
"properties": {
1371+
"fuelCapacity": { }
1372+
},
1373+
"type": "object"
1374+
}
1375+
],
1376+
"description": "Gasoline vehicle implementation of VehicleBase",
1377+
"type": "object"
1378+
}
1379+
],
12991380
"properties": {
1381+
"enginePower": {
1382+
"properties": {
1383+
"hp": { },
1384+
"torque": { }
1385+
},
1386+
"title": "EnginePower",
1387+
"type": "object"
1388+
},
13001389
"powerSource": {
13011390
"type": "string"
13021391
},
1303-
"topSpeed": {
1304-
"format": "int32",
1305-
"type": "integer"
1306-
},
1392+
"topSpeed": { },
13071393
"vehicleType": { }
13081394
},
13091395
"title": "VehicleBase",
@@ -1317,6 +1403,10 @@
13171403
{
13181404
"batteryCapacity": 0,
13191405
"chargeTime": 0,
1406+
"enginePower": {
1407+
"hp": 0,
1408+
"torque": 0
1409+
},
13201410
"powerSource": "string",
13211411
"topSpeed": 0,
13221412
"vehicleType": "string"
@@ -1345,14 +1435,38 @@
13451435
"allOf": [
13461436
{
13471437
"description": "Demonstrates the use of discriminator for polymorphic deserialization (not publishable)",
1438+
"oneOf": [
1439+
{ },
1440+
{
1441+
"allOf": [
1442+
{ },
1443+
{
1444+
"properties": {
1445+
"fuelCapacity": {
1446+
"format": "int32",
1447+
"type": "integer"
1448+
}
1449+
},
1450+
"type": "object"
1451+
}
1452+
],
1453+
"description": "Gasoline vehicle implementation of VehicleBase",
1454+
"type": "object"
1455+
}
1456+
],
13481457
"properties": {
1458+
"enginePower": {
1459+
"properties": {
1460+
"hp": { },
1461+
"torque": { }
1462+
},
1463+
"title": "EnginePower",
1464+
"type": "object"
1465+
},
13491466
"powerSource": {
13501467
"type": "string"
13511468
},
1352-
"topSpeed": {
1353-
"format": "int32",
1354-
"type": "integer"
1355-
},
1469+
"topSpeed": { },
13561470
"vehicleType": { }
13571471
},
13581472
"title": "VehicleBase",
@@ -1375,6 +1489,10 @@
13751489
"description": "Gasoline vehicle implementation of VehicleBase",
13761490
"examples": [
13771491
{
1492+
"enginePower": {
1493+
"hp": 0,
1494+
"torque": 0
1495+
},
13781496
"fuelCapacity": 0,
13791497
"powerSource": "string",
13801498
"topSpeed": 0,
@@ -1400,14 +1518,39 @@
14001518
"allOf": [
14011519
{
14021520
"description": "Demonstrates the use of discriminator for polymorphic deserialization (not publishable)",
1521+
"oneOf": [
1522+
{
1523+
"allOf": [
1524+
{ },
1525+
{
1526+
"properties": {
1527+
"batteryCapacity": { },
1528+
"chargeTime": {
1529+
"format": "int32",
1530+
"type": "integer"
1531+
}
1532+
},
1533+
"type": "object"
1534+
}
1535+
],
1536+
"description": "Electric vehicle implementation of VehicleBase",
1537+
"type": "object"
1538+
},
1539+
{ }
1540+
],
14031541
"properties": {
1542+
"enginePower": {
1543+
"properties": {
1544+
"hp": { },
1545+
"torque": { }
1546+
},
1547+
"title": "EnginePower",
1548+
"type": "object"
1549+
},
14041550
"powerSource": {
14051551
"type": "string"
14061552
},
1407-
"topSpeed": {
1408-
"format": "int32",
1409-
"type": "integer"
1410-
},
1553+
"topSpeed": { },
14111554
"vehicleType": { }
14121555
},
14131556
"title": "VehicleBase",
@@ -2004,4 +2147,4 @@
20042147
]
20052148
}
20062149
}
2007-
}
2150+
}

0 commit comments

Comments
 (0)