Skip to content

Commit 1c1a3b8

Browse files
committed
Added the FQCN to the @Size-annotation.
1 parent ef8b310 commit 1c1a3b8

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

client/deployment/src/main/java/io/quarkiverse/openapi/generator/deployment/wrapper/QuarkusJavaClientCodegen.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.File;
44
import java.net.URL;
5+
import java.util.Collection;
56
import java.util.List;
67
import java.util.Locale;
78
import java.util.Map;
@@ -16,6 +17,8 @@
1617
import org.openapitools.codegen.SupportingFile;
1718
import org.openapitools.codegen.config.GlobalSettings;
1819
import org.openapitools.codegen.languages.JavaClientCodegen;
20+
import org.openapitools.codegen.model.ModelMap;
21+
import org.openapitools.codegen.model.ModelsMap;
1922
import org.openapitools.codegen.utils.ProcessUtils;
2023
import org.openapitools.codegen.utils.URLPathUtils;
2124
import org.slf4j.Logger;
@@ -43,6 +46,31 @@ public QuarkusJavaClientCodegen() {
4346
this.setTemplateDir("templates");
4447
}
4548

49+
@Override
50+
public ModelsMap postProcessModels(ModelsMap objs) {
51+
objs = super.postProcessModels(objs);
52+
53+
objs.getModels().stream()
54+
.map(ModelMap::getModel)
55+
.map(CodegenModel::getVars)
56+
.flatMap(Collection::stream)
57+
.filter(codegenProperty -> codegenProperty.getDatatypeWithEnum().contains("@Size")
58+
|| codegenProperty.getDataType().contains("@Size"))
59+
.forEach(modelMap -> {
60+
Optional.of(modelMap)
61+
.map(CodegenProperty::getDatatypeWithEnum)
62+
.map(datatype -> datatype.replace("@Size", "@jakarta.validation.constraints.Size"))
63+
.ifPresent(modelMap::setDatatypeWithEnum);
64+
65+
Optional.of(modelMap)
66+
.map(CodegenProperty::getDataType)
67+
.map(datatype -> datatype.replace("@Size", "@jakarta.validation.constraints.Size"))
68+
.ifPresent(modelMap::setDataType);
69+
});
70+
71+
return objs;
72+
}
73+
4674
@Override
4775
public String getName() {
4876
return "quarkus";

client/integration-tests/bean-validation/src/main/openapi/bean-validation-true.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ components:
4949
- name
5050
- secondName
5151
- size
52+
- listOfStrings
5253
properties:
5354
id:
5455
type: integer
@@ -64,4 +65,9 @@ components:
6465
size:
6566
type: number
6667
minimum: 1.0
67-
maximum: 10.0
68+
maximum: 10.0
69+
listOfStrings:
70+
type: array
71+
items:
72+
type: string
73+
minLength: 1

client/integration-tests/bean-validation/src/test/java/io/quarkiverse/openapi/generator/it/BeanValidationTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ void testValidationAnnotationsAreInPlaceModel() throws Exception {
4646
Field name = ValidatedObject.class.getDeclaredField("name");
4747
Field secondName = ValidatedObject.class.getDeclaredField("secondName");
4848
Field size = ValidatedObject.class.getDeclaredField("size");
49+
Field listOfStrings = ValidatedObject.class.getDeclaredField("listOfStrings");
4950

5051
assertThat(Stream.of(id, name, secondName, size)
5152
.allMatch(f -> f.isAnnotationPresent(NotNull.class)))
@@ -69,6 +70,9 @@ void testValidationAnnotationsAreInPlaceModel() throws Exception {
6970
assertThat(size.getAnnotation(DecimalMin.class).value()).isEqualTo("1.0");
7071
assertThat(size.isAnnotationPresent(DecimalMax.class)).isTrue();
7172
assertThat(size.getAnnotation(DecimalMax.class).value()).isEqualTo("10.0");
73+
74+
assertThat(listOfStrings.isAnnotationPresent(NotNull.class)).isTrue();
75+
assertThat(listOfStrings.isAnnotationPresent(Valid.class)).isTrue();
7276
}
7377

7478
@Test

0 commit comments

Comments
 (0)