Skip to content

Commit f3f412f

Browse files
timonbackDavid Beck
andauthored
Refactor/rename to payload schema object (#922)
* refactor(core): rename NamedSchemaObject to PayloadSchemaObject extracted from #890 Co-authored-by: David Beck <[email protected]> * refactor(core): use SchemaType constants --------- Co-authored-by: David Beck <[email protected]>
1 parent d017164 commit f3f412f

File tree

48 files changed

+229
-194
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+229
-194
lines changed

springwolf-add-ons/springwolf-json-schema/src/test/java/io/github/springwolf/addons/json_schema/JsonSchemaCustomizerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.github.springwolf.asyncapi.v3.model.AsyncAPI;
66
import io.github.springwolf.asyncapi.v3.model.components.Components;
77
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
8+
import io.github.springwolf.asyncapi.v3.model.schema.SchemaType;
89
import org.junit.jupiter.api.BeforeEach;
910
import org.junit.jupiter.api.Test;
1011

@@ -43,7 +44,7 @@ public void shouldAddJsonSchemaExtensionTest() throws JsonProcessingException {
4344
// given
4445
AsyncAPI asyncAPI = createAsyncApi();
4546
SchemaObject schemaObject = new SchemaObject();
46-
schemaObject.setType("object");
47+
schemaObject.setType(SchemaType.OBJECT);
4748
asyncAPI.getComponents().setSchemas(Map.of("schema", schemaObject));
4849

4950
when(jsonSchemaGenerator.fromSchema(any(), any())).thenReturn("mock-string");

springwolf-add-ons/springwolf-json-schema/src/test/java/io/github/springwolf/addons/json_schema/JsonSchemaGeneratorTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io.github.springwolf.asyncapi.v3.model.channel.message.MessageReference;
1010
import io.github.springwolf.asyncapi.v3.model.components.ComponentSchema;
1111
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
12+
import io.github.springwolf.asyncapi.v3.model.schema.SchemaType;
1213
import io.github.springwolf.core.asyncapi.schemas.SwaggerSchemaUtil;
1314
import io.swagger.v3.core.util.Json;
1415
import io.swagger.v3.oas.models.media.ArraySchema;
@@ -50,14 +51,14 @@ public void validateJsonSchemaTest(String expectedJsonSchema, Supplier<Schema<?>
5051

5152
// ref cycle ping -> pingField -> pong -> pongField -> ping (repeat)
5253
SchemaObject pingSchema = new SchemaObject();
53-
pingSchema.setType("object");
54+
pingSchema.setType(SchemaType.OBJECT);
5455
pingSchema.setProperties(Map.of("pingfield", ComponentSchema.of(MessageReference.toSchema("PongSchema"))));
5556
SchemaObject pongSchema = new SchemaObject();
56-
pongSchema.setType("object");
57+
pongSchema.setType(SchemaType.OBJECT);
5758
pongSchema.setProperties(Map.of("pongField", ComponentSchema.of(MessageReference.toSchema("PingSchema"))));
5859

5960
SchemaObject stringSchema = new SchemaObject();
60-
stringSchema.setType("string");
61+
stringSchema.setType(SchemaType.STRING);
6162

6263
Map<String, SchemaObject> definitions =
6364
Map.of("StringRef", stringSchema, "PingSchema", pingSchema, "PongSchema", pongSchema);

springwolf-asyncapi/src/test/java/io/github/springwolf/asyncapi/v3/bindings/kafka/KafkaBindingTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io.github.springwolf.asyncapi.v3.model.operation.Operation;
1010
import io.github.springwolf.asyncapi.v3.model.operation.OperationAction;
1111
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
12+
import io.github.springwolf.asyncapi.v3.model.schema.SchemaType;
1213
import io.github.springwolf.asyncapi.v3.model.server.Server;
1314
import org.junit.jupiter.api.Test;
1415

@@ -52,11 +53,11 @@ void shouldSerializeKafkaOperationBinding() throws IOException {
5253
"kafka",
5354
KafkaOperationBinding.builder()
5455
.groupId(SchemaObject.builder()
55-
.type("string")
56+
.type(SchemaType.STRING)
5657
.enumValues(List.of("myGroupId"))
5758
.build())
5859
.clientId(SchemaObject.builder()
59-
.type("string")
60+
.type(SchemaType.STRING)
6061
.enumValues(List.of("myClientId"))
6162
.build())
6263
.build()))
@@ -140,7 +141,7 @@ void shouldSerializeKafkaMessage() throws IOException {
140141
KafkaMessageBinding.builder()
141142
.key(
142143
SchemaObject.builder()
143-
.type("string")
144+
.type(SchemaType.STRING)
144145
.enumValues(List.of("myKey"))
145146
.build())
146147
.schemaIdLocation("payload")

springwolf-asyncapi/src/test/java/io/github/springwolf/asyncapi/v3/bindings/mqtt/MQTTBindingTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.github.springwolf.asyncapi.v3.jackson.DefaultAsyncApiSerializerService;
66
import io.github.springwolf.asyncapi.v3.model.AsyncAPI;
77
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
8+
import io.github.springwolf.asyncapi.v3.model.schema.SchemaType;
89
import io.github.springwolf.asyncapi.v3.model.server.Server;
910
import org.junit.jupiter.api.Test;
1011

@@ -58,12 +59,12 @@ void shouldSerializeMQTTServerExample2() throws IOException {
5859
"mqtt",
5960
MQTTServerBinding.builder()
6061
.sessionExpiryInterval(SchemaObject.builder()
61-
.type("integer")
62+
.type(SchemaType.INTEGER)
6263
.minimum(new BigDecimal("30"))
6364
.maximum(new BigDecimal("1200"))
6465
.build())
6566
.maximumPacketSize(SchemaObject.builder()
66-
.type("integer")
67+
.type(SchemaType.INTEGER)
6768
.minimum(new BigDecimal("256"))
6869
.build())
6970
.build()))

springwolf-asyncapi/src/test/java/io/github/springwolf/asyncapi/v3/jackson/DefaultAsyncApiSerializerServiceIntegrationTest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ private AsyncAPI getAsyncAPITestObject() {
7171
"kafka",
7272
KafkaMessageBinding.builder()
7373
// FIXME: We should have a SchemaString (Schema<String>)
74-
.key(SchemaObject.builder().type("string").build())
74+
.key(SchemaObject.builder()
75+
.type(SchemaType.STRING)
76+
.build())
7577
.build()))
7678
.build();
7779
Map<String, Message> messages = Map.of(message.getMessageId(), message);
@@ -100,9 +102,9 @@ private AsyncAPI getAsyncAPITestObject() {
100102
.build();
101103

102104
SchemaObject examplePayloadSchema = new SchemaObject();
103-
examplePayloadSchema.setType("object");
105+
examplePayloadSchema.setType(SchemaType.OBJECT);
104106
SchemaObject stringSchema = new SchemaObject();
105-
stringSchema.setType("string");
107+
stringSchema.setType(SchemaType.STRING);
106108
examplePayloadSchema.setProperties(Map.of("s", stringSchema));
107109
Map<String, SchemaObject> schemas = Map.of("ExamplePayload", examplePayloadSchema);
108110

springwolf-asyncapi/src/test/java/io/github/springwolf/asyncapi/v3/model/AsyncAPITest.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.github.springwolf.asyncapi.v3.model.operation.OperationTraits;
2121
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
2222
import io.github.springwolf.asyncapi.v3.model.schema.SchemaReference;
23+
import io.github.springwolf.asyncapi.v3.model.schema.SchemaType;
2324
import io.github.springwolf.asyncapi.v3.model.security_scheme.SecurityScheme;
2425
import io.github.springwolf.asyncapi.v3.model.security_scheme.SecurityType;
2526
import io.github.springwolf.asyncapi.v3.model.server.Server;
@@ -40,16 +41,16 @@ void shouldCreateSimpleAsyncAPI() throws IOException {
4041
var userSignUpMessage = MessageObject.builder()
4142
.messageId("UserSignedUp")
4243
.payload(MessagePayload.of(SchemaObject.builder()
43-
.type("object")
44+
.type(SchemaType.OBJECT)
4445
.properties(Map.of(
4546
"displayName",
4647
SchemaObject.builder()
47-
.type("string")
48+
.type(SchemaType.STRING)
4849
.description("Name of the user")
4950
.build(),
5051
"email",
5152
SchemaObject.builder()
52-
.type("string")
53+
.type(SchemaType.STRING)
5354
.format("email")
5455
.description("Email of the user")
5556
.build()))
@@ -284,11 +285,11 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
284285
.schemas(Map.of(
285286
"lightMeasuredPayload",
286287
SchemaObject.builder()
287-
.type("object")
288+
.type(SchemaType.OBJECT)
288289
.properties(Map.of(
289290
"lumens",
290291
SchemaObject.builder()
291-
.type("integer")
292+
.type(SchemaType.INTEGER)
292293
.minimum(BigDecimal.ZERO)
293294
.description("Light intensity measured in lumens.")
294295
.build(),
@@ -297,11 +298,11 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
297298
.build(),
298299
"turnOnOffPayload",
299300
SchemaObject.builder()
300-
.type("object")
301+
.type(SchemaType.OBJECT)
301302
.properties(Map.of(
302303
"command",
303304
SchemaObject.builder()
304-
.type("string")
305+
.type(SchemaType.STRING)
305306
.enumValues(List.of("on", "off"))
306307
.description("Whether to turn on or off the light.")
307308
.build(),
@@ -310,11 +311,11 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
310311
.build(),
311312
"dimLightPayload",
312313
SchemaObject.builder()
313-
.type("object")
314+
.type(SchemaType.OBJECT)
314315
.properties(Map.of(
315316
"percentage",
316317
SchemaObject.builder()
317-
.type("integer")
318+
.type(SchemaType.INTEGER)
318319
.description(
319320
"Percentage to which the light should be dimmed to.")
320321
.minimum(BigDecimal.ZERO)
@@ -325,7 +326,7 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
325326
.build(),
326327
"sentAt",
327328
SchemaObject.builder()
328-
.type("string")
329+
.type(SchemaType.STRING)
329330
.format("date-time")
330331
.description("Date and time when the message was sent.")
331332
.build()))
@@ -349,11 +350,11 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
349350
"commonHeaders",
350351
MessageTrait.builder()
351352
.headers(MessageHeaders.of(SchemaObject.builder()
352-
.type("object")
353+
.type(SchemaType.OBJECT)
353354
.properties(Map.of(
354355
"my-app-header",
355356
SchemaObject.builder()
356-
.type("integer")
357+
.type(SchemaType.INTEGER)
357358
.minimum(BigDecimal.ZERO)
358359
.maximum(new BigDecimal("100"))
359360
.build()))
@@ -366,7 +367,7 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
366367
"kafka",
367368
KafkaOperationBinding.builder()
368369
.clientId(SchemaObject.builder()
369-
.type("string")
370+
.type(SchemaType.STRING)
370371
.enumValues(List.of("my-app-id"))
371372
.build())
372373
.build()))

springwolf-asyncapi/src/test/java/io/github/springwolf/asyncapi/v3/model/channel/MessageTest.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import io.github.springwolf.asyncapi.v3.model.channel.message.MessageTrait;
1212
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
1313
import io.github.springwolf.asyncapi.v3.model.schema.SchemaReference;
14+
import io.github.springwolf.asyncapi.v3.model.schema.SchemaType;
1415
import org.junit.jupiter.api.Test;
1516

1617
import java.io.IOException;
@@ -35,22 +36,22 @@ void shouldSerializeMessage() throws IOException {
3536
Tag.builder().name("signup").build(),
3637
Tag.builder().name("register").build()))
3738
.headers(MessageHeaders.of(SchemaObject.builder()
38-
.type("object")
39+
.type(SchemaType.OBJECT)
3940
.properties(Map.of(
4041
"correlationId",
4142
SchemaObject.builder()
4243
.description("Correlation ID set by application")
43-
.type("string")
44+
.type(SchemaType.STRING)
4445
.build(),
4546
"applicationInstanceId",
4647
SchemaObject.builder()
4748
.description(
4849
"Unique identifier for a given instance of the publishing application")
49-
.type("string")
50+
.type(SchemaType.STRING)
5051
.build()))
5152
.build()))
5253
.payload(MessagePayload.of(SchemaObject.builder()
53-
.type("object")
54+
.type(SchemaType.OBJECT)
5455
.properties(Map.of(
5556
"user", SchemaReference.fromSchema("userCreate"),
5657
"signup", SchemaReference.fromSchema("signup")))

0 commit comments

Comments
 (0)