gnodet-bot commented on code in PR #28242:
URL: https://github.com/apache/camel/pull/28242#discussion_r4336867221


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/CatalogDocs.java:
##########
@@ -1635,11 +1634,49 @@ private static void addCommonModelFields(JsonObject 
result, BaseModel<?> model)
         }
         if (!model.getBodyTypes().isEmpty()) {
             // what the body is after the step and what it needs, which the 
options do not say (CAMEL-24961)
-            result.put("bodyTypes", 
JsonMapper.asJsonObjectBodyTypes(model.getBodyTypes()));
+            result.put("bodyTypes", bodyTypes(model.getBodyTypes()));
             result.put("bodyTypesHint", BODY_TYPES_HINT);
         }
     }
 
+    /**
+     * The body types a line per side, as compact as the options are: the 
carriers, the Java type, the format, the
+     * description, the body for other option values, and the options that 
make it not known (CAMEL-24961).
+     */
+    static JsonObject bodyTypes(Map<String, BodyTypeModel> bodyTypes) {
+        JsonObject answer = new JsonObject();
+        for (Map.Entry<String, BodyTypeModel> entry : bodyTypes.entrySet()) {
+            BodyTypeModel side = entry.getValue();
+            StringBuilder line = new 
StringBuilder(carriers(side.getCarriers(), side.getJavaType()));
+            if (side.getFormat() != null) {
+                line.append(", as ").append(side.getFormat());
+            }
+            if (side.getDescription() != null) {
+                line.append(". ").append(side.getDescription());
+            }
+            if (!side.getByOption().isEmpty()) {
+                List<String> values = new ArrayList<>();
+                for (BodyTypeModel.OptionBodyTypeModel option : 
side.getByOption()) {
+                    values.add(option.getOption() + "=" + option.getValue() + 
": "
+                               + carriers(option.getCarriers(), 
option.getJavaType()));
+                }
+                line.append(". With ").append(String.join("; ", values));
+            }
+            if (!side.getDependsOn().isEmpty()) {
+                line.append(". Not known when ").append(String.join(" or ", 
side.getDependsOn())).append(" is set");
+            }
+            answer.put(entry.getKey(), line.toString());
+        }
+        return answer;
+    }
+
+    private static String carriers(List<String> carriers, String javaType) {
+        String answer = carriers.size() == 1
+                ? carriers.get(0)
+                : String.join(", ", carriers.subList(0, carriers.size() - 1)) 
+ " or " + carriers.get(carriers.size() - 1);
+        return javaType != null ? answer + " (" + javaType + ")" : answer;

Review Comment:
   ⚠️ **Latent `IndexOutOfBoundsException`**: if `carriers` is empty, the else 
branch calls `subList(0, -1)` (throws `IllegalArgumentException`) and `get(-1)` 
(throws `IndexOutOfBoundsException`). No current annotation triggers this, but 
the first `@BodyType` added without an explicit `value` will blow up here.
   
   ```suggestion
       private static String carriers(List<String> carriers, String javaType) {
           if (carriers.isEmpty()) {
               return javaType != null ? "(" + javaType + ")" : "unknown";
           }
           String answer = carriers.size() == 1
                   ? carriers.get(0)
                   : String.join(", ", carriers.subList(0, carriers.size() - 
1)) + " or " + carriers.get(carriers.size() - 1);
           return javaType != null ? answer + " (" + javaType + ")" : answer;
       }
   ```



##########
components/camel-aws/camel-aws2-sqs/src/main/java/org/apache/camel/component/aws2/sqs/Sqs2Endpoint.java:
##########
@@ -33,6 +33,9 @@
 import org.apache.camel.clock.Clock;
 import org.apache.camel.component.aws2.sqs.client.Sqs2ClientFactory;
 import org.apache.camel.spi.*;
+import org.apache.camel.spi.BodyType;
+import org.apache.camel.spi.BodyType.Carrier;
+import org.apache.camel.spi.BodyTypes;

Review Comment:
   💡 **Redundant explicit imports** (nit): `Sqs2Endpoint` already has `import 
org.apache.camel.spi.*;` — the wildcard already covers `BodyType`, 
`BodyType.Carrier`, and `BodyTypes`. Every other file in this PR correctly adds 
only the explicit imports (no wildcard). Either remove the wildcard or these 
three explicit imports to be consistent.
   
   ```suggestion
   ```



-- 
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]

Reply via email to