Skip to content

Commit 1656119

Browse files
committed
[Java] fix beanvalidation compilation failed when items type in array is int64
1 parent 81f576c commit 1656119

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,10 @@ private String getBeanValidation(Schema<?> items) {
999999
return getNumberBeanValidation(items);
10001000
}
10011001

1002+
if (ModelUtils.isLongSchema(items)) {
1003+
return getLongBeanValidation(items);
1004+
}
1005+
10021006
if (ModelUtils.isIntegerSchema(items)) {
10031007
return getIntegerBeanValidation(items);
10041008
}
@@ -1021,6 +1025,21 @@ private String getIntegerBeanValidation(Schema<?> items) {
10211025
return "";
10221026
}
10231027

1028+
private String getLongBeanValidation(Schema<?> items) {
1029+
if (items.getMinimum() != null && items.getMaximum() != null) {
1030+
return String.format(Locale.ROOT, "@Min(%sL) @Max(%sL)", items.getMinimum(), items.getMaximum());
1031+
}
1032+
1033+
if (items.getMinimum() != null) {
1034+
return String.format(Locale.ROOT, "@Min(%sL)", items.getMinimum());
1035+
}
1036+
1037+
if (items.getMaximum() != null) {
1038+
return String.format(Locale.ROOT, "@Max(%sL)", items.getMaximum());
1039+
}
1040+
return "";
1041+
}
1042+
10241043
private String getNumberBeanValidation(Schema<?> items) {
10251044
if (items.getMinimum() != null && items.getMaximum() != null) {
10261045
return String.format(Locale.ROOT, "@DecimalMin(value = \"%s\", inclusive = %s) @DecimalMax(value = \"%s\", inclusive = %s)",

0 commit comments

Comments
 (0)