luigidemasi commented on code in PR #27082:
URL: https://github.com/apache/camel/pull/27082#discussion_r4141609282
##########
dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/TransformTools.java:
##########
@@ -151,6 +158,7 @@ private String transformYamlToXml(String yaml) throws
Exception {
RoutesDefinition rd = new RoutesDefinition();
rd.setRoutes(routeDefs);
+
rd.setSemantic(DefaultSemanticDefinitionConfigurer.getDefinition(ctx));
Review Comment:
Fixed in
[0bb166a78dfe](https://github.com/apache/camel/commit/0bb166a78dfe9539e9dd3c1194a668d7630acfa4).
Export now goes through `SemanticDefinitionConfigurer`, with context-plugin
lookup and lazy discovery in `SemanticDefinitionHelper`; this also covers
YAML-only registrations. MCP no longer references the implementation class.
The placeholder observation is correct: context-based conversion needs a
resolved numeric value. The documentation now states that requirement, and
tests cover both defaulted placeholders and missing required properties.
Conversion errors now include the underlying cause so YAML reports the missing
key instead of only a preparse failure.
_Generated by Codex via /oss-address-review on behalf of
[luigidemasi](https://github.com/luigidemasi)._
##########
dsl/camel-jbang/camel-jbang-mcp/src/main/java/org/apache/camel/dsl/jbang/core/commands/mcp/TransformTools.java:
##########
@@ -176,16 +184,25 @@ private String transformJavaToFormat(String java, String
targetFormat) throws Ex
"Could not parse Java route. Ensure it contains a
valid route definition.");
}
+ // Java expression clauses are normally materialized when
processors are created.
+ routeDefs.forEach(route ->
ProcessorDefinitionHelper.filterTypeInOutputs(route.getOutputs(),
ExpressionNode.class)
+ .forEach(ExpressionNode::preCreateProcessor));
Review Comment:
Added in
[0bb166a78dfe](https://github.com/apache/camel/commit/0bb166a78dfe9539e9dd3c1194a668d7630acfa4).
The parameterized regression converts a non-semantic `.filter().simple(...)`
with a nested `.setBody().simple(...)` to both YAML and XML, reloads each
output, and verifies that both Simple expressions are preserved.
_Generated by Codex via /oss-address-review on behalf of
[luigidemasi](https://github.com/luigidemasi)._
##########
components/camel-ai/camel-semantic/src/main/java/org/apache/camel/semantic/DefaultSemanticDefinitionConfigurer.java:
##########
@@ -0,0 +1,122 @@
+/*
+ * 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.semantic;
+
+import java.util.LinkedHashMap;
+import java.util.Locale;
+import java.util.Map;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.model.PropertyDefinition;
+import org.apache.camel.model.app.SemanticDefinition;
+import org.apache.camel.model.app.SemanticQuestionDefinition;
+import org.apache.camel.model.spi.SemanticDefinitionConfigurer;
+import org.apache.camel.spi.Resource;
+import org.apache.camel.util.StringHelper;
+
+/** Converts Java/XML declarations to the same immutable questions used by
YAML and programmatic registration. */
+public class DefaultSemanticDefinitionConfigurer implements
SemanticDefinitionConfigurer {
+ @Override
+ public void configure(CamelContext context, Resource resource, String
source, SemanticDefinition definition) {
+ Map<String, SemanticQuestion> questions = new LinkedHashMap<>();
+ if (definition != null) {
+ for (SemanticQuestionDefinition question :
definition.getQuestions()) {
+ String name = question.getName();
+ if (name == null || name.isBlank()) {
+ throw new IllegalArgumentException("Semantic question
requires a nonblank name");
+ }
+ if (questions.containsKey(name)) {
+ throw new IllegalArgumentException("Duplicate semantic
question: " + name);
+ }
+ try {
+ questions.put(name, question(context, question));
+ } catch (IllegalArgumentException e) {
+ throw new IllegalArgumentException("Invalid semantic
question '" + name + "': " + e.getMessage(), e);
+ }
+ }
+ }
+ // A YAML loader can register its own declarations from the same
resource before its RouteBuilder runs.
+ SemanticQuestions.get(context).replace("model:" + source, resource,
questions);
+ }
+
+ /** Export a snapshot of the registered questions and their effective
decision policies. */
+ public static SemanticDefinition getDefinition(CamelContext context) {
Review Comment:
Fixed in
[0bb166a78dfe](https://github.com/apache/camel/commit/0bb166a78dfe9539e9dd3c1194a668d7630acfa4).
Export omits threshold `0.5`, uncertainty `0`, and policy `fail`. Regression
tests verify that the compact output reloads with the same defaults for
YAML-to-XML and Java-to-YAML/XML; non-default policies remain covered by the
existing round-trip test.
_Generated by Codex via /oss-address-review on behalf of
[luigidemasi](https://github.com/luigidemasi)._
--
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]