fjtirado commented on code in PR #4178:
URL: 
https://github.com/apache/incubator-kie-kogito-runtimes/pull/4178#discussion_r2759800568


##########
quarkus/addons/asyncapi/deployment/src/main/java/org/kie/kogito/quarkus/serverless/workflow/asyncapi/AsyncAPIInfoConverter.java:
##########
@@ -48,19 +51,57 @@ public Optional<AsyncInfo> apply(String id) {
 
     private static AsyncInfo from(AsyncAPI asyncApi) {
         Map<String, AsyncChannelInfo> map = new HashMap<>();
-        for (Entry<String, ChannelItem> entry : 
asyncApi.getChannels().entrySet()) {
-            addChannel(map, entry.getValue().getPublish(), entry.getKey() + 
"_out", true);
-            addChannel(map, entry.getValue().getSubscribe(), entry.getKey(), 
false);
+
+        // AsyncAPI v3.0.0 migration: In v3, channels and operations are 
separate top-level objects
+        // v2: channels contained publish/subscribe operations directly
+        // v3: operations reference channels via $ref, and channels have 
addresses
+        // Build a helper map: channelId -> address (topic/path)
+        Map<String, String> channelIdToAddress = new HashMap<>();
+        if (asyncApi.getChannels() != null) {
+            for (Entry<String, Object> ch : asyncApi.getChannels().entrySet()) 
{
+                String channelId = ch.getKey();
+                if (ch.getValue() instanceof Channel) {
+                    Channel channel = (Channel) ch.getValue();
+                    // In v3, address holds the actual path/topic (key is just 
an ID)
+                    String address = 
Optional.ofNullable(channel.getAddress()).orElse(channelId);
+                    channelIdToAddress.put(channelId, address);
+                }
+            }
         }
-        return new AsyncInfo(map);
-    }
 
-    private static void addChannel(Map<String, AsyncChannelInfo> map, 
Operation operation, String channelName, boolean publish) {
-        if (operation != null) {
-            String operationId = operation.getOperationId();
-            if (operationId != null) {
-                map.putIfAbsent(operationId, new AsyncChannelInfo(channelName, 
publish));
+        // Iterate operations and map operation key -> AsyncChannelInfo
+        if (asyncApi.getOperations() != null) {
+            for (Entry<String, Object> opEntry : 
asyncApi.getOperations().entrySet()) {
+                String opKey = opEntry.getKey();
+                if (!(opEntry.getValue() instanceof Operation)) {
+                    continue;
+                }
+                Operation op = (Operation) opEntry.getValue();
+
+                // In v3.0.0, the operation key is the operation identifier
+                String operationId = opKey;
+
+                // Resolve the referenced channel ID from "$ref: 
#/channels/<id>"
+                String channelId = null;
+                if (op.getChannel() != null) {
+                    String ref = op.getChannel().getRef(); // expected form
+                    if (ref != null && ref.contains("/")) {
+                        channelId = ref.substring(ref.lastIndexOf('/') + 1);
+                    }
+                }
+
+                String address = channelId != null ? 
channelIdToAddress.get(channelId) : null;
+                OperationAction action = op.getAction();
+
+                if (operationId != null && address != null && action != null) {
+                    // AsyncAPI v3.0.0: action is now OperationAction enum 
(SEND/RECEIVE) instead of v2's publish/subscribe
+                    boolean publish = action == OperationAction.SEND; // send 
-> we publish, receive -> we consume
+                    String channelName = publish ? address + "_out" : address;
+                    map.putIfAbsent(operationId, new 
AsyncChannelInfo(channelName, publish));
+                }

Review Comment:
   I think this code should nested withint the previous if (that way you save a 
couple of redudant if). 
   For example, if op.getChannel is null, channelId will be null, adrress will 
be null, and the map.putIfAbsent block will never be executed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to