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.f...@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}

Reply via email to