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


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/OpenApiVerbs.java:
##########
@@ -62,34 +65,89 @@ public static Set<String> bodylessEndpoints(String content, 
Path directory) {
                 continue;
             }
             try {
-                String text = Files.readString(spec);
-                if (!text.stripLeading().startsWith("{")) {
-                    continue; // a YAML specification: not read here
-                }
-                JsonObject root = (JsonObject) Jsoner.deserialize(text);
-                JsonObject paths = root.getMap("paths");
+                Map<?, ?> paths = paths(Files.readString(spec));
                 if (paths == null) {
                     continue;
                 }
-                for (Map.Entry<String, Object> path : paths.entrySet()) {
-                    if (!(path.getValue() instanceof Map<?, ?> operations)) {
+                for (Object path : paths.values()) {
+                    if (!(path instanceof Map<?, ?> operations)) {
                         continue;
                     }
                     for (Map.Entry<?, ?> operation : operations.entrySet()) {
                         String verb = 
String.valueOf(operation.getKey()).toLowerCase(java.util.Locale.ROOT);
-                        if (!WITHOUT_BODY.contains(verb) || 
!(operation.getValue() instanceof Map<?, ?> details)) {
-                            continue;
-                        }
-                        Object id = details.get("operationId");
-                        if (id != null) {
-                            answer.add("direct:" + id);
+                        if (WITHOUT_BODY.contains(verb) && 
operation.getValue() instanceof Map<?, ?> details
+                                && details.get("operationId") != null) {
+                            answer.add("direct:" + details.get("operationId"));
                         }
                     }
                 }
             } catch (Exception e) {
-                // an unreadable or unparseable specification says nothing
+                // Catching Exception handles unreadable and unparseable JSON 
or YAML specifications.
             }
         }
         return answer;
     }
+
+    public static Set<String> requiredPathParameters(String specContent, 
String operationId) {

Review Comment:
   ⚠️ **Unused method (medium):** This new public method is not called anywhere 
in this PR or in the existing codebase. The CAMEL-24992 feature requires 
integrating this into `SourceValidator` (or equivalent) to walk the steps 
before a `rest-openapi:` call and check that headers matching these path 
parameter names are set. Without that integration, this method is orphaned 
infrastructure.
   
   Also: missing Javadoc on a new public API method — at minimum document the 
contract (what `specContent` is, what happens when `operationId` is not found, 
what the returned set contains).



##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/OpenApiVerbs.java:
##########
@@ -62,34 +65,89 @@ public static Set<String> bodylessEndpoints(String content, 
Path directory) {
                 continue;
             }
             try {
-                String text = Files.readString(spec);
-                if (!text.stripLeading().startsWith("{")) {
-                    continue; // a YAML specification: not read here
-                }
-                JsonObject root = (JsonObject) Jsoner.deserialize(text);
-                JsonObject paths = root.getMap("paths");
+                Map<?, ?> paths = paths(Files.readString(spec));
                 if (paths == null) {
                     continue;
                 }
-                for (Map.Entry<String, Object> path : paths.entrySet()) {
-                    if (!(path.getValue() instanceof Map<?, ?> operations)) {
+                for (Object path : paths.values()) {
+                    if (!(path instanceof Map<?, ?> operations)) {
                         continue;
                     }
                     for (Map.Entry<?, ?> operation : operations.entrySet()) {
                         String verb = 
String.valueOf(operation.getKey()).toLowerCase(java.util.Locale.ROOT);
-                        if (!WITHOUT_BODY.contains(verb) || 
!(operation.getValue() instanceof Map<?, ?> details)) {
-                            continue;
-                        }
-                        Object id = details.get("operationId");
-                        if (id != null) {
-                            answer.add("direct:" + id);
+                        if (WITHOUT_BODY.contains(verb) && 
operation.getValue() instanceof Map<?, ?> details
+                                && details.get("operationId") != null) {
+                            answer.add("direct:" + details.get("operationId"));
                         }
                     }
                 }
             } catch (Exception e) {
-                // an unreadable or unparseable specification says nothing
+                // Catching Exception handles unreadable and unparseable JSON 
or YAML specifications.
             }
         }
         return answer;
     }
+
+    public static Set<String> requiredPathParameters(String specContent, 
String operationId) {
+        Set<String> pathParams = new java.util.LinkedHashSet<>();

Review Comment:
   💡 **Nit (low):** `java.util.LinkedHashSet` is already imported at line 21. 
Use the simple name for consistency:
   
   ```suggestion
           Set<String> pathParams = new LinkedHashSet<>();
   ```



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