davsclaus commented on code in PR #30803:
URL: https://github.com/apache/camel/pull/30803#discussion_r4701071952


##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/ProjectBodies.java:
##########
@@ -0,0 +1,102 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.dsl.jbang.core.commands.ai;
+
+import java.nio.file.Path;
+import java.util.Comparator;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.camel.catalog.CamelCatalog;
+import org.apache.camel.dsl.jbang.core.commands.ai.ProjectRoutes.Route;
+import org.apache.camel.dsl.yaml.validator.BodyOrigin;
+import org.apache.camel.dsl.yaml.validator.ProjectFacts;
+import org.apache.camel.dsl.yaml.validator.YamlValidator;
+
+/**
+ * Where the message body of each YAML route of a project comes from, for 
{@code camel overview} (CAMEL-25200). It is
+ * the analysis of the body check of {@code camel validate}, made the way 
{@code camel validate} makes it: per file,
+ * with the same schema validator, only for a file that passes the schema, and 
with the GET operations of an OpenAPI
+ * contract beside the route known to carry no body. So the {@code 
body-never-set} findings of the two are the same.
+ */
+final class ProjectBodies {
+
+    private ProjectBodies() {
+    }
+
+    /**
+     * The body origin of each YAML route, by the key of the route in the 
overview.
+     *
+     * @param dir     the project directory, for the OpenAPI contracts the 
routes bind to; may be null
+     * @param sources the content of each route file by its path relative to 
the directory
+     * @param routes  the routes of the overview
+     */
+    static Map<String, BodyOrigin> analyze(
+            Path dir, Map<String, String> sources, List<Route> routes, 
CamelCatalog catalog) {
+        Map<String, BodyOrigin> answer = new LinkedHashMap<>();
+        YamlValidator validator = null;
+        for (Map.Entry<String, String> e : sources.entrySet()) {
+            String file = e.getKey();
+            String name = file.toLowerCase(Locale.ROOT);
+            if (!name.endsWith(".yaml") && !name.endsWith(".yml")) {
+                continue;
+            }
+            List<BodyOrigin> origins;
+            try {
+                if (validator == null) {
+                    validator = catalog != null
+                            ? SourceValidator.yamlValidator(catalog) : 
SourceValidator.yamlValidator();
+                }
+                Set<String> bodyless = dir != null ? 
OpenApiVerbs.bodylessEndpoints(e.getValue(), dir) : Set.of();
+                origins = validator.bodyOrigins(e.getValue(), new 
ProjectFacts(bodyless, Map.of(), null));
+            } catch (Exception ex) {
+                // the overview is still an overview without the bodies
+                continue;
+            }
+            if (!origins.isEmpty()) {
+                match(file, origins, routes, answer);
+            }

Review Comment:
   Added in 80abf4a10425: `LOG.debug("Cannot analyze the message bodies of {}: 
{}", file, ex.getMessage(), ex)` before the `continue`.
   
   _Claude Code on behalf of davsclaus_



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