You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by zh...@apache.org on 2024/10/31 06:37:30 UTC

(camel-quarkus) branch 3.15.x updated (e85219a41f -> 40844906cf)

This is an automated email from the ASF dual-hosted git repository.

zhfeng pushed a change to branch 3.15.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


    from e85219a41f Update generated files after release
     new b4330881df Fix #6716 to introduce ignore-unknown-properties property (#6719)
     new 40844906cf Introduce additionProperties in rest-openapi codegen and fix some known issues with mustache template files (#6726)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../pages/reference/extensions/rest-openapi.adoc   | 12 +++++++++++
 .../CamelQuarkusSwaggerCodegenProvider.java        | 24 ++++++++++++++++++++--
 .../rest/openapi/deployment/QuarkusCodegen.java    |  4 ++++
 .../Quarkus/generatedAnnotation.mustache           |  1 -
 .../handlebars/Quarkus/modelEnum.mustache          |  2 +-
 .../handlebars/Quarkus/modelInnerEnum.mustache     |  4 ++--
 .../resources/handlebars/Quarkus/pojo.mustache     |  4 ++++
 .../runtime/RestOpenApiBuildTimeConfig.java        | 17 +++++++++++++++
 .../src/main/resources/application.properties      |  2 ++
 9 files changed, 64 insertions(+), 6 deletions(-)


(camel-quarkus) 01/02: Fix #6716 to introduce ignore-unknown-properties property (#6719)

Posted by zh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

zhfeng pushed a commit to branch 3.15.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit b4330881dfc9d649d78e1f9073473db9f8e91868
Author: Zheng Feng <zh...@gmail.com>
AuthorDate: Wed Oct 30 19:34:14 2024 +0800

    Fix #6716 to introduce ignore-unknown-properties property (#6719)
---
 docs/modules/ROOT/pages/reference/extensions/rest-openapi.adoc    | 6 ++++++
 .../openapi/deployment/CamelQuarkusSwaggerCodegenProvider.java    | 5 +++++
 .../quarkus/component/rest/openapi/deployment/QuarkusCodegen.java | 4 ++++
 .../resources/handlebars/Quarkus/generatedAnnotation.mustache     | 1 +
 .../quarkus/rest/openapi/runtime/RestOpenApiBuildTimeConfig.java  | 8 ++++++++
 .../rest-openapi/src/main/resources/application.properties        | 1 +
 6 files changed, 25 insertions(+)

diff --git a/docs/modules/ROOT/pages/reference/extensions/rest-openapi.adoc b/docs/modules/ROOT/pages/reference/extensions/rest-openapi.adoc
index 957f609ad8..05e8a63cf3 100644
--- a/docs/modules/ROOT/pages/reference/extensions/rest-openapi.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/rest-openapi.adoc
@@ -165,6 +165,12 @@ If `true`, use bean validation annotations in the generated model classes.
 If `true`, use NON_NULL Jackson annotation in the generated model classes.
 | `boolean`
 | `false`
+
+|icon:lock[title=Fixed at build time] [[quarkus.camel.openapi.codegen.ignore-unknown-properties]]`link:#quarkus.camel.openapi.codegen.ignore-unknown-properties[quarkus.camel.openapi.codegen.ignore-unknown-properties]`
+
+If `true`, use JsonIgnoreProperties(ignoreUnknown = true) annotation in the generated model classes.
+| `boolean`
+| `false`
 |===
 
 [.configuration-legend]
diff --git a/extensions/rest-openapi/deployment/src/main/java/org/apache/camel/quarkus/component/rest/openapi/deployment/CamelQuarkusSwaggerCodegenProvider.java b/extensions/rest-openapi/deployment/src/main/java/org/apache/camel/quarkus/component/rest/openapi/deployment/CamelQuarkusSwaggerCodegenProvider.java
index 48df92c740..23f86e0e4c 100644
--- a/extensions/rest-openapi/deployment/src/main/java/org/apache/camel/quarkus/component/rest/openapi/deployment/CamelQuarkusSwaggerCodegenProvider.java
+++ b/extensions/rest-openapi/deployment/src/main/java/org/apache/camel/quarkus/component/rest/openapi/deployment/CamelQuarkusSwaggerCodegenProvider.java
@@ -82,6 +82,8 @@ public class CamelQuarkusSwaggerCodegenProvider implements CodeGenProvider {
             String models = config.getOptionalValue("quarkus.camel.openapi.codegen.models", String.class).orElse("");
             boolean useBeanValidation = config.getValue("quarkus.camel.openapi.codegen.use-bean-validation", Boolean.class);
             boolean notNullJackson = config.getValue("quarkus.camel.openapi.codegen.not-null-jackson", Boolean.class);
+            boolean ignoreUnknownProperties = config.getValue("quarkus.camel.openapi.codegen.ignore-unknown-properties",
+                    Boolean.class);
             for (String specFile : specFiles) {
                 CodegenConfigurator configurator = new CodegenConfigurator();
                 configurator.setLang("quarkus");
@@ -100,6 +102,9 @@ public class CamelQuarkusSwaggerCodegenProvider implements CodeGenProvider {
                 if (notNullJackson) {
                     configurator.getAdditionalProperties().put(NOT_NULL_JACKSON_ANNOTATION, "true");
                 }
+                if (ignoreUnknownProperties) {
+                    configurator.getAdditionalProperties().put("ignoreUnknownProperties", "true");
+                }
 
                 final ClientOptInput input = configurator.toClientOptInput();
                 new DefaultGenerator().opts(input).generate();
diff --git a/extensions/rest-openapi/deployment/src/main/java/org/apache/camel/quarkus/component/rest/openapi/deployment/QuarkusCodegen.java b/extensions/rest-openapi/deployment/src/main/java/org/apache/camel/quarkus/component/rest/openapi/deployment/QuarkusCodegen.java
index 0d7fae0fac..42618f4517 100644
--- a/extensions/rest-openapi/deployment/src/main/java/org/apache/camel/quarkus/component/rest/openapi/deployment/QuarkusCodegen.java
+++ b/extensions/rest-openapi/deployment/src/main/java/org/apache/camel/quarkus/component/rest/openapi/deployment/QuarkusCodegen.java
@@ -38,6 +38,7 @@ public class QuarkusCodegen extends AbstractJavaCodegen implements BeanValidatio
     public QuarkusCodegen() {
         super();
         importMapping.put("QuarkusRegisterForReflection", "io.quarkus.runtime.annotations.RegisterForReflection");
+        importMapping.put("JsonIgnoreProperties", "com.fasterxml.jackson.annotation.JsonIgnoreProperties");
         supportedLibraries.put("quarkus3", "Quarkus 3 framework");
     }
 
@@ -100,6 +101,9 @@ public class QuarkusCodegen extends AbstractJavaCodegen implements BeanValidatio
             }
         }
         model.imports.add("QuarkusRegisterForReflection");
+        if (additionalProperties.containsKey("ignoreUnknownProperties")) {
+            model.imports.add("JsonIgnoreProperties");
+        }
     }
 
     @Override
diff --git a/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/generatedAnnotation.mustache b/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/generatedAnnotation.mustache
index bd62dcc664..6aa9a052e9 100644
--- a/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/generatedAnnotation.mustache
+++ b/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/generatedAnnotation.mustache
@@ -16,3 +16,4 @@
 }}
 {{^hideGenerationTimestamp}}@{{#jakarta}}jakarta{{/jakarta}}{{^jakarta}}javax{{/jakarta}}.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}"){{/hideGenerationTimestamp}}
 @RegisterForReflection{{#serializableModel}}(serialization = true){{/serializableModel}}
+{{#ignoreUnknownProperties}}@JsonIgnoreProperties(ignoreUnknown = true){{/ignoreUnknownProperties}}
diff --git a/extensions/rest-openapi/runtime/src/main/java/org/apache/camel/quarkus/rest/openapi/runtime/RestOpenApiBuildTimeConfig.java b/extensions/rest-openapi/runtime/src/main/java/org/apache/camel/quarkus/rest/openapi/runtime/RestOpenApiBuildTimeConfig.java
index 0e0dbfb340..1d087cf701 100644
--- a/extensions/rest-openapi/runtime/src/main/java/org/apache/camel/quarkus/rest/openapi/runtime/RestOpenApiBuildTimeConfig.java
+++ b/extensions/rest-openapi/runtime/src/main/java/org/apache/camel/quarkus/rest/openapi/runtime/RestOpenApiBuildTimeConfig.java
@@ -63,6 +63,14 @@ public class RestOpenApiBuildTimeConfig {
          */
         @ConfigItem(defaultValue = "false")
         public boolean notNullJackson;
+
+        /**
+         * If `true`, use JsonIgnoreProperties(ignoreUnknown = true) annotation in the generated model classes.
+         *
+         * @asciidoclet
+         */
+        @ConfigItem(defaultValue = "false")
+        public boolean ignoreUnknownProperties;
     }
 
 }
diff --git a/integration-tests/rest-openapi/src/main/resources/application.properties b/integration-tests/rest-openapi/src/main/resources/application.properties
index 59425bb75b..a16f53a6ab 100644
--- a/integration-tests/rest-openapi/src/main/resources/application.properties
+++ b/integration-tests/rest-openapi/src/main/resources/application.properties
@@ -17,5 +17,6 @@
 quarkus.native.resources.includes=openapi.json,petstore.json,example.yaml
 quarkus.camel.openapi.codegen.model-package=org.apache.camel.quarkus.component.rest.openapi.it.model
 quarkus.camel.openapi.codegen.not-null-jackson=true
+quarkus.camel.openapi.codegen.ignore-unknown-properties=true
 camel.rest.bindingMode=json
 camel.rest.bindingPackageScan=${quarkus.camel.openapi.codegen.model-package}


(camel-quarkus) 02/02: Introduce additionProperties in rest-openapi codegen and fix some known issues with mustache template files (#6726)

Posted by zh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

zhfeng pushed a commit to branch 3.15.x
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git

commit 40844906cffa8facc0662c44b76713e6f3bc1a90
Author: Zheng Feng <zh...@gmail.com>
AuthorDate: Thu Oct 31 06:50:32 2024 +0800

    Introduce additionProperties in rest-openapi codegen and fix some known issues with mustache template files (#6726)
---
 .../pages/reference/extensions/rest-openapi.adoc    |  6 ++++++
 .../CamelQuarkusSwaggerCodegenProvider.java         | 21 ++++++++++++++++++---
 .../handlebars/Quarkus/generatedAnnotation.mustache |  2 --
 .../resources/handlebars/Quarkus/modelEnum.mustache |  2 +-
 .../handlebars/Quarkus/modelInnerEnum.mustache      |  4 ++--
 .../main/resources/handlebars/Quarkus/pojo.mustache |  4 ++++
 .../openapi/runtime/RestOpenApiBuildTimeConfig.java |  9 +++++++++
 .../src/main/resources/application.properties       |  1 +
 8 files changed, 41 insertions(+), 8 deletions(-)

diff --git a/docs/modules/ROOT/pages/reference/extensions/rest-openapi.adoc b/docs/modules/ROOT/pages/reference/extensions/rest-openapi.adoc
index 05e8a63cf3..fee26616da 100644
--- a/docs/modules/ROOT/pages/reference/extensions/rest-openapi.adoc
+++ b/docs/modules/ROOT/pages/reference/extensions/rest-openapi.adoc
@@ -171,6 +171,12 @@ If `true`, use NON_NULL Jackson annotation in the generated model classes.
 If `true`, use JsonIgnoreProperties(ignoreUnknown = true) annotation in the generated model classes.
 | `boolean`
 | `false`
+
+|icon:lock[title=Fixed at build time] [[quarkus.camel.openapi.codegen.additional-properties.-additional-properties]]`link:#quarkus.camel.openapi.codegen.additional-properties.-additional-properties[quarkus.camel.openapi.codegen.additional-properties."additional-properties"]`
+
+Additional properties to be used in the mustache templates.
+| `Map<String,String>`
+| 
 |===
 
 [.configuration-legend]
diff --git a/extensions/rest-openapi/deployment/src/main/java/org/apache/camel/quarkus/component/rest/openapi/deployment/CamelQuarkusSwaggerCodegenProvider.java b/extensions/rest-openapi/deployment/src/main/java/org/apache/camel/quarkus/component/rest/openapi/deployment/CamelQuarkusSwaggerCodegenProvider.java
index 23f86e0e4c..546af5455f 100644
--- a/extensions/rest-openapi/deployment/src/main/java/org/apache/camel/quarkus/component/rest/openapi/deployment/CamelQuarkusSwaggerCodegenProvider.java
+++ b/extensions/rest-openapi/deployment/src/main/java/org/apache/camel/quarkus/component/rest/openapi/deployment/CamelQuarkusSwaggerCodegenProvider.java
@@ -84,6 +84,7 @@ public class CamelQuarkusSwaggerCodegenProvider implements CodeGenProvider {
             boolean notNullJackson = config.getValue("quarkus.camel.openapi.codegen.not-null-jackson", Boolean.class);
             boolean ignoreUnknownProperties = config.getValue("quarkus.camel.openapi.codegen.ignore-unknown-properties",
                     Boolean.class);
+
             for (String specFile : specFiles) {
                 CodegenConfigurator configurator = new CodegenConfigurator();
                 configurator.setLang("quarkus");
@@ -97,14 +98,28 @@ public class CamelQuarkusSwaggerCodegenProvider implements CodeGenProvider {
                 configurator.getCodegenArguments()
                         .add(new CodegenArgument().option(CodegenConstants.MODEL_DOCS_OPTION).type("boolean").value("false"));
                 if (useBeanValidation) {
-                    configurator.getAdditionalProperties().put(USE_BEANVALIDATION, "true");
+                    configurator.getAdditionalProperties().put(USE_BEANVALIDATION, true);
                 }
                 if (notNullJackson) {
-                    configurator.getAdditionalProperties().put(NOT_NULL_JACKSON_ANNOTATION, "true");
+                    configurator.getAdditionalProperties().put(NOT_NULL_JACKSON_ANNOTATION, true);
                 }
                 if (ignoreUnknownProperties) {
-                    configurator.getAdditionalProperties().put("ignoreUnknownProperties", "true");
+                    configurator.getAdditionalProperties().put("ignoreUnknownProperties", true);
                 }
+                config.getPropertyNames().forEach(name -> {
+                    if (name.startsWith("quarkus.camel.openapi.codegen.additional-properties")) {
+                        String key = name.substring("quarkus.camel.openapi.codegen.additional-properties.".length());
+                        String value = config.getValue(name, String.class);
+                        if (configurator.getAdditionalProperties().containsKey(key)) {
+                            LOG.warn("Overriding existing property: " + key + " with value: " + value);
+                        }
+                        if (value.equals("true") || value.equals("false")) {
+                            configurator.getAdditionalProperties().put(key, Boolean.parseBoolean(value));
+                        } else {
+                            configurator.getAdditionalProperties().put(key, value);
+                        }
+                    }
+                });
 
                 final ClientOptInput input = configurator.toClientOptInput();
                 new DefaultGenerator().opts(input).generate();
diff --git a/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/generatedAnnotation.mustache b/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/generatedAnnotation.mustache
index 6aa9a052e9..071df2fc88 100644
--- a/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/generatedAnnotation.mustache
+++ b/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/generatedAnnotation.mustache
@@ -15,5 +15,3 @@
     limitations under the License.
 }}
 {{^hideGenerationTimestamp}}@{{#jakarta}}jakarta{{/jakarta}}{{^jakarta}}javax{{/jakarta}}.annotation.Generated(value = "{{generatorClass}}", date = "{{generatedDate}}"){{/hideGenerationTimestamp}}
-@RegisterForReflection{{#serializableModel}}(serialization = true){{/serializableModel}}
-{{#ignoreUnknownProperties}}@JsonIgnoreProperties(ignoreUnknown = true){{/ignoreUnknownProperties}}
diff --git a/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/modelEnum.mustache b/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/modelEnum.mustache
index a86cf7ff4c..9f975db070 100644
--- a/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/modelEnum.mustache
+++ b/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/modelEnum.mustache
@@ -71,7 +71,7 @@ public enum {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum
         return b;
       }
     }
-    {{^errorOnUnknownEnum}}return null;{{/errorOnUnknownEnum}}{{#errorOnUnknownEnum}}throw new IllegalArgumentException("Unexpected value '" + text + "' for '{{{classname}}}' enum.");{{/errorOnUnknownEnum}}
+    {{^errorOnUnknownEnum}}return null;{{/errorOnUnknownEnum}}{{#errorOnUnknownEnum}}throw new IllegalArgumentException("Unexpected value '" + input + "' for '{{{classname}}}' enum.");{{/errorOnUnknownEnum}}
   }
 {{#gson}}
 
diff --git a/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/modelInnerEnum.mustache b/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/modelInnerEnum.mustache
index 9b13af047a..4690242474 100644
--- a/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/modelInnerEnum.mustache
+++ b/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/modelInnerEnum.mustache
@@ -55,7 +55,7 @@
           return b;
         }
       }
-      {{^errorOnUnknownEnum}}return null;{{/errorOnUnknownEnum}}{{#errorOnUnknownEnum}}throw new IllegalArgumentException("Unexpected value '" + text + "' for '{{{classname}}}' enum.");{{/errorOnUnknownEnum}}
+      {{^errorOnUnknownEnum}}return null;{{/errorOnUnknownEnum}}{{#errorOnUnknownEnum}}throw new IllegalArgumentException("Unexpected value '" + input + "' for '{{{classname}}}' enum.");{{/errorOnUnknownEnum}}
     }
     {{#gson}}
     public static class Adapter extends TypeAdapter<{{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}> {
@@ -70,4 +70,4 @@
         return {{#datatypeWithEnum}}{{{.}}}{{/datatypeWithEnum}}{{^datatypeWithEnum}}{{classname}}{{/datatypeWithEnum}}.fromValue(({{{datatype}}})(value));
       }
     }{{/gson}}
-  }
\ No newline at end of file
+  }
diff --git a/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/pojo.mustache b/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/pojo.mustache
index fc8b7d72f2..f03c1e3980 100644
--- a/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/pojo.mustache
+++ b/extensions/rest-openapi/deployment/src/main/resources/handlebars/Quarkus/pojo.mustache
@@ -22,6 +22,10 @@
 {{#notNullJacksonAnnotation}}
 @JsonInclude(JsonInclude.Include.NON_NULL)
 {{/notNullJacksonAnnotation}}
+@RegisterForReflection{{#serializableModel}}(serialization = true){{/serializableModel}}
+{{#ignoreUnknownProperties}}
+@JsonIgnoreProperties(ignoreUnknown = true)
+{{/ignoreUnknownProperties}}
 
 public class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}{{#parcelableModel}}implements Parcelable {{#serializableModel}}, Serializable {{/serializableModel}}{{#interfaceModels}}{{#@first}}, {{/@first}}{{classname}}{{^@last}}, {{/@last}}{{#@last}} {{/@last}}{{/interfaceModels}}{{/parcelableModel}}{{^parcelableModel}}{{#serializableModel}}implements Serializable{{#interfaceModels}}{{#@first}}, {{/@first}}{{classname}}{{^@last}}, {{/@last}}{{#@last}} {{/@last}}{{/interfaceMode [...]
 {{#serializableModel}}
diff --git a/extensions/rest-openapi/runtime/src/main/java/org/apache/camel/quarkus/rest/openapi/runtime/RestOpenApiBuildTimeConfig.java b/extensions/rest-openapi/runtime/src/main/java/org/apache/camel/quarkus/rest/openapi/runtime/RestOpenApiBuildTimeConfig.java
index 1d087cf701..fcebc9e0a5 100644
--- a/extensions/rest-openapi/runtime/src/main/java/org/apache/camel/quarkus/rest/openapi/runtime/RestOpenApiBuildTimeConfig.java
+++ b/extensions/rest-openapi/runtime/src/main/java/org/apache/camel/quarkus/rest/openapi/runtime/RestOpenApiBuildTimeConfig.java
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.quarkus.rest.openapi.runtime;
 
+import java.util.Map;
 import java.util.Optional;
 
 import io.quarkus.runtime.annotations.ConfigGroup;
@@ -71,6 +72,14 @@ public class RestOpenApiBuildTimeConfig {
          */
         @ConfigItem(defaultValue = "false")
         public boolean ignoreUnknownProperties;
+
+        /**
+         * Additional properties to be used in the mustache templates.
+         *
+         * @asciidoclet
+         */
+        @ConfigItem
+        public Map<String, String> additionalProperties;
     }
 
 }
diff --git a/integration-tests/rest-openapi/src/main/resources/application.properties b/integration-tests/rest-openapi/src/main/resources/application.properties
index a16f53a6ab..01f7a2133a 100644
--- a/integration-tests/rest-openapi/src/main/resources/application.properties
+++ b/integration-tests/rest-openapi/src/main/resources/application.properties
@@ -18,5 +18,6 @@ quarkus.native.resources.includes=openapi.json,petstore.json,example.yaml
 quarkus.camel.openapi.codegen.model-package=org.apache.camel.quarkus.component.rest.openapi.it.model
 quarkus.camel.openapi.codegen.not-null-jackson=true
 quarkus.camel.openapi.codegen.ignore-unknown-properties=true
+quarkus.camel.openapi.codegen.additional-properties.errorOnUnknownEnum=true
 camel.rest.bindingMode=json
 camel.rest.bindingPackageScan=${quarkus.camel.openapi.codegen.model-package}