-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: Multiple fixes related with Channel Messages Some of the tests are failing due to some AssertJ recursion issue. Help is welcome * fix: Minor properties fixes * fix: Fixes to AMQP Some fixes to the AMQP plugin and example (Still not finished) * fix: Minor properties fixes * fix: Migrated asyncapi.json examples to v3 * fix: Migration to AsyncAPI v3 As per https://www.asyncapi.com/docs/migration/migrating-to-v3 For a channel with multiple messages, you specify multiple key-value pairs. For a channel with just one message, you use a single key-value pair. That means that the use of 'oneOf' is removed. * fix: Improved support for Channel Messages Fixed different bugs and limitations with the publishing of Messages in a Channel with the AsyncAPI v3 spec * fix: Fixed Channel Merger When merging Channels, the messages were not merged. This is now fixed. * fix: Added basic support for Operations Still plenty of errors, but Operations are now appearing in the AsyncAPI v3 output. * fix: AsyncAPI module test
- Loading branch information
Showing
58 changed files
with
1,571 additions
and
903 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 13 additions & 24 deletions
37
springwolf-core/src/main/java/io/github/stavshamir/springwolf/asyncapi/MessageHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,40 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.stavshamir.springwolf.asyncapi; | ||
|
||
import io.github.stavshamir.springwolf.asyncapi.v3.model.channel.message.Message; | ||
import io.github.stavshamir.springwolf.asyncapi.v3.model.channel.message.MessageObject; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.TreeSet; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
|
||
@Slf4j | ||
public class MessageHelper { | ||
private static final String ONE_OF = "oneOf"; | ||
|
||
private static final Comparator<MessageObject> byMessageName = Comparator.comparing(MessageObject::getName); | ||
|
||
private static final Supplier<Set<MessageObject>> messageSupplier = () -> new TreeSet<>(byMessageName); | ||
|
||
public static Object toMessageObjectOrComposition(Set<MessageObject> messages) { | ||
return switch (messages.size()) { | ||
case 0 -> throw new IllegalArgumentException("messages must not be empty"); | ||
case 1 -> messages.toArray()[0]; | ||
default -> Map.of( | ||
ONE_OF, new ArrayList<>(messages.stream().collect(Collectors.toCollection(messageSupplier)))); | ||
}; | ||
} | ||
private MessageHelper() {} | ||
|
||
@SuppressWarnings("unchecked") | ||
public static Set<MessageObject> messageObjectToSet(Object messageObject) { | ||
if (messageObject instanceof MessageObject message) { | ||
return new HashSet<>(Collections.singletonList(message)); | ||
public static Map<String, Message> toMessagesMap(Set<MessageObject> messages) { | ||
if (messages.isEmpty()) { | ||
throw new IllegalArgumentException("messages must not be empty"); | ||
} | ||
|
||
if (messageObject instanceof Map) { | ||
List<MessageObject> messages = ((Map<String, List<MessageObject>>) messageObject).get(ONE_OF); | ||
return new HashSet<>(messages); | ||
} | ||
return new ArrayList<>(messages.stream().collect(Collectors.toCollection(messageSupplier))) | ||
.stream().collect(Collectors.toMap(MessageObject::getMessageId, Function.identity())); | ||
} | ||
|
||
log.warn( | ||
"Message object must contain either a Message or a Map<String, Set<Message>, but contained: {}", | ||
messageObject.getClass()); | ||
return new HashSet<>(); | ||
// FIXME: Do we need this method? | ||
@SuppressWarnings("unchecked") | ||
public static Set<Message> messageObjectToSet(Map<String, Message> messages) { | ||
return new HashSet<>(messages.values()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.