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

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


The following commit(s) were added to refs/heads/main by this push:
     new 0c2a53478d Fix #6736 no need to add RegisterForReflection annotation 
on array type Class (#6737)
0c2a53478d is described below

commit 0c2a53478d063abbf43badd27c94e03df1925d0c
Author: Zheng Feng <zh.f...@gmail.com>
AuthorDate: Fri Nov 1 20:08:38 2024 +0800

    Fix #6736 no need to add RegisterForReflection annotation on array type 
Class (#6737)
---
 .../rest/openapi/deployment/QuarkusCodegen.java    | 16 +++++
 .../resources/handlebars/Quarkus/pojo.mustache     |  2 +
 .../rest-openapi/src/main/openapi/petstore.json    | 75 ++++++++++++++++++++++
 3 files changed, 93 insertions(+)

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 42618f4517..6680167d78 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
@@ -18,6 +18,7 @@
 package org.apache.camel.quarkus.component.rest.openapi.deployment;
 
 import java.io.File;
+import java.util.Map;
 
 import io.swagger.codegen.v3.CodegenModel;
 import io.swagger.codegen.v3.CodegenProperty;
@@ -26,6 +27,7 @@ import io.swagger.codegen.v3.SupportingFile;
 import io.swagger.codegen.v3.generators.features.BeanValidationFeatures;
 import io.swagger.codegen.v3.generators.features.NotNullAnnotationFeatures;
 import io.swagger.codegen.v3.generators.java.AbstractJavaCodegen;
+import io.swagger.v3.oas.models.media.Schema;
 import org.apache.commons.lang3.BooleanUtils;
 
 import static io.swagger.codegen.v3.CodegenConstants.IS_ENUM_EXT_NAME;
@@ -62,6 +64,18 @@ public class QuarkusCodegen extends AbstractJavaCodegen 
implements BeanValidatio
         return "Quarkus";
     }
 
+    @Override
+    public CodegenModel fromModel(String name, Schema schema, Map<String, 
Schema> allSchemas) {
+        CodegenModel model = super.fromModel(name, schema, allSchemas);
+        if (schema != null && "array".equals(schema.getType())) {
+            additionalProperties.put("useQuarkusRegisterForReflection", false);
+        }
+        if (additionalProperties.containsKey("ignoreUnknownProperties")) {
+            model.imports.add("JsonIgnoreProperties");
+        }
+        return model;
+    }
+
     @Override
     public void processOpts() {
         if ("quarkus3".equals(library)) {
@@ -81,6 +95,7 @@ public class QuarkusCodegen extends AbstractJavaCodegen 
implements BeanValidatio
         if (additionalProperties.containsKey("jackson")) {
             supportingFiles.add(new 
SupportingFile("RFC3339DateFormat.mustache", invokerFolder, 
"RFC3339DateFormat.java"));
         }
+
     }
 
     @Override
@@ -101,6 +116,7 @@ public class QuarkusCodegen extends AbstractJavaCodegen 
implements BeanValidatio
             }
         }
         model.imports.add("QuarkusRegisterForReflection");
+        additionalProperties.put("useQuarkusRegisterForReflection", true);
         if (additionalProperties.containsKey("ignoreUnknownProperties")) {
             model.imports.add("JsonIgnoreProperties");
         }
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 f03c1e3980..2944857ff6 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,7 +22,9 @@
 {{#notNullJacksonAnnotation}}
 @JsonInclude(JsonInclude.Include.NON_NULL)
 {{/notNullJacksonAnnotation}}
+{{#useQuarkusRegisterForReflection}}
 @RegisterForReflection{{#serializableModel}}(serialization = 
true){{/serializableModel}}
+{{/useQuarkusRegisterForReflection}}
 {{#ignoreUnknownProperties}}
 @JsonIgnoreProperties(ignoreUnknown = true)
 {{/ignoreUnknownProperties}}
diff --git a/integration-tests/rest-openapi/src/main/openapi/petstore.json 
b/integration-tests/rest-openapi/src/main/openapi/petstore.json
index b03f018744..9120395d95 100644
--- a/integration-tests/rest-openapi/src/main/openapi/petstore.json
+++ b/integration-tests/rest-openapi/src/main/openapi/petstore.json
@@ -303,6 +303,58 @@
                                ]
                        }
                },
+               "/pets": {
+                       "get": {
+                               "summary": "List all pets",
+                               "operationId": "listPets",
+                               "tags": [
+                                       "pets"
+                               ],
+                               "parameters": [
+                                       {
+                                               "name": "limit",
+                                               "in": "query",
+                                               "description": "How many items 
to return at one time (max 100)",
+                                               "required": false,
+                                               "schema": {
+                                                       "type": "integer",
+                                                       "maximum": 100,
+                                                       "format": "int32"
+                                               }
+                                       }
+                               ],
+                               "responses": {
+                                       "200": {
+                                               "description": "A paged array 
of pets",
+                                               "headers": {
+                                                       "x-next": {
+                                                               "description": 
"A link to the next page of responses",
+                                                               "schema": {
+                                                                       "type": 
"string"
+                                                               }
+                                                       }
+                                               },
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "$ref": 
"#/components/schemas/Pets"
+                                                               }
+                                                       }
+                                               }
+                                       },
+                                       "default": {
+                                               "description": "unexpected 
error",
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "$ref": 
"#/components/schemas/Error"
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+               },
                "/pet/{petId}": {
                        "get": {
                                "tags": [
@@ -1168,6 +1220,29 @@
                                        "name": "pet"
                                }
                        },
+                       "Pets": {
+                               "type": "array",
+                               "maxItems": 100,
+                               "items": {
+                                       "$ref": "#/components/schemas/Pet"
+                               }
+                       },
+                       "Error": {
+                               "type": "object",
+                               "required": [
+                                       "code",
+                                       "message"
+                               ],
+                               "properties": {
+                                       "code": {
+                                               "type": "integer",
+                                               "format": "int32"
+                                       },
+                                       "message": {
+                                               "type": "string"
+                                       }
+                               }
+                       },
                        "ApiResponse": {
                                "type": "object",
                                "properties": {

Reply via email to