Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different fixes in the asyncapi v3 spec examples #543

Merged
merged 17 commits into from
Jan 18, 2024
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class SQSChannelBindingQueue {
* identifier should be the one in this field.
*/
@NotNull
@JsonProperty("queue")
@JsonProperty("name")
private String name;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import java.util.List;

/**
* SQS Point-To-Point
* </p>
Expand All @@ -32,7 +34,7 @@ public class SQSOperationBinding extends OperationBinding {
*/
@NotNull
@JsonProperty("queues")
private SQSChannelBindingQueue queues;
private List<SQSChannelBindingQueue> queues;

/**
* Optional, defaults to latest. The version of this binding.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ public class DefaultChannelsService implements ChannelsService {
private final List<? extends ChannelsScanner> channelsScanners;

/**
* Collects all AsyncAPI ChannelItems using the available {@link ChannelsScanner}
* Collects all AsyncAPI ChannelObjects using the available {@link ChannelsScanner}
* beans.
* @return Map of channel names mapping to detected ChannelItems
* @return Map of channel names mapping to detected ChannelObject
*/
@Override
public Map<String, ChannelObject> findChannels() {
Expand All @@ -41,7 +41,11 @@ public Map<String, ChannelObject> findChannels() {
return ChannelMerger.mergeChannels(foundChannelItems);
}

// FIXME
/**
* Collects all AsyncAPI Operation using the available {@link ChannelsScanner}
* beans.
* @return Map of operation names mapping to detected Operation
*/
@Override
public Map<String, Operation> findOperations() {
List<Map.Entry<String, Operation>> foundOperations = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,7 @@ private Stream<MethodAndAnnotation<A>> getAnnotatedMethods(Class<?> type) {
}

private boolean isInvalidChannel(Map.Entry<String, ChannelObject> entry) {
// Operation publish = entry.getValue().getPublish();
// boolean publishBindingExists = publish != null && publish.getBindings() != null;
//
// Operation subscribe = entry.getValue().getSubscribe();
// boolean subscribeBindingExists = subscribe != null && subscribe.getBindings() != null;

boolean allNonNull = entry.getKey() != null; // && (publishBindingExists || subscribeBindingExists); FIXME
boolean allNonNull = entry.getKey() != null;
ctasada marked this conversation as resolved.
Show resolved Hide resolved

if (!allNonNull) {
log.warn(
Expand All @@ -113,13 +107,7 @@ private boolean isInvalidChannel(Map.Entry<String, ChannelObject> entry) {
}

private boolean isInvalidOperation(Map.Entry<String, Operation> entry) {
// Operation publish = entry.getValue().getPublish();
// boolean publishBindingExists = publish != null && publish.getBindings() != null;
//
// Operation subscribe = entry.getValue().getSubscribe();
// boolean subscribeBindingExists = subscribe != null && subscribe.getBindings() != null;

boolean allNonNull = entry.getKey() != null; // && (publishBindingExists || subscribeBindingExists); FIXME
boolean allNonNull = entry.getKey() != null;

if (!allNonNull) {
log.warn(
Expand All @@ -142,7 +130,6 @@ private Map.Entry<String, ChannelObject> buildChannel(MethodAndAnnotation<A> met

List<String> servers = AsyncAnnotationScannerUtil.getServers(operationAnnotation, resolver);
if (servers != null && !servers.isEmpty()) {
// FIXME: It was originally operationId, which doesn't exist anymore
validateServers(servers, operation.getTitle());
channelBuilder.servers(servers.stream()
.map(it -> ServerReference.builder().ref(it).build())
Expand All @@ -157,19 +144,13 @@ private Map.Entry<String, ChannelObject> buildChannel(MethodAndAnnotation<A> met
}

private Map.Entry<String, Operation> buildOperation(MethodAndAnnotation<A> methodAndAnnotation) {
Operation.OperationBuilder operationBuilder = Operation.builder();
AsyncOperation operationAnnotation =
this.asyncAnnotationProvider.getAsyncOperation(methodAndAnnotation.annotation());
String operationName = resolver.resolveStringValue(operationAnnotation.channelName());

Operation operation = buildOperation(operationAnnotation, methodAndAnnotation.method(), operationName);
operation.setAction(this.asyncAnnotationProvider.getOperationType());

MessageObject message = buildMessage(operationAnnotation, methodAndAnnotation.method());

// FIXME
// Operation operation =
// operationBuilder.messages(Map.of(message.getMessageId(), message)).build();
return Map.entry(operationName, operation);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ public static void processAsyncMessageAnnotation(
messageBuilder.name(annotationName);
}

// FIXME
// String annotationSchemaFormat = asyncMessage.schemaFormat();
// var schemaFormat = annotationSchemaFormat != null ? annotationSchemaFormat :
// Message.DEFAULT_SCHEMA_FORMAT;
// messageBuilder.schemaFormat(schemaFormat);

String annotationTitle = resolver.resolveStringValue(asyncMessage.title());
if (StringUtils.hasText(annotationTitle)) {
messageBuilder.title(annotationTitle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ private Stream<Map.Entry<String, ChannelObject>> mapClassToChannel(Class<?> comp
}

private Stream<Map.Entry<String, Operation>> mapClassToOperation(Class<?> component) {
log.debug("Mapping class \"{}\" to channels", component.getName());
log.debug("Mapping class \"{}\" to operations", component.getName());

ClassAnnotation classAnnotation = AnnotationUtil.findAnnotationOrThrow(classAnnotationClass, component);

Expand All @@ -106,7 +106,6 @@ private Stream<Map.Entry<String, Operation>> mapClassToOperation(Class<?> compon
return Stream.empty();
}

// FIXME
String channelName = bindingFactory.getChannelName(classAnnotation);
String operationId = channelName + "_receive_" + component.getSimpleName();

Expand Down Expand Up @@ -173,13 +172,11 @@ private Operation buildOperation(ClassAnnotation classAnnotation, Map<String, Me
Map<String, OperationBinding> opBinding = operationBinding != null ? new HashMap<>(operationBinding) : null;
String channelName = bindingFactory.getChannelName(classAnnotation);

// var messageReferences = messages.values().stream().map(m -> MessageReference.fromMessage(m)).toList();

// FIXME
return Operation.builder()
.action(OperationAction.RECEIVE)
.channel(ChannelReference.fromChannel(channelName))
// .messages(messageReferences)
// FIXME: Adding MessageReferences fails kakfa-example. We need to investigate
// .messages(messages.values().stream().toList())
.bindings(opBinding)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ private AsyncAPI getAsyncAPITestObject() {
.schema(MessageReference.toSchema("ExamplePayload"))
.build()))
.bindings(Map.of(
// FIXME: We should have a SchemaString (Schema<String>)
"kafka",
new KafkaMessageBinding(
SchemaObject.builder().type("string").build(), null, null, null, "binding-version-1")))
KafkaMessageBinding.builder()
// FIXME: We should have a SchemaString (Schema<String>)
.key(SchemaObject.builder().type("string").build())
.build()))
.build();
Map<String, Message> messages = Map.of(message.getMessageId(), message);

Expand All @@ -106,7 +107,6 @@ private AsyncAPI getAsyncAPITestObject() {
.description("This channel is used to exchange messages about users signing up")
.servers(List.of(
ServerReference.builder().ref("#/servers/production").build()))
// .subscribe(newUserOperation) FIXME
.messages(Map.of(message.getMessageId(), MessageReference.toComponentMessage(message)))
.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,38 @@ void shouldMergeDifferentMessageForSameOperation() {
}

@Test
void shouldUseOtherMessageIfFirstMessageIsMissing() {
void shouldUseOtherMessageIfFirstMessageIsMissingForChannels() {
// given
String channelName = "channel";
MessageObject message2 = MessageObject.builder()
.messageId("message2")
.messageId(String.class.getCanonicalName())
.name(String.class.getCanonicalName())
.description("This is a string")
.build();
ChannelObject publisherChannel1 = ChannelObject.builder().build();
ChannelObject publisherChannel2 = ChannelObject.builder()
.messages(Map.of(message2.getName(), message2))
.build();

// when
Map<String, ChannelObject> mergedChannels = ChannelMerger.mergeChannels(
Arrays.asList(Map.entry(channelName, publisherChannel1), Map.entry(channelName, publisherChannel2)));

// then expectedMessage message2
var expectedMessages = Map.of(message2.getName(), message2);

assertThat(mergedChannels).hasSize(1).hasEntrySatisfying(channelName, it -> {
assertThat(it.getMessages()).hasSize(1);
assertThat(it.getMessages()).containsExactlyInAnyOrderEntriesOf(expectedMessages);
});
}

@Test
void shouldUseOtherMessageIfFirstMessageIsMissingForOperations() {
// given
String channelName = "channel-name";
MessageObject message2 = MessageObject.builder()
.messageId(String.class.getCanonicalName())
.name(String.class.getCanonicalName())
.description("This is a string")
.build();
Expand All @@ -238,24 +265,16 @@ void shouldUseOtherMessageIfFirstMessageIsMissing() {
.title("publisher2")
.messages(List.of(MessageReference.toChannelMessage(channelName, message2)))
.build();
ChannelObject publisherChannel1 =
ChannelObject.builder() /*.publish(publishOperation1)FIXME*/.build();
ChannelObject publisherChannel2 =
ChannelObject.builder() /*.publish(publishOperation2)FIXME*/.build();

// when
Map<String, ChannelObject> mergedChannels = ChannelMerger.mergeChannels(
Arrays.asList(Map.entry(channelName, publisherChannel1), Map.entry(channelName, publisherChannel2)));

Map<String, Operation> mergedOperations = ChannelMerger.mergeOperations(
Arrays.asList(Map.entry("publisher1", publishOperation1), Map.entry("publisher1", publishOperation2)));
// then expectedMessage message2
var expectedMessages = MessageHelper.toMessagesMap(Set.of(message2));
assertThat(mergedChannels).hasSize(1).hasEntrySatisfying(channelName, it -> {
// assertThat(it.getPublish()) FIXME
// .isEqualTo(Operation.builder()
// .title("publisher1")
// .message(expectedMessages) FIXME
// .build());
// assertThat(it.getSubscribe()).isNull(); FIXME
var expectedMessage = MessageReference.toChannelMessage(channelName, message2);

assertThat(mergedOperations).hasSize(1).hasEntrySatisfying("publisher1", it -> {
assertThat(it.getMessages()).hasSize(1);
assertThat(it.getMessages()).containsExactlyInAnyOrder(expectedMessage);
});
}
}
Loading