Skip to content

Commit cbc3453

Browse files
authored
Fix #17757 - Include minimum and maximum values in arrays with number items (#17759)
1 parent 5a7f050 commit cbc3453

3 files changed

Lines changed: 24 additions & 26 deletions

File tree

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,21 +1003,21 @@ private String getNumberBeanValidation(Schema<?> items) {
10031003
if (items.getMinimum() != null && items.getMaximum() != null) {
10041004
return String.format(Locale.ROOT, "@DecimalMin(value = \"%s\", inclusive = %s) @DecimalMax(value = \"%s\", inclusive = %s)",
10051005
items.getMinimum(),
1006-
Optional.ofNullable(items.getExclusiveMinimum()).orElse(Boolean.FALSE),
1006+
!Optional.ofNullable(items.getExclusiveMinimum()).orElse(Boolean.FALSE),
10071007
items.getMaximum(),
1008-
Optional.ofNullable(items.getExclusiveMaximum()).orElse(Boolean.FALSE));
1008+
!Optional.ofNullable(items.getExclusiveMaximum()).orElse(Boolean.FALSE));
10091009
}
10101010

10111011
if (items.getMinimum() != null) {
10121012
return String.format(Locale.ROOT, "@DecimalMin( value = \"%s\", inclusive = %s)",
10131013
items.getMinimum(),
1014-
Optional.ofNullable(items.getExclusiveMinimum()).orElse(Boolean.FALSE));
1014+
!Optional.ofNullable(items.getExclusiveMinimum()).orElse(Boolean.FALSE));
10151015
}
10161016

10171017
if (items.getMaximum() != null) {
10181018
return String.format(Locale.ROOT, "@DecimalMax( value = \"%s\", inclusive = %s)",
10191019
items.getMaximum(),
1020-
Optional.ofNullable(items.getExclusiveMaximum()).orElse(Boolean.FALSE));
1020+
!Optional.ofNullable(items.getExclusiveMaximum()).orElse(Boolean.FALSE));
10211021
}
10221022

10231023
return "";

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaValidationArrayPrimitivesTest.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,13 @@ private static Consumer<Map<String, File>> assertWithValidationWithoutJsonNullab
6464
.withType("List<@Max(10) Integer>")
6565
.toType()
6666
.hasProperty("numberMinMax")
67-
.withType("List<@DecimalMin(value = \"1\", inclusive = false) @DecimalMax(value = \"10\", inclusive = false) BigDecimal>")
67+
.withType("List<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>")
6868
.toType()
6969
.hasProperty("numberMin")
70-
.withType("List<@DecimalMin(value = \"1\", inclusive = false) BigDecimal>")
70+
.withType("List<@DecimalMin(value = \"1\", inclusive = true) BigDecimal>")
7171
.toType()
7272
.hasProperty("numberMax")
73-
.withType("List<@DecimalMax(value = \"10\", inclusive = false) BigDecimal>")
73+
.withType("List<@DecimalMax(value = \"10\", inclusive = true) BigDecimal>")
7474
.toType()
7575
.hasProperty("stringPatternWithMin")
7676
.withType("Set<@Pattern(regexp = \"^\\\\d{3}-\\\\d{2}-\\\\d{4}$\") @Size(min = 10) String>")
@@ -88,7 +88,7 @@ private static Consumer<Map<String, File>> assertWithValidationWithoutJsonNullab
8888
.withType("Set<@Size(max = 1) String>")
8989
.toType()
9090
.hasProperty("stringNumbers")
91-
.withType("Set<@DecimalMin(value = \"1\", inclusive = false) @DecimalMax(value = \"10\", inclusive = false) BigDecimal>")
91+
.withType("Set<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>")
9292
.toType()
9393
.hasProperty("intMinMaxNullable")
9494
.withType("List<@Min(1) @Max(10) Integer>")
@@ -100,13 +100,13 @@ private static Consumer<Map<String, File>> assertWithValidationWithoutJsonNullab
100100
.withType("List<@Max(10) Integer>")
101101
.toType()
102102
.hasProperty("numberMinMaxNullable")
103-
.withType("List<@DecimalMin(value = \"1\", inclusive = false) @DecimalMax(value = \"10\", inclusive = false) BigDecimal>")
103+
.withType("List<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>")
104104
.toType()
105105
.hasProperty("numberMinNullable")
106-
.withType("List<@DecimalMin(value = \"1\", inclusive = false) BigDecimal>")
106+
.withType("List<@DecimalMin(value = \"1\", inclusive = true) BigDecimal>")
107107
.toType()
108108
.hasProperty("numberMaxNullable")
109-
.withType("List<@DecimalMax(value = \"10\", inclusive = true) BigDecimal>")
109+
.withType("List<@DecimalMax(value = \"10\", inclusive = false) BigDecimal>")
110110
.toType();
111111
}
112112

