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 53e024f16538 CAMEL-26933: camel-jbang - the DTOs of camel generate
rest compile in a Camel 4 project, and the REST DSL is the only output (#30031)
53e024f16538 is described below
commit 53e024f165382d241f0ce23c479adc2c6943da29
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 15 17:02:03 2026 +0100
CAMEL-26933: camel-jbang - the DTOs of camel generate rest compile in a
Camel 4 project, and the REST DSL is the only output (#30031)
- The DTOs used javax.validation and javax.annotation (useJakartaEe=false),
JsonNullable of jackson-databind-nullable,
and with spring-boot the Swagger annotations: they did not compile in a
Camel 4 project. They now use Jakarta EE,
no JsonNullable and no Swagger annotations; with --runtime=main they are
generated as for Quarkus, without Spring.
Checked with javac: the DTOs of the petstore specification compile with
Jackson annotations and Jakarta Validation
and Annotation only (and Spring for spring-boot).
- The banner of the OpenAPI Generator was printed on stdout after the REST
DSL, so > rest.xml was not XML: the
generator runs quiet.
- --input takes an http:// or https:// URL, which the parser reads; it was
refused as a file that does not exist.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../ROOT/pages/camel-4x-upgrade-guide-4_24.adoc | 8 +++++
.../core/commands/generate/CodeRestGenerator.java | 38 +++++++++++++++-------
.../commands/generate/CodeRestGeneratorTest.java | 38 ++++++++++++++++++++++
3 files changed, 72 insertions(+), 12 deletions(-)
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
index ce445e3773fa..5139905f9578 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_24.adoc
@@ -3409,6 +3409,14 @@ file), the command asks there whether to overwrite the
file.
* A quoted trait value, and the value of `cronjob.schedule`, is one value also
with a comma in it
(`cronjob.schedule=0 1,13 * * *`): it was split into a list, which failed
with exit code `70`.
+=== camel-jbang - camel generate rest --dto
+
+The DTOs of `camel generate rest --dto` use Jakarta EE (`jakarta.validation`,
`jakarta.annotation`) instead of
+`javax`, and no longer use `JsonNullable` of `jackson-databind-nullable` or
the Swagger annotations
+(`io.swagger.v3.oas.annotations`), so they compile in a Camel 4 project. With
`--runtime=main` they no longer use
+Spring (`@DateTimeFormat`). The OpenAPI Generator no longer prints its banner
on stdout after the REST DSL, and
+`--input` takes an `http://` or `https://` URL.
+
=== camel-jbang - camel version list
* `camel version list` prints the `Last updated` note on stderr, so stdout has
the table only.
diff --git
a/dsl/camel-jbang/camel-jbang-plugin-generate/src/main/java/org/apache/camel/dsl/jbang/core/commands/generate/CodeRestGenerator.java
b/dsl/camel-jbang/camel-jbang-plugin-generate/src/main/java/org/apache/camel/dsl/jbang/core/commands/generate/CodeRestGenerator.java
index 13bd52a79bd4..805aafeca2bd 100644
---
a/dsl/camel-jbang/camel-jbang-plugin-generate/src/main/java/org/apache/camel/dsl/jbang/core/commands/generate/CodeRestGenerator.java
+++
b/dsl/camel-jbang/camel-jbang-plugin-generate/src/main/java/org/apache/camel/dsl/jbang/core/commands/generate/CodeRestGenerator.java
@@ -105,9 +105,9 @@ public class CodeRestGenerator extends CamelCommand {
@Override
public Integer doCall() throws Exception {
- // validate that the input file exists
+ // validate that the input file exists; a URL is read by the parser
(it was refused as a file that does not exist)
File f = new File(input);
- if (!f.exists() && !f.isFile()) {
+ if (!isUrl(input) && !f.isFile()) {
printer().printErr("Input file " + input + " does not exist");
return CliExitCode.FILE_NOT_FOUND;
}
@@ -157,6 +157,10 @@ public class CodeRestGenerator extends CamelCommand {
return 0;
}
+ private static boolean isUrl(String input) {
+ return input.startsWith("http://") || input.startsWith("https://");
+ }
+
/**
* The directory of the package of the DTOs, in the working directory.
*/
@@ -174,8 +178,11 @@ public class CodeRestGenerator extends CamelCommand {
// the generator writes into a temporary directory, from which the DTOs
are copied into the directory of their package
private void generateDto(Path packageDir) throws IOException {
final String code = "code";
- final String generatorName = RuntimeType.quarkus.equals(runtime) ?
"jaxrs-spec" : "java-camel";
- final String library = RuntimeType.quarkus.equals(runtime) ? "quarkus"
: "spring-boot";
+ // the DTOs of Spring Boot may use Spring (such as @DateTimeFormat);
the others only Jackson and Jakarta, as a
+ // Camel Main project has no Spring (CAMEL-26933)
+ final boolean springBoot = RuntimeType.springBoot.equals(runtime);
+ final String generatorName = springBoot ? "java-camel" : "jaxrs-spec";
+ final String library = springBoot ? "spring-boot" : "quarkus";
File output = createTempDirectory().toFile();
try {
generateDto(code, generatorName, library, output);
@@ -196,15 +203,22 @@ public class CodeRestGenerator extends CamelCommand {
.setLibrary(library)
.setInputSpec(input)
.setModelPackage(packageName)
+ // the DTOs compile with what a Camel 4 project has: Jakarta
EE (not javax), no JsonNullable of
+ // jackson-databind-nullable, and no Swagger annotations
(CAMEL-26933)
.setAdditionalProperties(
- Map.of(
- SERIALIZABLE_MODEL, "false",
- "useJakartaEe", "false",
- "useSwaggerAnnotations", "false",
- GENERATE_MODELS, "true",
- "generatePom", "false",
- "generateApis", "false",
- "sourceFolder", code))
+ Map.ofEntries(
+ Map.entry(SERIALIZABLE_MODEL, "false"),
+ Map.entry("useJakartaEe", "true"),
+ Map.entry("useSwaggerAnnotations", "false"),
+ Map.entry("documentationProvider", "none"),
+ Map.entry("annotationLibrary", "none"),
+ Map.entry("openApiNullable", "false"),
+ Map.entry(GENERATE_MODELS, "true"),
+ Map.entry("generatePom", "false"),
+ Map.entry("generateApis", "false"),
+ Map.entry("sourceFolder", code)))
+ // no banner of the generator on stdout, where the REST DSL is
printed
+ .addGlobalProperty("quiet", "true")
.setOutputDir(output.getAbsolutePath());
final ClientOptInput clientOptInput = configurator.toClientOptInput();
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 66da5a1cba58..104f88b6531c 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
@@ -16,7 +16,10 @@
*/
package org.apache.camel.dsl.jbang.core.commands.generate;
+import java.io.ByteArrayOutputStream;
import java.io.IOException;
+import java.io.PrintStream;
+import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -29,6 +32,8 @@ 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;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
import static org.assertj.core.api.Assertions.assertThat;
@@ -127,6 +132,39 @@ class CodeRestGeneratorTest {
assertThat(Files.readString(rest)).contains("- route:", "steps:",
"log: \"Not implemented yet: direct:");
}
+ @ParameterizedTest
+ @ValueSource(strings = { "quarkus", "main", "spring-boot" })
+ void theDtosUseJakartaAndNoLibraryTheProjectDoesNotHave(String runtime)
throws Exception {
+ // CAMEL-26933: the DTOs imported javax.validation and JsonNullable
(quarkus), or the Swagger annotations
+ // (spring-boot), and did not compile in a Camel 4 project
+ Path packageDir = dir.resolve("model");
+
+ int exitCode = generate(packageDir, "--package=model", "--runtime=" +
runtime);
+
+ assertThat(exitCode).as(printer.getOutput()).isZero();
+ String pet = Files.readString(packageDir.resolve("Pet.java"));
+ assertThat(pet).contains("import
jakarta.validation").doesNotContain("javax.", "JsonNullable", "io.swagger");
+ if (!"spring-boot".equals(runtime)) {
+ // a Camel Main or Quarkus project has no Spring
+
assertThat(Files.readString(packageDir.resolve("Order.java"))).doesNotContain("org.springframework");
+ }
+ }
+
+ @Test
+ void theRestDslIsTheOnlyOutput() throws Exception {
+ // CAMEL-26933: the banner of the OpenAPI Generator was printed on
stdout after the REST DSL
+ PrintStream previous = System.out;
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ System.setOut(new PrintStream(out, true, StandardCharsets.UTF_8));
+ try {
+ assertThat(generate(dir.resolve("model"),
"--package=model")).isZero();
+ } finally {
+ System.setOut(previous);
+ }
+
+
assertThat(out.toString(StandardCharsets.UTF_8)).doesNotContain("OpenAPI
Generator");
+ }
+
private int generate(Path packageDir, String... args) throws Exception {
return generate(SPEC, packageDir, args);
}