Skip to content

Commit

Permalink
Fix apache#6736 no need to add RegisterForReflection annotation on ar…
Browse files Browse the repository at this point in the history
…ray type Class
  • Loading branch information
zhfeng committed Nov 1, 2024
1 parent 33b7197 commit 8afddb8
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,7 @@
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;
Expand Down Expand Up @@ -62,6 +64,18 @@ public String getDefaultTemplateDir() {
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)) {
Expand All @@ -81,6 +95,7 @@ public void processOpts() {
if (additionalProperties.containsKey("jackson")) {
supportingFiles.add(new SupportingFile("RFC3339DateFormat.mustache", invokerFolder, "RFC3339DateFormat.java"));
}

}

@Override
Expand All @@ -101,6 +116,7 @@ public void postProcessModelProperty(CodegenModel model, CodegenProperty propert
}
}
model.imports.add("QuarkusRegisterForReflection");
additionalProperties.put("useQuarkusRegisterForReflection", true);
if (additionalProperties.containsKey("ignoreUnknownProperties")) {
model.imports.add("JsonIgnoreProperties");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
{{#notNullJacksonAnnotation}}
@JsonInclude(JsonInclude.Include.NON_NULL)
{{/notNullJacksonAnnotation}}
{{#useQuarkusRegisterForReflection}}
@RegisterForReflection{{#serializableModel}}(serialization = true){{/serializableModel}}
{{/useQuarkusRegisterForReflection}}
{{#ignoreUnknownProperties}}
@JsonIgnoreProperties(ignoreUnknown = true)
{{/ignoreUnknownProperties}}
Expand Down
75 changes: 75 additions & 0 deletions integration-tests/rest-openapi/src/main/openapi/petstore.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -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": {
Expand Down

0 comments on commit 8afddb8

Please sign in to comment.