@@ -138,13 +138,13 @@ private static Consumer<Map<String, File>> assertWithValidationWithJsonNullable(
138138
.withType("List<@Max(10) Integer>")
139139
.toType()
140140
.hasProperty("numberMinMax")
141-
.withType("List<@DecimalMin(value = \"1\", inclusive = false) @DecimalMax(value = \"10\", inclusive = false) BigDecimal>")
141+
.withType("List<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>")
142142
.toType()
143143
.hasProperty("numberMin")
144-
.withType("List<@DecimalMin(value = \"1\", inclusive = false) BigDecimal>")
144+
.withType("List<@DecimalMin(value = \"1\", inclusive = true) BigDecimal>")
145145
.toType()
146146
.hasProperty("numberMax")
147-
.withType("List<@DecimalMax(value = \"10\", inclusive = false) BigDecimal>")
147+
.withType("List<@DecimalMax(value = \"10\", inclusive = true) BigDecimal>")
148148
.toType()
149149
.hasProperty("stringPatternWithMin")
150150
.withType("JsonNullable<Set<@Pattern(regexp = \"^\\\\d{3}-\\\\d{2}-\\\\d{4}$\") @Size(min = 10) String>>")
@@ -162,7 +162,7 @@ private static Consumer<Map<String, File>> assertWithValidationWithJsonNullable(
162162
.withType("JsonNullable<Set<@Size(max = 1) String>>")
163163
.toType()
164164
.hasProperty("stringNumbers")
165-
.withType("Set<@DecimalMin(value = \"1\", inclusive = false) @DecimalMax(value = \"10\", inclusive = false) BigDecimal>")
165+
.withType("Set<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>")
166166
.toType()
167167
.hasProperty("intMinMaxNullable")
168168
.withType("JsonNullable<List<@Min(1) @Max(10) Integer>>")
@@ -174,13 +174,13 @@ private static Consumer<Map<String, File>> assertWithValidationWithJsonNullable(
174174
.withType("JsonNullable<List<@Max(10) Integer>>")
175175
.toType()
176176
.hasProperty("numberMinMaxNullable")
177-
.withType("JsonNullable<List<@DecimalMin(value = \"1\", inclusive = false) @DecimalMax(value = \"10\", inclusive = false) BigDecimal>>")
177+
.withType("JsonNullable<List<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>>")
178178
.toType()
179179
.hasProperty("numberMinNullable")
180-
.withType("JsonNullable<List<@DecimalMin(value = \"1\", inclusive = false) BigDecimal>>")
180+
.withType("JsonNullable<List<@DecimalMin(value = \"1\", inclusive = true) BigDecimal>>")
181181
.toType()
182182
.hasProperty("numberMaxNullable")
183-
.withType("JsonNullable<List<@DecimalMax(value = \"10\", inclusive = true) BigDecimal>>")
183+
.withType("JsonNullable<List<@DecimalMax(value = \"10\", inclusive = false) BigDecimal>>")
184184
.toType();
185185
}
186186

modules/openapi-generator/src/test/java/org/openapitools/codegen/java/spring/SpringCodegenTest.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -973,8 +973,6 @@ public void shouldAddValidAnnotationIntoCollectionWhenBeanValidationIsEnabled_is
973973
.withType( "Set<Integer>" );
974974
}
975975

976-
977-
978976
@Test
979977
public void shouldAddValidAnnotationIntoCollectionWhenBeanValidationIsEnabled_issue17150() throws IOException {
980978
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
@@ -1025,13 +1023,13 @@ public void shouldAddValidAnnotationIntoCollectionWhenBeanValidationIsEnabled_is
10251023
.withType( "List<@Max(10) Integer>" )
10261024
.toType()
10271025
.hasProperty("numberMinMax")
1028-
.withType( "List<@DecimalMin(value = \"1\", inclusive = false) @DecimalMax(value = \"10\", inclusive = false) BigDecimal>" )
1026+
.withType( "List<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>" )
10291027
.toType()
10301028
.hasProperty("numberMin")
1031-
.withType( "List<@DecimalMin(value = \"1\", inclusive = false) BigDecimal>" )
1029+
.withType( "List<@DecimalMin(value = \"1\", inclusive = true) BigDecimal>" )
10321030
.toType()
10331031
.hasProperty("numberMax")
1034-
.withType( "List<@DecimalMax(value = \"10\", inclusive = false) BigDecimal>" )
1032+
.withType( "List<@DecimalMax(value = \"10\", inclusive = true) BigDecimal>" )
10351033
.toType()
10361034

10371035
.hasProperty("stringPatternNullable")
@@ -1056,13 +1054,13 @@ public void shouldAddValidAnnotationIntoCollectionWhenBeanValidationIsEnabled_is
10561054
.withType( "JsonNullable<List<@Max(10) Integer>>" )
10571055
.toType()
10581056
.hasProperty("numberMinMaxNullable")
1059-
.withType( "JsonNullable<List<@DecimalMin(value = \"1\", inclusive = false) @DecimalMax(value = \"10\", inclusive = false) BigDecimal>>" )
1057+
.withType( "JsonNullable<List<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>>" )
10601058
.toType()
10611059
.hasProperty("numberMinNullable")
1062-
.withType( "JsonNullable<List<@DecimalMin(value = \"1\", inclusive = false) BigDecimal>>" )
1060+
.withType( "JsonNullable<List<@DecimalMin(value = \"1\", inclusive = true) BigDecimal>>" )
10631061
.toType()
10641062
.hasProperty("numberMaxNullable")
1065-
.withType( "JsonNullable<List<@DecimalMax(value = \"10\", inclusive = false) BigDecimal>>" )
1063+
.withType( "JsonNullable<List<@DecimalMax(value = \"10\", inclusive = true) BigDecimal>>" )
10661064
.toType()
10671065
;
10681066
}

0 commit comments

Comments
 (0)