|
24 | 24 |
|
25 | 25 | import io.swagger.v3.oas.models.parameters.Parameter;
|
26 | 26 | import io.swagger.v3.parser.core.models.ParseOptions;
|
| 27 | + |
| 28 | +import java.math.BigDecimal; |
27 | 29 | import java.time.OffsetDateTime;
|
28 | 30 | import java.time.ZonedDateTime;
|
29 | 31 | import java.util.*;
|
@@ -945,6 +947,93 @@ public void ignoreBeanValidationAnnotationsContainerTest() {
|
945 | 947 | Assert.assertEquals(defaultValue, "List<File>");
|
946 | 948 | }
|
947 | 949 |
|
| 950 | + @Test |
| 951 | + public void AnnotationsContainerTest() { |
| 952 | + final P_AbstractJavaCodegen codegen = new P_AbstractJavaCodegen(); |
| 953 | + codegen.additionalProperties().put("useBeanValidation", true); |
| 954 | + |
| 955 | + // 1. string type |
| 956 | + Schema<?> schema = new ArraySchema().items(new Schema<>().type("string").pattern("^[a-z]$").minLength(0).maxLength(36)); |
| 957 | + String defaultValue = codegen.getTypeDeclaration(schema); |
| 958 | + Assert.assertEquals(defaultValue, "List<@Pattern(regexp = \"^[a-z]$\")@Size(min=0, max = 36) String>"); |
| 959 | + |
| 960 | + schema = new ArraySchema().items(new Schema<>().type("string").pattern("^[a-z]$").minLength(0)); |
| 961 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 962 | + Assert.assertEquals(defaultValue, "List<@Pattern(regexp = \"^[a-z]$\")@Size(min=0) String>"); |
| 963 | + |
| 964 | + schema = new ArraySchema().items(new Schema<>().type("string").pattern("^[a-z]$").maxLength(36)); |
| 965 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 966 | + Assert.assertEquals(defaultValue, "List<@Pattern(regexp = \"^[a-z]$\")@Size(max = 36) String"); |
| 967 | + |
| 968 | + schema = new ArraySchema().items(new Schema<>().type("string").format("email")); |
| 969 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 970 | + Assert.assertEquals(defaultValue, "List<@Email String>"); |
| 971 | + |
| 972 | + // 2. string type with number format |
| 973 | + schema = new ArraySchema().items(new Schema<>().type("string").format("number").minimum(BigDecimal.ZERO).maximum(BigDecimal.TEN).exclusiveMinimum(Boolean.TRUE).exclusiveMaximum(Boolean.TRUE)); |
| 974 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 975 | + Assert.assertEquals(defaultValue, "List<@DecimalMin(value = \"0\", inclusive = true) @DecimalMax(value = \"10\", inclusive = True) String>"); |
| 976 | + |
| 977 | + schema = new ArraySchema().items(new Schema<>().type("string").format("number").minimum(BigDecimal.ZERO).exclusiveMinimum(Boolean.TRUE)); |
| 978 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 979 | + Assert.assertEquals(defaultValue, "List<@DecimalMin(value = \"0\", inclusive = true) String>"); |
| 980 | + |
| 981 | + schema = new ArraySchema().items(new Schema<>().type("string").format("number").maximum(BigDecimal.TEN).exclusiveMaximum(Boolean.TRUE)); |
| 982 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 983 | + Assert.assertEquals(defaultValue, "@DecimalMax(value = \"10\", inclusive = true) String>"); |
| 984 | + |
| 985 | + // 3. number type |
| 986 | + schema = new ArraySchema().items(new Schema<>().type("number").minimum(BigDecimal.ZERO).maximum(BigDecimal.TEN).exclusiveMinimum(Boolean.TRUE).exclusiveMaximum(Boolean.TRUE)); |
| 987 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 988 | + Assert.assertEquals(defaultValue, "List<@DecimalMin(value = \"0\", inclusive = true) @DecimalMax(value = \"10\", inclusive = true) BigDecimal>"); |
| 989 | + |
| 990 | + schema = new ArraySchema().items(new Schema<>().type("number").minimum(BigDecimal.ZERO).exclusiveMinimum(Boolean.TRUE)); |
| 991 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 992 | + Assert.assertEquals(defaultValue, "List<@DecimalMin(value = \"0\", inclusive = true) BigDecimal>"); |
| 993 | + |
| 994 | + schema = new ArraySchema().items(new Schema<>().type("number").maximum(BigDecimal.TEN).exclusiveMaximum(Boolean.TRUE)); |
| 995 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 996 | + Assert.assertEquals(defaultValue, "List<@DecimalMax(value = \"10\", inclusive = true) BigDecimal>"); |
| 997 | + |
| 998 | + schema = new ArraySchema().items(new Schema<>().type("number").minimum(BigDecimal.ZERO).maximum(BigDecimal.TEN)); |
| 999 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 1000 | + Assert.assertEquals(defaultValue, "List<@DecimalMin(value = \"0\", inclusive = false) @DecimalMax(value = \"10\", inclusive = false) BigDecimal>"); |
| 1001 | + |
| 1002 | + schema = new ArraySchema().items(new Schema<>().type("number").minimum(BigDecimal.ZERO)); |
| 1003 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 1004 | + Assert.assertEquals(defaultValue, "List<@DecimalMin(value = \"0\", inclusive = false) BigDecimal>"); |
| 1005 | + |
| 1006 | + schema = new ArraySchema().items(new Schema<>().type("number").maximum(BigDecimal.TEN)); |
| 1007 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 1008 | + Assert.assertEquals(defaultValue, "List<@DecimalMax(value = \"10\", inclusive = false) BigDecimal>"); |
| 1009 | + |
| 1010 | + // 4. integer type with int64 format |
| 1011 | + schema = new ArraySchema().items(new Schema<>().type("integer").format("int64").minimum(BigDecimal.ZERO).maximum(BigDecimal.TEN)); |
| 1012 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 1013 | + Assert.assertEquals(defaultValue, "List<@Min(0L) @Max(10L) Long>"); |
| 1014 | + |
| 1015 | + schema = new ArraySchema().items(new Schema<>().type("integer").format("int64").minimum(BigDecimal.ZERO)); |
| 1016 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 1017 | + Assert.assertEquals(defaultValue, "List<@Min(0L) Long>"); |
| 1018 | + |
| 1019 | + schema = new ArraySchema().items(new Schema<>().type("integer").format("int64").maximum(BigDecimal.TEN)); |
| 1020 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 1021 | + Assert.assertEquals(defaultValue, "List<@Max(10L) Long>"); |
| 1022 | + |
| 1023 | + // 5. integer type |
| 1024 | + schema = new ArraySchema().items(new Schema<>().type("integer").minimum(BigDecimal.ZERO).maximum(BigDecimal.TEN)); |
| 1025 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 1026 | + Assert.assertEquals(defaultValue, "List<@Min(0L) @Max(10L) Long>"); |
| 1027 | + |
| 1028 | + schema = new ArraySchema().items(new Schema<>().type("integer").minimum(BigDecimal.ZERO)); |
| 1029 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 1030 | + Assert.assertEquals(defaultValue, "List<@Min(0L) Long>"); |
| 1031 | + |
| 1032 | + schema = new ArraySchema().items(new Schema<>().type("integer").maximum(BigDecimal.TEN)); |
| 1033 | + defaultValue = codegen.getTypeDeclaration(schema); |
| 1034 | + Assert.assertEquals(defaultValue, "List<@Max(10L) Long>"); |
| 1035 | + } |
| 1036 | + |
948 | 1037 | private static Schema<?> createObjectSchemaWithMinItems() {
|
949 | 1038 | return new ObjectSchema()
|
950 | 1039 | .addProperties("id", new IntegerSchema().format("int32"))
|
|
0 commit comments