Skip to content

Commit

Permalink
Fix OpenAPITools#17757 - Include minimum and maximum values in arrays…
Browse files Browse the repository at this point in the history
… with number items (OpenAPITools#17759)
  • Loading branch information
MarBode authored Feb 7, 2024
1 parent 5a7f050 commit cbc3453
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1003,21 +1003,21 @@ private String getNumberBeanValidation(Schema<?> items) {
if (items.getMinimum() != null && items.getMaximum() != null) {
return String.format(Locale.ROOT, "@DecimalMin(value = \"%s\", inclusive = %s) @DecimalMax(value = \"%s\", inclusive = %s)",
items.getMinimum(),
Optional.ofNullable(items.getExclusiveMinimum()).orElse(Boolean.FALSE),
!Optional.ofNullable(items.getExclusiveMinimum()).orElse(Boolean.FALSE),
items.getMaximum(),
Optional.ofNullable(items.getExclusiveMaximum()).orElse(Boolean.FALSE));
!Optional.ofNullable(items.getExclusiveMaximum()).orElse(Boolean.FALSE));
}

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

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

return "";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ private static Consumer<Map<String, File>> assertWithValidationWithoutJsonNullab
.withType("List<@Max(10) Integer>")
.toType()
.hasProperty("numberMinMax")
.withType("List<@DecimalMin(value = \"1\", inclusive = false) @DecimalMax(value = \"10\", inclusive = false) BigDecimal>")
.withType("List<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>")
.toType()
.hasProperty("numberMin")
.withType("List<@DecimalMin(value = \"1\", inclusive = false) BigDecimal>")
.withType("List<@DecimalMin(value = \"1\", inclusive = true) BigDecimal>")
.toType()
.hasProperty("numberMax")
.withType("List<@DecimalMax(value = \"10\", inclusive = false) BigDecimal>")
.withType("List<@DecimalMax(value = \"10\", inclusive = true) BigDecimal>")
.toType()
.hasProperty("stringPatternWithMin")
.withType("Set<@Pattern(regexp = \"^\\\\d{3}-\\\\d{2}-\\\\d{4}$\") @Size(min = 10) String>")
Expand All @@ -88,7 +88,7 @@ private static Consumer<Map<String, File>> assertWithValidationWithoutJsonNullab
.withType("Set<@Size(max = 1) String>")
.toType()
.hasProperty("stringNumbers")
.withType("Set<@DecimalMin(value = \"1\", inclusive = false) @DecimalMax(value = \"10\", inclusive = false) BigDecimal>")
.withType("Set<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>")
.toType()
.hasProperty("intMinMaxNullable")
.withType("List<@Min(1) @Max(10) Integer>")
Expand All @@ -100,13 +100,13 @@ private static Consumer<Map<String, File>> assertWithValidationWithoutJsonNullab
.withType("List<@Max(10) Integer>")
.toType()
.hasProperty("numberMinMaxNullable")
.withType("List<@DecimalMin(value = \"1\", inclusive = false) @DecimalMax(value = \"10\", inclusive = false) BigDecimal>")
.withType("List<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>")
.toType()
.hasProperty("numberMinNullable")
.withType("List<@DecimalMin(value = \"1\", inclusive = false) BigDecimal>")
.withType("List<@DecimalMin(value = \"1\", inclusive = true) BigDecimal>")
.toType()
.hasProperty("numberMaxNullable")
.withType("List<@DecimalMax(value = \"10\", inclusive = true) BigDecimal>")
.withType("List<@DecimalMax(value = \"10\", inclusive = false) BigDecimal>")
.toType();
}

