This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 6ea6b9e94894 CAMEL-26933: camel-openapi-rest-dsl-generator - the
routes of generate rest --routes validate and run (#29923)
6ea6b9e94894 is described below
commit 6ea6b9e94894e506d63b6fed26b177cf3c77e52d
Author: Claus Ibsen <[email protected]>
AuthorDate: Sat Nov 14 19:25:39 2026 +0100
CAMEL-26933: camel-openapi-rest-dsl-generator - the routes of generate rest
--routes validate and run (#29923)
The generated routes had no steps and the description of the operation
under from,
which has none: camel validate yaml reported 19 errors for the petstore
spec, and
camel run failed with "Route ... has no output processors".
The description goes on the route, and each route gets a log step that says
it is
not implemented yet, to replace with the implementation.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../modules/ROOT/pages/camel-jbang-projects.adoc | 3 ++-
.../core/commands/generate/CodeRestGeneratorTest.java | 18 ++++++++++++++++++
.../camel/generator/openapi/RestDslYamlGenerator.java | 15 +++++++++++----
...penApiV3PetstoreSimpleWithRoutesDescriptionYaml.txt | 4 +++-
.../OpenApiV3PetstoreSimpleWithRoutesYaml.txt | 2 ++
5 files changed, 36 insertions(+), 6 deletions(-)
diff --git a/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc
b/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc
index ab0998ebc891..799b446e1b88 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-jbang-projects.adoc
@@ -417,7 +417,8 @@ camel generate rest --input=petstore.yaml --dto
--runtime=quarkus --package=com.
----
`--routes` also generates a route for each operation (YAML only), and `--dto`
generates Java data objects
-for the schemas of the specification.
+for the schemas of the specification. Each generated route has a `log` step
that says it is not implemented yet: the
+routes run as they are (`camel run petstore-rest.yaml`), and you replace that
step with the implementation.
=== JSON schema
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-generate/src/test/java/org/apache/camel/dsl/jbang/core/commands/generate/CodeRestGeneratorTest.java
b/dsl/camel-jbang/camel-jbang-plugin-generate/src/test/java/org/apache/camel/dsl/jbang/core/commands/generate/CodeRestGeneratorTest.java
index a6de00bf1fab..66da5a1cba58 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-generate/src/test/java/org/apache/camel/dsl/jbang/core/commands/generate/CodeRestGeneratorTest.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-generate/src/test/java/org/apache/camel/dsl/jbang/core/commands/generate/CodeRestGeneratorTest.java
@@ -26,6 +26,7 @@ import java.util.stream.Stream;
import org.apache.camel.dsl.jbang.core.commands.CamelJBangMain;
import org.apache.camel.dsl.jbang.core.common.CommandLineTestHelper;
import org.apache.camel.dsl.jbang.run.common.StringPrinter;
+import org.apache.camel.dsl.yaml.validator.YamlValidator;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
@@ -109,6 +110,23 @@ class CodeRestGeneratorTest {
assertThat(target.resolve("sub").resolve("A.java")).hasContent("a");
}
+ @Test
+ void theRoutesOfTheRestDslValidate() throws Exception {
+ // the routes had no steps and a description under from: 19 errors of
camel validate yaml, and camel run
+ // failed with "Route ... has no output processors" (CAMEL-26933)
+ Path rest = dir.resolve("rest.yaml");
+ CodeRestGenerator command = new CodeRestGenerator(new
CamelJBangMain().withPrinter(printer));
+ CommandLineTestHelper.parse(command, "--input=" + SPEC, "--routes",
"--output=" + rest);
+
+ assertThat(command.doCall()).as(printer.getOutput()).isZero();
+
+ YamlValidator validator = new YamlValidator();
+ validator.init();
+ var errors = validator.validate(rest.toFile());
+ assertThat(errors).as(Files.readString(rest)).isEmpty();
+ assertThat(Files.readString(rest)).contains("- route:", "steps:",
"log: \"Not implemented yet: direct:");
+ }
+
private int generate(Path packageDir, String... args) throws Exception {
return generate(SPEC, packageDir, args);
}
diff --git
a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslYamlGenerator.java
b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslYamlGenerator.java
index dd01505a5850..6763b1fca4ab 100644
---
a/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslYamlGenerator.java
+++
b/tooling/openapi-rest-dsl-generator/src/main/java/org/apache/camel/generator/openapi/RestDslYamlGenerator.java
@@ -159,13 +159,20 @@ public class RestDslYamlGenerator extends
RestDslGenerator<RestDslYamlGenerator>
// add Routes
if (generateRoutes) {
for (Map.Entry<String, String> entry : toTagData.entrySet()) {
- ObjectNode from = JsonNodeFactory.instance.objectNode();
- from.set("uri", new StringNode(entry.getKey()));
+ ObjectNode route = JsonNodeFactory.instance.objectNode();
+ // the description is one of the route, not of its from (which
has none): such a route did not validate
String description = entry.getValue();
if (description != null && !description.isBlank()) {
- from.set("description", new StringNode(description));
+ route.set("description", new StringNode(description));
}
- ObjectNode route = JsonNodeFactory.instance.objectNode();
+ ObjectNode from = JsonNodeFactory.instance.objectNode();
+ from.set("uri", new StringNode(entry.getKey()));
+ // a step to replace with the implementation: a route without
steps fails to start
+ // ("Route ... has no output processors")
+ ArrayNode steps = JsonNodeFactory.instance.arrayNode();
+ steps.add(JsonNodeFactory.instance.objectNode()
+ .put("log", "Not implemented yet: " + entry.getKey()));
+ from.set("steps", steps);
route.set("from", from);
((ArrayNode)
node).add(xmlMapper.createObjectNode().set("route", route));
}
diff --git
a/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleWithRoutesDescriptionYaml.txt
b/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleWithRoutesDescriptionYaml.txt
index 7519acc7e003..98a43fe97ba1 100644
---
a/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleWithRoutesDescriptionYaml.txt
+++
b/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleWithRoutesDescriptionYaml.txt
@@ -9,6 +9,8 @@
type: "body"
to: "direct:rest1"
- route:
+ description: "Update Pet Data"
from:
uri: "direct:rest1"
- description: "Update Pet Data"
+ steps:
+ - log: "Not implemented yet: direct:rest1"
diff --git
a/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleWithRoutesYaml.txt
b/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleWithRoutesYaml.txt
index 79616b22ce7c..f6b3746aca28 100644
---
a/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleWithRoutesYaml.txt
+++
b/tooling/openapi-rest-dsl-generator/src/test/resources/OpenApiV3PetstoreSimpleWithRoutesYaml.txt
@@ -10,3 +10,5 @@
- route:
from:
uri: "direct:rest1"
+ steps:
+ - log: "Not implemented yet: direct:rest1"