diff --git a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/wrapper/QuarkusJavaClientCodegen.java b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/wrapper/QuarkusJavaClientCodegen.java index cfe51cde..f81598d2 100644 --- a/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/wrapper/QuarkusJavaClientCodegen.java +++ b/client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/wrapper/QuarkusJavaClientCodegen.java @@ -2,6 +2,7 @@ import java.io.File; import java.net.URL; +import java.util.Collection; import java.util.List; import java.util.Locale; import java.util.Map; @@ -16,6 +17,8 @@ import org.openapitools.codegen.SupportingFile; import org.openapitools.codegen.config.GlobalSettings; import org.openapitools.codegen.languages.JavaClientCodegen; +import org.openapitools.codegen.model.ModelMap; +import org.openapitools.codegen.model.ModelsMap; import org.openapitools.codegen.utils.ProcessUtils; import org.openapitools.codegen.utils.URLPathUtils; import org.slf4j.Logger; @@ -43,6 +46,31 @@ public QuarkusJavaClientCodegen() { this.setTemplateDir("templates"); } + @Override + public ModelsMap postProcessModels(ModelsMap objs) { + objs = super.postProcessModels(objs); + + objs.getModels().stream() + .map(ModelMap::getModel) + .map(CodegenModel::getVars) + .flatMap(Collection::stream) + .filter(codegenProperty -> codegenProperty.getDatatypeWithEnum().contains("@Size") + || codegenProperty.getDataType().contains("@Size")) + .forEach(modelMap -> { + Optional.of(modelMap) + .map(CodegenProperty::getDatatypeWithEnum) + .map(datatype -> datatype.replace("@Size", "@jakarta.validation.constraints.Size")) + .ifPresent(modelMap::setDatatypeWithEnum); + + Optional.of(modelMap) + .map(CodegenProperty::getDataType) + .map(datatype -> datatype.replace("@Size", "@jakarta.validation.constraints.Size")) + .ifPresent(modelMap::setDataType); + }); + + return objs; + } + @Override public String getName() { return "quarkus"; diff --git a/client/integration-tests/bean-validation/src/main/openapi/bean-validation-true.yaml b/client/integration-tests/bean-validation/src/main/openapi/bean-validation-true.yaml index 68041e31..14cd99d3 100644 --- a/client/integration-tests/bean-validation/src/main/openapi/bean-validation-true.yaml +++ b/client/integration-tests/bean-validation/src/main/openapi/bean-validation-true.yaml @@ -49,6 +49,7 @@ components: - name - secondName - size + - listOfStrings properties: id: type: integer @@ -64,4 +65,9 @@ components: size: type: number minimum: 1.0 - maximum: 10.0 \ No newline at end of file + maximum: 10.0 + listOfStrings: + type: array + items: + type: string + minLength: 1 \ No newline at end of file diff --git a/client/integration-tests/bean-validation/src/test/java/io/quarkiverse/openapi/generator/it/BeanValidationTest.java b/client/integration-tests/bean-validation/src/test/java/io/quarkiverse/openapi/generator/it/BeanValidationTest.java index 154ee8f3..5280b66e 100644 --- a/client/integration-tests/bean-validation/src/test/java/io/quarkiverse/openapi/generator/it/BeanValidationTest.java +++ b/client/integration-tests/bean-validation/src/test/java/io/quarkiverse/openapi/generator/it/BeanValidationTest.java @@ -46,6 +46,7 @@ void testValidationAnnotationsAreInPlaceModel() throws Exception { Field name = ValidatedObject.class.getDeclaredField("name"); Field secondName = ValidatedObject.class.getDeclaredField("secondName"); Field size = ValidatedObject.class.getDeclaredField("size"); + Field listOfStrings = ValidatedObject.class.getDeclaredField("listOfStrings"); assertThat(Stream.of(id, name, secondName, size) .allMatch(f -> f.isAnnotationPresent(NotNull.class))) @@ -69,6 +70,9 @@ void testValidationAnnotationsAreInPlaceModel() throws Exception { assertThat(size.getAnnotation(DecimalMin.class).value()).isEqualTo("1.0"); assertThat(size.isAnnotationPresent(DecimalMax.class)).isTrue(); assertThat(size.getAnnotation(DecimalMax.class).value()).isEqualTo("10.0"); + + assertThat(listOfStrings.isAnnotationPresent(NotNull.class)).isTrue(); + assertThat(listOfStrings.isAnnotationPresent(Valid.class)).isTrue(); } @Test