|
| 1 | +package io.swagger.v3.core.resolving; |
| 2 | + |
| 3 | +import io.swagger.v3.core.converter.ModelConverters; |
| 4 | +import io.swagger.v3.core.matchers.SerializationMatchers; |
| 5 | +import io.swagger.v3.oas.models.media.Schema; |
| 6 | +import org.testng.annotations.Test; |
| 7 | + |
| 8 | +import javax.validation.constraints.Size; |
| 9 | +import java.util.List; |
| 10 | +import java.util.Map; |
| 11 | + |
| 12 | +public class Ticket4760Test { |
| 13 | + |
| 14 | + @Test |
| 15 | + public void testArraySchemaItemsValidation(){ |
| 16 | + final Map<String, Schema> stringSchemaMap = ModelConverters.getInstance().readAll(ClassWithArraySchemaItemsValidation.class); |
| 17 | + final String expectedJson = "{\n" + |
| 18 | + " \"ClassWithArraySchemaItemsValidation\" : {\n" + |
| 19 | + " \"type\" : \"object\",\n" + |
| 20 | + " \"properties\" : {\n" + |
| 21 | + " \"setOfEnums\" : {\n" + |
| 22 | + " \"maxItems\" : 3,\n" + |
| 23 | + " \"minItems\" : 1,\n" + |
| 24 | + " \"type\" : \"array\",\n" + |
| 25 | + " \"items\" : {\n" + |
| 26 | + " \"type\" : \"string\",\n" + |
| 27 | + " \"enum\" : [ \"green\", \"blue\" ]\n" + |
| 28 | + " }\n" + |
| 29 | + " }\n" + |
| 30 | + " }\n" + |
| 31 | + " }\n" + |
| 32 | + "}"; |
| 33 | + SerializationMatchers.assertEqualsToJson(stringSchemaMap, expectedJson); |
| 34 | + } |
| 35 | + |
| 36 | + private static class ClassWithArraySchemaItemsValidation{ |
| 37 | + |
| 38 | + public enum MyEnum { |
| 39 | + red, |
| 40 | + green |
| 41 | + } |
| 42 | + |
| 43 | + public enum MyOtherEnum { |
| 44 | + green, |
| 45 | + blue |
| 46 | + } |
| 47 | + |
| 48 | + @io.swagger.v3.oas.annotations.media.ArraySchema(schema = @io.swagger.v3.oas.annotations.media.Schema(implementation = MyOtherEnum.class)) |
| 49 | + @Size(min = 1, max = 3) |
| 50 | + private List<MyEnum> setOfEnums; |
| 51 | + |
| 52 | + public List<MyEnum> getSetOfEnums() { |
| 53 | + return setOfEnums; |
| 54 | + } |
| 55 | + |
| 56 | + public void setSetOfEnums(List<MyEnum> setOfEnums) { |
| 57 | + this.setOfEnums = setOfEnums; |
| 58 | + } |
| 59 | + } |
| 60 | +} |
0 commit comments