Expand Down Expand Up @@ -138,13 +138,13 @@ private static Consumer<Map<String, File>> assertWithValidationWithJsonNullable(
.withType("List<@Max(10) Integer>")
.toType()
.hasProperty("numberMinMax")
.withType("List<@DecimalMin(value = \"1\", inclusive = false) @DecimalMax(value = \"10\", inclusive = false) BigDecimal>")
.withType("List<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>")
.toType()
.hasProperty("numberMin")
.withType("List<@DecimalMin(value = \"1\", inclusive = false) BigDecimal>")
.withType("List<@DecimalMin(value = \"1\", inclusive = true) BigDecimal>")
.toType()
.hasProperty("numberMax")
.withType("List<@DecimalMax(value = \"10\", inclusive = false) BigDecimal>")
.withType("List<@DecimalMax(value = \"10\", inclusive = true) BigDecimal>")
.toType()
.hasProperty("stringPatternWithMin")
.withType("JsonNullable<Set<@Pattern(regexp = \"^\\\\d{3}-\\\\d{2}-\\\\d{4}$\") @Size(min = 10) String>>")
Expand All @@ -162,7 +162,7 @@ private static Consumer<Map<String, File>> assertWithValidationWithJsonNullable(
.withType("JsonNullable<Set<@Size(max = 1) String>>")
.toType()
.hasProperty("stringNumbers")
.withType("Set<@DecimalMin(value = \"1\", inclusive = false) @DecimalMax(value = \"10\", inclusive = false) BigDecimal>")
.withType("Set<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>")
.toType()
.hasProperty("intMinMaxNullable")
.withType("JsonNullable<List<@Min(1) @Max(10) Integer>>")
Expand All @@ -174,13 +174,13 @@ private static Consumer<Map<String, File>> assertWithValidationWithJsonNullable(
.withType("JsonNullable<List<@Max(10) Integer>>")
.toType()
.hasProperty("numberMinMaxNullable")
.withType("JsonNullable<List<@DecimalMin(value = \"1\", inclusive = false) @DecimalMax(value = \"10\", inclusive = false) BigDecimal>>")
.withType("JsonNullable<List<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>>")
.toType()
.hasProperty("numberMinNullable")
.withType("JsonNullable<List<@DecimalMin(value = \"1\", inclusive = false) BigDecimal>>")
.withType("JsonNullable<List<@DecimalMin(value = \"1\", inclusive = true) BigDecimal>>")
.toType()
.hasProperty("numberMaxNullable")
.withType("JsonNullable<List<@DecimalMax(value = \"10\", inclusive = true) BigDecimal>>")
.withType("JsonNullable<List<@DecimalMax(value = \"10\", inclusive = false) BigDecimal>>")
.toType();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -973,8 +973,6 @@ public void shouldAddValidAnnotationIntoCollectionWhenBeanValidationIsEnabled_is
.withType( "Set<Integer>" );
}



@Test
public void shouldAddValidAnnotationIntoCollectionWhenBeanValidationIsEnabled_issue17150() throws IOException {
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
Expand Down Expand Up @@ -1025,13 +1023,13 @@ public void shouldAddValidAnnotationIntoCollectionWhenBeanValidationIsEnabled_is
.withType( "List<@Max(10) Integer>" )
.toType()
.hasProperty("numberMinMax")
.withType( "List<@DecimalMin(value = \"1\", inclusive = false) @DecimalMax(value = \"10\", inclusive = false) BigDecimal>" )
.withType( "List<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>" )
.toType()
.hasProperty("numberMin")
.withType( "List<@DecimalMin(value = \"1\", inclusive = false) BigDecimal>" )
.withType( "List<@DecimalMin(value = \"1\", inclusive = true) BigDecimal>" )
.toType()
.hasProperty("numberMax")
.withType( "List<@DecimalMax(value = \"10\", inclusive = false) BigDecimal>" )
.withType( "List<@DecimalMax(value = \"10\", inclusive = true) BigDecimal>" )
.toType()

.hasProperty("stringPatternNullable")
Expand All @@ -1056,13 +1054,13 @@ public void shouldAddValidAnnotationIntoCollectionWhenBeanValidationIsEnabled_is
.withType( "JsonNullable<List<@Max(10) Integer>>" )
.toType()
.hasProperty("numberMinMaxNullable")
.withType( "JsonNullable<List<@DecimalMin(value = \"1\", inclusive = false) @DecimalMax(value = \"10\", inclusive = false) BigDecimal>>" )
.withType( "JsonNullable<List<@DecimalMin(value = \"1\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>>" )
.toType()
.hasProperty("numberMinNullable")
.withType( "JsonNullable<List<@DecimalMin(value = \"1\", inclusive = false) BigDecimal>>" )
.withType( "JsonNullable<List<@DecimalMin(value = \"1\", inclusive = true) BigDecimal>>" )
.toType()
.hasProperty("numberMaxNullable")
.withType( "JsonNullable<List<@DecimalMax(value = \"10\", inclusive = false) BigDecimal>>" )
.withType( "JsonNullable<List<@DecimalMax(value = \"10\", inclusive = true) BigDecimal>>" )
.toType()
;
}
Expand Down

0 comments on commit cbc3453

Please sign in to comment.