diff --git a/springwolf-asyncapi/src/main/java/io/github/springwolf/asyncapi/v3/model/channel/message/MessageReference.java b/springwolf-asyncapi/src/main/java/io/github/springwolf/asyncapi/v3/model/channel/message/MessageReference.java index bc6b16b9d..4bb00559c 100644 --- a/springwolf-asyncapi/src/main/java/io/github/springwolf/asyncapi/v3/model/channel/message/MessageReference.java +++ b/springwolf-asyncapi/src/main/java/io/github/springwolf/asyncapi/v3/model/channel/message/MessageReference.java @@ -27,23 +27,23 @@ public String getRef() { /** * Convenient Builder to create a Message reference to an existing Message * - * @param message Message to create the reference to. This Message MUST have a 'messageName' field - * @return a Message with the 'ref' field pointing to "#/components/messages/{messageName}" + * @param message Message to create the reference to. This Message MUST have a 'messageId' field + * @return a Message with the 'ref' field pointing to "#/components/messages/{messageId}" */ public static MessageReference toComponentMessage(MessageObject message) { - return toComponentMessage(message.getName()); + return toComponentMessage(message.getMessageId()); } - public static MessageReference toComponentMessage(String messageName) { - return new MessageReference("#/components/messages/" + messageName); + public static MessageReference toComponentMessage(String messageId) { + return new MessageReference("#/components/messages/" + messageId); } public static MessageReference toChannelMessage(String channelName, MessageObject message) { - return new MessageReference("#/channels/" + channelName + "/messages/" + message.getName()); + return new MessageReference("#/channels/" + channelName + "/messages/" + message.getMessageId()); } - public static MessageReference toChannelMessage(String channelName, String messageName) { - return new MessageReference("#/channels/" + channelName + "/messages/" + messageName); + public static MessageReference toChannelMessage(String channelName, String messageId) { + return new MessageReference("#/channels/" + channelName + "/messages/" + messageId); } public static MessageReference toSchema(String schemaName) { diff --git a/springwolf-asyncapi/src/test/java/io/github/springwolf/asyncapi/v3/jackson/DefaultAsyncApiSerializerServiceIntegrationTest.java b/springwolf-asyncapi/src/test/java/io/github/springwolf/asyncapi/v3/jackson/DefaultAsyncApiSerializerServiceIntegrationTest.java index 28a0e1357..a268b0bc7 100644 --- a/springwolf-asyncapi/src/test/java/io/github/springwolf/asyncapi/v3/jackson/DefaultAsyncApiSerializerServiceIntegrationTest.java +++ b/springwolf-asyncapi/src/test/java/io/github/springwolf/asyncapi/v3/jackson/DefaultAsyncApiSerializerServiceIntegrationTest.java @@ -86,7 +86,7 @@ private AsyncAPI getAsyncAPITestObject() { Operation newUserOperation = Operation.builder() .action(OperationAction.SEND) .channel(ChannelReference.fromChannel("new-user")) - .messages(List.of(MessageReference.toChannelMessage("new-user", message.getName()))) + .messages(List.of(MessageReference.toChannelMessage("new-user", message))) .bindings(Map.of("kafka", operationBinding)) .build(); diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/DefaultComponentsService.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/DefaultComponentsService.java index 4e5e4064a..e3d13c651 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/DefaultComponentsService.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/components/DefaultComponentsService.java @@ -112,9 +112,9 @@ public Map getMessages() { @Override public MessageReference registerMessage(MessageObject message) { - log.debug("Registering message for {}", message.getName()); + log.debug("Registering message for {}", message.getMessageId()); - messages.putIfAbsent(message.getName(), message); + messages.putIfAbsent(message.getMessageId(), message); return MessageReference.toComponentMessage(message); } diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/channels/AsyncAnnotationChannelsScanner.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/channels/AsyncAnnotationChannelsScanner.java index 7c28ddab3..915e28c12 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/channels/AsyncAnnotationChannelsScanner.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/channels/AsyncAnnotationChannelsScanner.java @@ -79,7 +79,7 @@ private Map.Entry buildChannel(MethodAndAnnotation met MessageObject message = buildMessage(operationAnnotation, methodAndAnnotation.method()); ChannelObject channelItem = channelBuilder - .messages(Map.of(message.getName(), MessageReference.toComponentMessage(message))) + .messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message))) .build(); return Map.entry(channelName, channelItem); } diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/channels/annotations/SpringAnnotationMethodLevelChannelsScanner.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/channels/annotations/SpringAnnotationMethodLevelChannelsScanner.java index fe6d879a1..d58858363 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/channels/annotations/SpringAnnotationMethodLevelChannelsScanner.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/channels/annotations/SpringAnnotationMethodLevelChannelsScanner.java @@ -73,7 +73,7 @@ private ChannelObject buildChannelItem(MethodAnnotation annotation, MessageObjec Map channelBinding = bindingFactory.buildChannelBinding(annotation); Map chBinding = channelBinding != null ? new HashMap<>(channelBinding) : null; return ChannelObject.builder() - .messages(Map.of(message.getName(), MessageReference.toComponentMessage(message))) + .messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message))) .bindings(chBinding) .build(); } diff --git a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/common/MessageHelper.java b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/common/MessageHelper.java index ca3c2fa31..61a219ea9 100644 --- a/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/common/MessageHelper.java +++ b/springwolf-core/src/main/java/io/github/springwolf/core/asyncapi/scanners/common/MessageHelper.java @@ -15,9 +15,9 @@ @Slf4j public class MessageHelper { - private static final Comparator byMessageName = Comparator.comparing(MessageObject::getName); + private static final Comparator byMessageId = Comparator.comparing(MessageObject::getMessageId); - private static final Supplier> messageSupplier = () -> new TreeSet<>(byMessageName); + private static final Supplier> messageSupplier = () -> new TreeSet<>(byMessageId); private MessageHelper() {} @@ -27,7 +27,7 @@ public static Map toMessagesMap(Set mes } return new ArrayList<>(messages.stream().collect(Collectors.toCollection(messageSupplier))) - .stream().collect(Collectors.toMap(MessageObject::getName, MessageReference::toComponentMessage)); + .stream().collect(Collectors.toMap(MessageObject::getMessageId, MessageReference::toComponentMessage)); } public static Map toOperationsMessagesMap( @@ -43,7 +43,7 @@ public static Map toOperationsMessagesMap( return new ArrayList<>(messages.stream().collect(Collectors.toCollection(messageSupplier))) .stream() .collect(Collectors.toMap( - MessageObject::getName, - e -> MessageReference.toChannelMessage(channelName, e.getName()))); + MessageObject::getMessageId, + e -> MessageReference.toChannelMessage(channelName, e.getMessageId()))); } } diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/channels/ChannelMergerTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/channels/ChannelMergerTest.java index 0ad143b35..4f8f9b28c 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/channels/ChannelMergerTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/channels/ChannelMergerTest.java @@ -70,28 +70,25 @@ void shouldMergeDifferentMessagesForSameChannel() { // given String channelName = "channel"; MessageObject message1 = MessageObject.builder() - .messageId("message1") .name(String.class.getCanonicalName()) .description("This is a string") .build(); MessageObject message2 = MessageObject.builder() - .messageId("message2") .name(Integer.class.getCanonicalName()) .description("This is an integer") .build(); MessageObject message3 = MessageObject.builder() - .messageId("message3") .name(Integer.class.getCanonicalName()) .description("This is also an integer, but in essence the same payload type") .build(); ChannelObject publisherChannel1 = ChannelObject.builder() - .messages(Map.of(message1.getName(), MessageReference.toComponentMessage(message1))) + .messages(Map.of(message1.getMessageId(), MessageReference.toComponentMessage(message1))) .build(); ChannelObject publisherChannel2 = ChannelObject.builder() - .messages(Map.of(message2.getName(), MessageReference.toComponentMessage(message2))) + .messages(Map.of(message2.getMessageId(), MessageReference.toComponentMessage(message2))) .build(); ChannelObject publisherChannel3 = ChannelObject.builder() - .messages(Map.of(message3.getName(), MessageReference.toComponentMessage(message3))) + .messages(Map.of(message3.getMessageId(), MessageReference.toComponentMessage(message3))) .build(); // when @@ -113,7 +110,6 @@ void shouldUseOtherMessageIfFirstMessageIsMissingForChannels() { // given String channelName = "channel"; MessageObject message2 = MessageObject.builder() - .messageId(String.class.getCanonicalName()) .name(String.class.getCanonicalName()) .description("This is a string") .build(); diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/channels/annotations/AsyncAnnotationChannelsScannerTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/channels/annotations/AsyncAnnotationChannelsScannerTest.java index bf6cde9f3..e9b1137e2 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/channels/annotations/AsyncAnnotationChannelsScannerTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/channels/annotations/AsyncAnnotationChannelsScannerTest.java @@ -271,7 +271,7 @@ void scan_componentHasAsyncMethodAnnotation() { .build()); MessageObject message = MessageObject.builder() - .messageId("simpleFoo") + .messageId("simpleFooId") .name("SimpleFooPayLoad") .title("Message Title") .description("Message description") @@ -283,7 +283,7 @@ void scan_componentHasAsyncMethodAnnotation() { ChannelObject expectedChannel = ChannelObject.builder() .bindings(null) - .messages(Map.of(message.getName(), MessageReference.toComponentMessage(message))) + .messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message))) .build(); assertThat(actualChannels).containsExactly(Map.entry("test-channel", expectedChannel)); @@ -353,7 +353,7 @@ private static class ClassWithMessageAnnotation { message = @AsyncMessage( description = "Message description", - messageId = "simpleFoo", + messageId = "simpleFooId", name = "SimpleFooPayLoad", contentType = "application/json", title = "Message Title"))) diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationMergerTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationMergerTest.java index 6f3ffe1a1..ff8c82376 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationMergerTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/OperationMergerTest.java @@ -79,17 +79,14 @@ void shouldMergeDifferentMessageForSameOperation() { String channelName = "channel"; String operationId = "operation"; MessageObject message1 = MessageObject.builder() - .messageId("message1") .name(String.class.getCanonicalName()) .description("This is a string") .build(); MessageObject message2 = MessageObject.builder() - .messageId("message2") .name(Integer.class.getCanonicalName()) .description("This is an integer") .build(); MessageObject message3 = MessageObject.builder() - .messageId("message3") .name(Integer.class.getCanonicalName()) .description("This is also an integer, but in essence the same payload type") .build(); @@ -137,7 +134,7 @@ void shouldUseOtherMessageIfFirstMessageIsMissingForChannels() { .build(); ChannelObject publisherChannel1 = ChannelObject.builder().build(); ChannelObject publisherChannel2 = ChannelObject.builder() - .messages(Map.of(message2.getName(), message2)) + .messages(Map.of(message2.getMessageId(), message2)) .build(); // when @@ -145,7 +142,7 @@ void shouldUseOtherMessageIfFirstMessageIsMissingForChannels() { Arrays.asList(Map.entry(channelName, publisherChannel1), Map.entry(channelName, publisherChannel2))); // then expectedMessage message2 - var expectedMessages = Map.of(message2.getName(), message2); + var expectedMessages = Map.of(message2.getMessageId(), message2); assertThat(mergedChannels).hasSize(1).hasEntrySatisfying(channelName, it -> { assertThat(it.getMessages()).hasSize(1); diff --git a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationOperationsScannerTest.java b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationOperationsScannerTest.java index 2af46328a..6d41754af 100644 --- a/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationOperationsScannerTest.java +++ b/springwolf-core/src/test/java/io/github/springwolf/core/asyncapi/scanners/operations/annotations/AsyncAnnotationOperationsScannerTest.java @@ -311,7 +311,7 @@ void scan_componentHasAsyncMethodAnnotationInAbstractClass() { .build()); MessageObject message = MessageObject.builder() - .messageId("simpleFoo") + .messageId("simpleFooAbstract") .name("SimpleFooPayLoad") .title("Message Title") .description("Message description") diff --git a/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/java/io/github/springwolf/plugins/cloudstream/asyncapi/scanners/channels/CloudStreamFunctionChannelsScanner.java b/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/java/io/github/springwolf/plugins/cloudstream/asyncapi/scanners/channels/CloudStreamFunctionChannelsScanner.java index b52678904..d457d205d 100644 --- a/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/java/io/github/springwolf/plugins/cloudstream/asyncapi/scanners/channels/CloudStreamFunctionChannelsScanner.java +++ b/springwolf-plugins/springwolf-cloud-stream-plugin/src/main/java/io/github/springwolf/plugins/cloudstream/asyncapi/scanners/channels/CloudStreamFunctionChannelsScanner.java @@ -104,7 +104,7 @@ private ChannelObject buildChannel(FunctionalChannelBeanData beanData) { Map channelBinding = buildChannelBinding(beanData.annotatedElement()); return ChannelObject.builder() .bindings(channelBinding) - .messages(Map.of(message.getName(), MessageReference.toComponentMessage(message))) + .messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message))) .build(); } diff --git a/springwolf-plugins/springwolf-cloud-stream-plugin/src/test/java/io/github/springwolf/plugins/cloudstream/asyncapi/scanners/channels/CloudStreamFunctionChannelsScannerIntegrationTest.java b/springwolf-plugins/springwolf-cloud-stream-plugin/src/test/java/io/github/springwolf/plugins/cloudstream/asyncapi/scanners/channels/CloudStreamFunctionChannelsScannerIntegrationTest.java index c06f03e17..c8d3a8f1c 100644 --- a/springwolf-plugins/springwolf-cloud-stream-plugin/src/test/java/io/github/springwolf/plugins/cloudstream/asyncapi/scanners/channels/CloudStreamFunctionChannelsScannerIntegrationTest.java +++ b/springwolf-plugins/springwolf-cloud-stream-plugin/src/test/java/io/github/springwolf/plugins/cloudstream/asyncapi/scanners/channels/CloudStreamFunctionChannelsScannerIntegrationTest.java @@ -140,7 +140,7 @@ void testConsumerBinding() { ChannelObject expectedChannel = ChannelObject.builder() .bindings(channelBinding) - .messages(Map.of(message.getName(), MessageReference.toComponentMessage(message))) + .messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message))) .build(); Operation expectedOperation = Operation.builder() @@ -193,7 +193,7 @@ void testSupplierBinding() { ChannelObject expectedChannel = ChannelObject.builder() .bindings(channelBinding) - .messages(Map.of(message.getName(), MessageReference.toComponentMessage(message))) + .messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message))) .build(); assertThat(actualChannels).containsExactly(Map.entry(topicName, expectedChannel)); @@ -245,7 +245,8 @@ void testFunctionBinding() { ChannelObject subscribeChannel = ChannelObject.builder() .bindings(channelBinding) - .messages(Map.of(subscribeMessage.getName(), MessageReference.toComponentMessage(subscribeMessage))) + .messages( + Map.of(subscribeMessage.getMessageId(), MessageReference.toComponentMessage(subscribeMessage))) .build(); MessageObject publishMessage = MessageObject.builder() @@ -270,7 +271,7 @@ void testFunctionBinding() { ChannelObject publishChannel = ChannelObject.builder() .bindings(channelBinding) - .messages(Map.of(publishMessage.getName(), MessageReference.toComponentMessage(publishMessage))) + .messages(Map.of(publishMessage.getMessageId(), MessageReference.toComponentMessage(publishMessage))) .build(); assertThat(actualChannels) @@ -324,7 +325,8 @@ void testKStreamFunctionBinding() { ChannelObject subscribeChannel = ChannelObject.builder() .bindings(channelBinding) - .messages(Map.of(subscribeMessage.getName(), MessageReference.toComponentMessage(subscribeMessage))) + .messages( + Map.of(subscribeMessage.getMessageId(), MessageReference.toComponentMessage(subscribeMessage))) .build(); MessageObject publishMessage = MessageObject.builder() @@ -349,7 +351,7 @@ void testKStreamFunctionBinding() { ChannelObject publishChannel = ChannelObject.builder() .bindings(channelBinding) - .messages(Map.of(publishMessage.getName(), MessageReference.toComponentMessage(publishMessage))) + .messages(Map.of(publishMessage.getMessageId(), MessageReference.toComponentMessage(publishMessage))) .build(); assertThat(actualChannels) @@ -426,9 +428,9 @@ void testFunctionBindingWithSameTopicName() { ChannelObject mergedChannel = ChannelObject.builder() .bindings(channelBinding) .messages(Map.of( - publishMessage.getName(), + publishMessage.getMessageId(), MessageReference.toComponentMessage(publishMessage), - subscribeMessage.getName(), + subscribeMessage.getMessageId(), MessageReference.toComponentMessage(subscribeMessage))) .build();