Skip to content

Commit 17d0e6c

Browse files
authored
chore: replace MessageReferences where used as SchemaReference (#1303)
* #1301 Refactoring MessageReference to SchemaReference * #1301 Refactoring MessageReference to SchemaReference * #1301 Refactoring MessageReference to SchemaReference
1 parent 413e2be commit 17d0e6c

File tree

25 files changed

+101
-98
lines changed

25 files changed

+101
-98
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
import com.fasterxml.jackson.databind.ObjectMapper;
77
import com.networknt.schema.JsonSchemaFactory;
88
import com.networknt.schema.SpecVersionDetector;
9-
import io.github.springwolf.asyncapi.v3.model.channel.message.MessageReference;
109
import io.github.springwolf.asyncapi.v3.model.components.ComponentSchema;
1110
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
11+
import io.github.springwolf.asyncapi.v3.model.schema.SchemaReference;
1212
import io.github.springwolf.asyncapi.v3.model.schema.SchemaType;
1313
import io.github.springwolf.core.asyncapi.schemas.SwaggerSchemaUtil;
1414
import io.swagger.v3.core.util.Json;
@@ -52,10 +52,10 @@ public void validateJsonSchemaTest(String expectedJsonSchema, Supplier<Schema<?>
5252
// ref cycle ping -> pingField -> pong -> pongField -> ping (repeat)
5353
SchemaObject pingSchema = new SchemaObject();
5454
pingSchema.setType(SchemaType.OBJECT);
55-
pingSchema.setProperties(Map.of("pingfield", ComponentSchema.of(MessageReference.toSchema("PongSchema"))));
55+
pingSchema.setProperties(Map.of("pingfield", ComponentSchema.of(SchemaReference.toSchema("PongSchema"))));
5656
SchemaObject pongSchema = new SchemaObject();
5757
pongSchema.setType(SchemaType.OBJECT);
58-
pongSchema.setProperties(Map.of("pongField", ComponentSchema.of(MessageReference.toSchema("PingSchema"))));
58+
pongSchema.setProperties(Map.of("pongField", ComponentSchema.of(SchemaReference.toSchema("PingSchema"))));
5959

6060
SchemaObject stringSchema = new SchemaObject();
6161
stringSchema.setType(SchemaType.STRING);

springwolf-asyncapi/src/main/java/io/github/springwolf/asyncapi/v3/model/channel/message/MessageHeaders.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.github.springwolf.asyncapi.v3.jackson.model.channel.message.MessageHeadersSerializer;
66
import io.github.springwolf.asyncapi.v3.model.schema.MultiFormatSchema;
77
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
8+
import io.github.springwolf.asyncapi.v3.model.schema.SchemaReference;
89
import lombok.EqualsAndHashCode;
910
import lombok.Getter;
1011
import lombok.ToString;
@@ -16,7 +17,7 @@
1617
public class MessageHeaders {
1718
private MultiFormatSchema multiFormatSchema;
1819
private SchemaObject schema;
19-
private MessageReference reference;
20+
private SchemaReference reference;
2021

2122
private MessageHeaders(MultiFormatSchema multiFormatSchema) {
2223
this.multiFormatSchema = multiFormatSchema;
@@ -26,7 +27,7 @@ private MessageHeaders(SchemaObject schema) {
2627
this.schema = schema;
2728
}
2829

29-
private MessageHeaders(MessageReference reference) {
30+
private MessageHeaders(SchemaReference reference) {
3031
this.reference = reference;
3132
}
3233

@@ -38,7 +39,7 @@ public static MessageHeaders of(SchemaObject schema) {
3839
return new MessageHeaders(schema);
3940
}
4041

41-
public static MessageHeaders of(MessageReference reference) {
42+
public static MessageHeaders of(SchemaReference reference) {
4243
return new MessageHeaders(reference);
4344
}
4445
}

springwolf-asyncapi/src/main/java/io/github/springwolf/asyncapi/v3/model/channel/message/MessagePayload.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.github.springwolf.asyncapi.v3.jackson.model.channel.message.MessagePayloadSerializer;
66
import io.github.springwolf.asyncapi.v3.model.schema.MultiFormatSchema;
77
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
8+
import io.github.springwolf.asyncapi.v3.model.schema.SchemaReference;
89
import lombok.EqualsAndHashCode;
910
import lombok.Getter;
1011
import lombok.ToString;
@@ -16,7 +17,7 @@
1617
public class MessagePayload {
1718
private MultiFormatSchema multiFormatSchema;
1819
private SchemaObject schema;
19-
private MessageReference reference;
20+
private SchemaReference reference;
2021

2122
private MessagePayload(MultiFormatSchema multiFormatSchema) {
2223
this.multiFormatSchema = multiFormatSchema;
@@ -26,7 +27,7 @@ private MessagePayload(SchemaObject schema) {
2627
this.schema = schema;
2728
}
2829

29-
private MessagePayload(MessageReference reference) {
30+
private MessagePayload(SchemaReference reference) {
3031
this.reference = reference;
3132
}
3233

@@ -38,7 +39,7 @@ public static MessagePayload of(SchemaObject schema) {
3839
return new MessagePayload(schema);
3940
}
4041

41-
public static MessagePayload of(MessageReference reference) {
42+
public static MessagePayload of(SchemaReference reference) {
4243
return new MessagePayload(reference);
4344
}
4445
}

springwolf-asyncapi/src/main/java/io/github/springwolf/asyncapi/v3/model/channel/message/MessageReference.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,4 @@ public static MessageReference toChannelMessage(String channelId, MessageObject
4545
public static MessageReference toChannelMessage(String channelId, String messageId) {
4646
return new MessageReference("#/channels/" + channelId + "/messages/" + messageId);
4747
}
48-
49-
public static MessageReference toSchema(String schemaName) {
50-
return new MessageReference("#/components/schemas/" + schemaName);
51-
}
5248
}

springwolf-asyncapi/src/main/java/io/github/springwolf/asyncapi/v3/model/components/ComponentSchema.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
55
import io.github.springwolf.asyncapi.v3.jackson.model.channel.message.ComponentSchemaSerializer;
6-
import io.github.springwolf.asyncapi.v3.model.channel.message.MessageReference;
76
import io.github.springwolf.asyncapi.v3.model.schema.MultiFormatSchema;
87
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
8+
import io.github.springwolf.asyncapi.v3.model.schema.SchemaReference;
99
import lombok.EqualsAndHashCode;
1010
import lombok.Getter;
1111
import lombok.ToString;
@@ -17,7 +17,7 @@
1717
public class ComponentSchema {
1818
private MultiFormatSchema multiFormatSchema;
1919
private SchemaObject schema;
20-
private MessageReference reference;
20+
private SchemaReference reference;
2121

2222
private ComponentSchema(MultiFormatSchema multiFormatSchema) {
2323
this.multiFormatSchema = multiFormatSchema;
@@ -27,7 +27,7 @@ private ComponentSchema(SchemaObject schema) {
2727
this.schema = schema;
2828
}
2929

30-
private ComponentSchema(MessageReference reference) {
30+
private ComponentSchema(SchemaReference reference) {
3131
this.reference = reference;
3232
}
3333

@@ -39,7 +39,7 @@ public static ComponentSchema of(SchemaObject schema) {
3939
return new ComponentSchema(schema);
4040
}
4141

42-
public static ComponentSchema of(MessageReference reference) {
42+
public static ComponentSchema of(SchemaReference reference) {
4343
return new ComponentSchema(reference);
4444
}
4545
}

springwolf-asyncapi/src/main/java/io/github/springwolf/asyncapi/v3/model/schema/SchemaReference.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public String getRef() {
2424
return ref;
2525
}
2626

27-
public static SchemaReference fromSchema(String schemaName) {
27+
public static SchemaReference toSchema(String schemaName) {
2828
return new SchemaReference("#/components/schemas/" + schemaName);
2929
}
3030
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.github.springwolf.asyncapi.v3.model.operation.OperationAction;
2121
import io.github.springwolf.asyncapi.v3.model.schema.MultiFormatSchema;
2222
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
23+
import io.github.springwolf.asyncapi.v3.model.schema.SchemaReference;
2324
import io.github.springwolf.asyncapi.v3.model.schema.SchemaType;
2425
import io.github.springwolf.asyncapi.v3.model.server.Server;
2526
import io.github.springwolf.asyncapi.v3.model.server.ServerReference;
@@ -65,7 +66,7 @@ private AsyncAPI getAsyncAPITestObject() {
6566
.name("io.github.springwolf.core.ExamplePayload")
6667
.title("Example Payload")
6768
.payload(MessagePayload.of(MultiFormatSchema.builder()
68-
.schema(MessageReference.toSchema("ExamplePayload"))
69+
.schema(SchemaReference.toSchema("ExamplePayload"))
6970
.build()))
7071
.bindings(Map.of(
7172
"kafka",

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
9999
.traits(List.of(MessageTrait.builder()
100100
.ref("#/components/messageTraits/commonHeaders")
101101
.build()))
102-
.payload(MessagePayload.of(MessageReference.toSchema("lightMeasuredPayload")))
102+
.payload(MessagePayload.of(SchemaReference.toSchema("lightMeasuredPayload")))
103103
.build();
104104

105105
var turnOnOffMessage = MessageObject.builder()
@@ -110,7 +110,7 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
110110
.traits(List.of(MessageTrait.builder()
111111
.ref("#/components/messageTraits/commonHeaders")
112112
.build()))
113-
.payload(MessagePayload.of(MessageReference.toSchema("turnOnOffPayload")))
113+
.payload(MessagePayload.of(SchemaReference.toSchema("turnOnOffPayload")))
114114
.build();
115115

116116
var dimLightMessage = MessageObject.builder()
@@ -121,7 +121,7 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
121121
.traits(List.of(MessageTrait.builder()
122122
.ref("#/components/messageTraits/commonHeaders")
123123
.build()))
124-
.payload(MessagePayload.of(MessageReference.toSchema("dimLightPayload")))
124+
.payload(MessagePayload.of(SchemaReference.toSchema("dimLightPayload")))
125125
.build();
126126

127127
AsyncAPI asyncAPI = AsyncAPI.builder()
@@ -294,7 +294,7 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
294294
.description("Light intensity measured in lumens.")
295295
.build(),
296296
"sentAt",
297-
SchemaReference.fromSchema("sentAt")))
297+
SchemaReference.toSchema("sentAt")))
298298
.build(),
299299
"turnOnOffPayload",
300300
SchemaObject.builder()
@@ -307,7 +307,7 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
307307
.description("Whether to turn on or off the light.")
308308
.build(),
309309
"sentAt",
310-
SchemaReference.fromSchema("sentAt")))
310+
SchemaReference.toSchema("sentAt")))
311311
.build(),
312312
"dimLightPayload",
313313
SchemaObject.builder()
@@ -322,7 +322,7 @@ void shouldCreateStreetlightsKafkaAsyncAPI() throws IOException {
322322
.maximum(new BigDecimal("100"))
323323
.build(),
324324
"sentAt",
325-
SchemaReference.fromSchema("sentAt")))
325+
SchemaReference.toSchema("sentAt")))
326326
.build(),
327327
"sentAt",
328328
SchemaObject.builder()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ void shouldSerializeMessage() throws IOException {
5353
.payload(MessagePayload.of(SchemaObject.builder()
5454
.type(SchemaType.OBJECT)
5555
.properties(Map.of(
56-
"user", SchemaReference.fromSchema("userCreate"),
57-
"signup", SchemaReference.fromSchema("signup")))
56+
"user", SchemaReference.toSchema("userCreate"),
57+
"signup", SchemaReference.toSchema("signup")))
5858
.build()))
5959
.correlationId(CorrelationID.builder()
6060
.description("Default Correlation ID")

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import com.fasterxml.jackson.core.JsonProcessingException;
55
import io.github.springwolf.asyncapi.v3.jackson.DefaultAsyncApiSerializerService;
6-
import io.github.springwolf.asyncapi.v3.model.channel.message.MessageReference;
76
import io.github.springwolf.asyncapi.v3.model.components.ComponentSchema;
87
import org.junit.jupiter.api.Test;
98

@@ -38,7 +37,7 @@ void shouldSerializeSimpleModel() throws JsonProcessingException {
3837
.required(List.of("name"))
3938
.properties(Map.of(
4039
"name", SchemaObject.builder().type(SchemaType.STRING).build(),
41-
"address", SchemaReference.fromSchema("Address"),
40+
"address", SchemaReference.toSchema("Address"),
4241
"age",
4342
SchemaObject.builder()
4443
.type(SchemaType.INTEGER)
@@ -96,7 +95,7 @@ void shouldSerializeStringToStringMapping() throws JsonProcessingException {
9695
void shouldSerializeModelMapping() throws JsonProcessingException {
9796
var schema = SchemaObject.builder()
9897
.type(SchemaType.OBJECT)
99-
.additionalProperties(ComponentSchema.of(MessageReference.toSchema("ComplexModel")))
98+
.additionalProperties(ComponentSchema.of(SchemaReference.toSchema("ComplexModel")))
10099
.build();
101100

102101
var example =
@@ -203,7 +202,7 @@ void shouldSerializeModelsWithComposition() throws JsonProcessingException {
203202
"ExtendedErrorModel",
204203
SchemaObject.builder()
205204
.allOf(List.of(
206-
ComponentSchema.of(MessageReference.toSchema("ErrorModel")),
205+
ComponentSchema.of(SchemaReference.toSchema("ErrorModel")),
207206
ComponentSchema.of(SchemaObject.builder()
208207
.type(SchemaType.OBJECT)
209208
.required(List.of("rootCause"))
@@ -285,7 +284,7 @@ void shouldSerializeModelsWithPolimorphismSupport() throws JsonProcessingExcepti
285284
.description(
286285
"A representation of a cat. Note that `Cat` will be used as the discriminator value.")
287286
.allOf(List.of(
288-
ComponentSchema.of(MessageReference.toSchema("Pet")),
287+
ComponentSchema.of(SchemaReference.toSchema("Pet")),
289288
ComponentSchema.of(SchemaObject.builder()
290289
.type(SchemaType.OBJECT)
291290
.properties(Map.of(
@@ -308,7 +307,7 @@ void shouldSerializeModelsWithPolimorphismSupport() throws JsonProcessingExcepti
308307
.description(
309308
"A representation of a dog. Note that `Dog` will be used as the discriminator value.")
310309
.allOf(List.of(
311-
ComponentSchema.of(MessageReference.toSchema("Pet")),
310+
ComponentSchema.of(SchemaReference.toSchema("Pet")),
312311
ComponentSchema.of(SchemaObject.builder()
313312
.type(SchemaType.OBJECT)
314313
.properties(Map.of(
@@ -327,7 +326,7 @@ void shouldSerializeModelsWithPolimorphismSupport() throws JsonProcessingExcepti
327326
.description(
328327
"A representation of an Australian walking stick. Note that `StickBug` will be used as the discriminator value.")
329328
.allOf(List.of(
330-
ComponentSchema.of(MessageReference.toSchema("Pet")),
329+
ComponentSchema.of(SchemaReference.toSchema("Pet")),
331330
ComponentSchema.of(SchemaObject.builder()
332331
.type(SchemaType.OBJECT)
333332
.properties(Map.of(

0 commit comments

Comments
 (0)