Skip to content

Commit

Permalink
fix(core): create correct servers reference
Browse files Browse the repository at this point in the history
  • Loading branch information
timonback committed Mar 5, 2024
1 parent a3b4743 commit c6c917d
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public class ServerReference implements Reference {
public String getRef() {
return ref;
}

public static ServerReference fromServer(String server) {
return new ServerReference("#/servers/" + server);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@ private Map.Entry<String, ChannelObject> buildChannel(MethodAndAnnotation<A> met
List<String> servers = AsyncAnnotationUtil.getServers(operationAnnotation, resolver);
if (servers != null && !servers.isEmpty()) {
validateServers(servers, operation.getTitle());
channelBuilder.servers(servers.stream()
.map(it -> ServerReference.builder().ref(it).build())
.toList());
channelBuilder.servers(
servers.stream().map(ServerReference::fromServer).toList());
}
MessageObject message = buildMessage(operationAnnotation, methodAndAnnotation.method());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,18 +204,7 @@ void scan_componentHasListenerMethodWithAllAttributes() {
ChannelObject expectedChannel = ChannelObject.builder()
.bindings(null)
.messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message)))
.servers(List.of(
ServerReference.builder().ref("server1").build(),
ServerReference.builder().ref("server2").build()))
.build();

Operation expectedOperation = Operation.builder()
.action(OperationAction.SEND)
.title("test-channel_send")
.channel(ChannelReference.fromChannel("test-channel"))
.description("description")
.bindings(Map.of(TestOperationBindingProcessor.TYPE, TestOperationBindingProcessor.BINDING))
.messages(List.of(MessageReference.toChannelMessage("test-channel", message)))
.servers(List.of(ServerReference.fromServer("server1"), ServerReference.fromServer("server2")))
.build();

assertThat(actualChannels).containsExactly(Map.entry("test-channel", expectedChannel));
Expand Down Expand Up @@ -244,29 +233,11 @@ void scan_componentHasMultipleListenerAnnotations() {
.description("SimpleFoo Message Description")
.build();

Operation expectedOperation1 = Operation.builder()
.action(OperationAction.SEND)
.channel(ChannelReference.fromChannel("test-channel-1"))
.description("test-channel-1-description")
.title("test-channel-1_send")
.bindings(EMPTY_MAP)
.messages(List.of(MessageReference.toChannelMessage("test-channel-1", message)))
.build();

ChannelObject expectedChannel1 = ChannelObject.builder()
.messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message)))
.bindings(null)
.build();

Operation expectedOperation2 = Operation.builder()
.action(OperationAction.SEND)
.channel(ChannelReference.fromChannel("test-channel-2"))
.description("test-channel-2-description")
.title("test-channel-2_send")
.bindings(EMPTY_MAP)
.messages(List.of(MessageReference.toChannelMessage("test-channel-2", message)))
.build();

ChannelObject expectedChannel2 = ChannelObject.builder()
.messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message)))
.bindings(null)
Expand Down Expand Up @@ -301,15 +272,6 @@ void scan_componentHasAsyncMethodAnnotation() {
.bindings(EMPTY_MAP)
.build();

Operation expectedOperation = Operation.builder()
.action(OperationAction.SEND)
.channel(ChannelReference.fromChannel("test-channel"))
.description("test channel operation description")
.title("test-channel_send")
.bindings(EMPTY_MAP)
.messages(List.of(MessageReference.toChannelMessage("test-channel", message)))
.build();

ChannelObject expectedChannel = ChannelObject.builder()
.bindings(null)
.messages(Map.of(message.getName(), MessageReference.toComponentMessage(message)))
Expand Down Expand Up @@ -416,15 +378,6 @@ void scan_componentHasOnlyDeclaredMethods(Class<?> clazz) {
.bindings(EMPTY_MAP)
.build();

Operation expectedOperation = Operation.builder()
.action(OperationAction.SEND)
.channel(ChannelReference.fromChannel("test-channel"))
.description("test channel operation description")
.title("test-channel_send")
.bindings(EMPTY_MAP)
.messages(List.of(MessageReference.toChannelMessage("test-channel", message)))
.build();

ChannelObject expectedChannel = ChannelObject.builder()
.bindings(null)
.messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import io.github.springwolf.asyncapi.v3.model.channel.ChannelObject;
import io.github.springwolf.asyncapi.v3.model.channel.ChannelReference;
import io.github.springwolf.asyncapi.v3.model.channel.ServerReference;
import io.github.springwolf.asyncapi.v3.model.channel.message.MessageHeaders;
import io.github.springwolf.asyncapi.v3.model.channel.message.MessageObject;
import io.github.springwolf.asyncapi.v3.model.channel.message.MessagePayload;
Expand Down Expand Up @@ -192,14 +191,6 @@ void scan_componentHasListenerMethodWithAllAttributes() {
.bindings(EMPTY_MAP)
.build();

ChannelObject expectedChannel = ChannelObject.builder()
.bindings(null)
.messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message)))
.servers(List.of(
ServerReference.builder().ref("server1").build(),
ServerReference.builder().ref("server2").build()))
.build();

Operation expectedOperation = Operation.builder()
.action(OperationAction.SEND)
.title("test-channel_send")
Expand Down Expand Up @@ -245,11 +236,6 @@ void scan_componentHasMultipleListenerAnnotations() {
.messages(List.of(MessageReference.toChannelMessage("test-channel-1", message)))
.build();

ChannelObject expectedChannel1 = ChannelObject.builder()
.messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message)))
.bindings(null)
.build();

Operation expectedOperation2 = Operation.builder()
.action(OperationAction.SEND)
.channel(ChannelReference.fromChannel("test-channel-2"))
Expand All @@ -259,11 +245,6 @@ void scan_componentHasMultipleListenerAnnotations() {
.messages(List.of(MessageReference.toChannelMessage("test-channel-2", message)))
.build();

ChannelObject expectedChannel2 = ChannelObject.builder()
.messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message)))
.bindings(null)
.build();

assertThat(actualOperations)
.containsExactlyInAnyOrderEntriesOf(Map.of(
"test-channel-1_send_methodWithMultipleAnnotation", expectedOperation1,
Expand Down Expand Up @@ -302,11 +283,6 @@ void scan_componentHasAsyncMethodAnnotation() {
.messages(List.of(MessageReference.toChannelMessage("test-channel", message)))
.build();

ChannelObject expectedChannel = ChannelObject.builder()
.bindings(null)
.messages(Map.of(message.getName(), MessageReference.toComponentMessage(message)))
.build();

assertThat(actualOperations)
.containsExactly(Map.entry("test-channel_send_methodWithAnnotation", expectedOperation));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class NestedProducer {
@AsyncOperation(
channelName = "topic-defined-via-asyncPublisher-annotation",
description = "Custom, optional description defined in the AsyncPublisher annotation",
servers = {"kafka"},
headers =
@AsyncOperation.Headers(
schemaName = "SpringDefaultHeaderAndCloudEvent",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,12 @@
"io.github.springwolf.examples.kafka.dtos.NestedPayloadDto": {
"$ref": "#/components/messages/io.github.springwolf.examples.kafka.dtos.NestedPayloadDto"
}
}
},
"servers": [
{
"$ref": "#/servers/kafka"
}
]
},
"xml-topic": {
"messages": {
Expand Down Expand Up @@ -1297,4 +1302,4 @@
]
}
}
}
}

0 comments on commit c6c917d

Please sign in to comment.