mirror of
https://github.com/jlengrand/openapi-generator.git
synced 2026-03-10 08:31:23 +00:00
Fix OpenAPITools#17757 - Include minimum and maximum values in arrays with number items (#17759)
This commit is contained in:
@@ -1003,21 +1003,21 @@ public abstract class AbstractJavaCodegen extends DefaultCodegen implements Code
|
||||
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 "";
|
||||
|
||||
@@ -64,13 +64,13 @@ public class JavaValidationArrayPrimitivesTest {
|
||||
.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>")
|
||||
@@ -88,7 +88,7 @@ public class JavaValidationArrayPrimitivesTest {
|
||||
.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>")
|
||||
@@ -100,13 +100,13 @@ public class JavaValidationArrayPrimitivesTest {
|
||||
.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();
|
||||
}
|
||||
|
||||
@@ -138,13 +138,13 @@ public class JavaValidationArrayPrimitivesTest {
|
||||
.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>>")
|
||||
@@ -162,7 +162,7 @@ public class JavaValidationArrayPrimitivesTest {
|
||||
.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>>")
|
||||
@@ -174,13 +174,13 @@ public class JavaValidationArrayPrimitivesTest {
|
||||
.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();
|
||||
}
|
||||
|
||||
|
||||
@@ -973,8 +973,6 @@ public class SpringCodegenTest {
|
||||
.withType( "Set<Integer>" );
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Test
|
||||
public void shouldAddValidAnnotationIntoCollectionWhenBeanValidationIsEnabled_issue17150() throws IOException {
|
||||
File output = Files.createTempDirectory("test").toFile().getCanonicalFile();
|
||||
@@ -1025,13 +1023,13 @@ public class SpringCodegenTest {
|
||||
.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")
|
||||
@@ -1056,13 +1054,13 @@ public class SpringCodegenTest {
|
||||
.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()
|
||||
;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user