gnodet-bot commented on code in PR #30345:
URL: https://github.com/apache/camel/pull/30345#discussion_r4623651472
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/AuthoringTools.java:
##########
@@ -198,6 +198,54 @@ static void register(Consumer<ToolDescriptor> registry) {
integer(args, "limit",
CatalogSamples.DEFAULT_LIMIT));
}));
+ registry.accept(tool("camel_catalog_pattern_recipes",
+ "Curated integration-pattern recipes from the Camel catalog:
complete route compositions, transport "
+ + "alternatives,
component requirements, recommended options, pitfalls and example links. "
+ + "Use term to
filter by recipe content; use camel_catalog_sample for an individual EIP or "
+ + "component
YAML example, and camel_catalog_doc to check the selected version's options.")
+ .param("term", "string",
+ "Optional phrase to match in recipe names, problems,
routes, options, requirements or pitfalls", false)
+ .param("camelVersion", "string", VERSION_DESC, false)
+ .core(true)
+ .deterministic(true)
+ .repeatHint("Use the matching recipe as a starting point, then
check its component and EIP options with "
+ + "camel_catalog_doc and validate the resulting
route with camel_validate_source.")
+ .executor((ctx, args) -> {
+ applyVersion(ctx, args);
+ String json = ctx.catalog().patternRecipesJSon();
+ if (json == null) {
+ throw new ToolExecutionException(
+ "Pattern recipes are not available in Camel
catalog version "
+ +
ctx.catalog().getLoadedVersion());
+ }
+ String term = args.get("term");
+ if (term == null || term.isBlank()) {
+ return json;
+ }
+ try {
+ Object parsed = Jsoner.deserialize(json);
+ if (!(parsed instanceof JsonObject answer)) {
+ throw new IllegalStateException("The pattern
recipes document is not a JSON object");
+ }
+ Collection<?> entries =
answer.getCollection("recipes");
+ if (entries == null) {
+ throw new IllegalStateException("The pattern
recipes document has no recipes array");
+ }
+ String query = term.toLowerCase(Locale.ROOT);
+ JsonArray matches = new JsonArray();
+ for (Object entry : entries) {
+ if (entry instanceof JsonObject recipe
+ &&
recipe.toJson().toLowerCase(Locale.ROOT).contains(query)) {
+ matches.add(recipe);
+ }
+ }
+ answer.put("recipes", matches);
+ return answer.toJson();
+ } catch (Exception e) {
+ throw new ToolExecutionException("The Camel pattern
recipes resource could not be read as JSON");
Review Comment:
🐛 The caught exception `e` is not chained as the cause here, so the original
stack trace (and any underlying message) is silently discarded. This makes
debugging harder when the JSON parsing fails.
```suggestion
throw new ToolExecutionException("The Camel pattern
recipes resource could not be read as JSON", e);
```
##########
dsl/camel-yaml-dsl/camel-yaml-dsl-validator/src/test/java/org/apache/camel/dsl/yaml/validator/PatternRecipesYamlValidationTest.java:
##########
@@ -0,0 +1,609 @@
+/*
+ * 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.yaml.validator;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+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.catalog.DefaultCamelCatalog;
+import org.apache.camel.tooling.model.JsonMapper;
+import org.apache.camel.util.json.JsonObject;
+import org.junit.jupiter.api.Test;
+import tools.jackson.databind.JsonNode;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Validates the curated pattern recipes against the YAML DSL schema and the
Camel Catalog metadata for the same Camel
+ * release.
+ */
+public class PatternRecipesYamlValidationTest {
+
+ private static final Map<String, Map<String, String>> EXPECTED_EXAMPLES =
Map.ofEntries(
+ Map.entry("idempotent-consumer",
+ Map.of("route/enrich-and-dedupe", "direct")),
+ Map.entry("content-based-routing-with-validation",
+ Map.of("route/content-based-router", "related")),
+ Map.entry("file-polling-with-idempotent-repository",
+ Map.of("connect/file-processing", "related")),
+ Map.entry("throttling-rate-limiting",
+ Map.of("route/dynamic-routing", "related")),
+ Map.entry("error-handling-dead-letter-redelivery",
+ Map.of("fail-well/error-handling", "direct")),
+ Map.entry("jms-asynchronous-request-reply",
+ Map.of("connect-service/jms-request-reply", "direct")),
+ Map.entry("circuit-breaker-with-fallback",
+ Map.of("fail-well/circuit-breaker", "direct")),
+ Map.entry("scatter-gather-with-timeout",
+ Map.of(
+ "route/filter-and-multicast", "related",
+ "route/aggregator", "related")),
+ Map.entry("transactional-outbox",
+ Map.of(
+ "connect-service/sql", "building-block",
+ "connect-service/artemis", "building-block")));
+
+ private static final Set<String> EXPECTED_NO_EXAMPLE_RECIPE_IDS = Set.of(
+ "saga-coordination-with-compensation");
+
+ private static final Set<String> ALLOWED_EXAMPLE_COVERAGE =
Set.of("direct", "related", "building-block");
+
+ private static final String EXAMPLE_REPOSITORY =
"apache/camel-jbang-examples";
+
+ private static final Set<String> EXPECTED_IDEMPOTENT_TRANSPORT_VARIANTS =
Set.of(
+ "kafka", "jms");
+
+ @Test
+ void everyRecipeYamlPassesCamelDslAndCatalogValidation() throws Exception {
+ CamelCatalog catalog = new DefaultCamelCatalog();
+ YamlValidator validator = new YamlValidator(true, null, catalog);
+ validator.init();
+
+ JsonNode yamlMapperTree;
Review Comment:
🔧 `yamlMapperTree` is declared but never assigned or read — the variable
used in the method body is `tree` (line ~1252 in the final file). This is dead
code that should be removed.
--
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]