|
10 | 10 | import io.swagger.v3.core.oas.models.ModelWithEnumField;
|
11 | 11 | import io.swagger.v3.core.oas.models.ModelWithEnumProperty;
|
12 | 12 | import io.swagger.v3.core.oas.models.ModelWithEnumRefProperty;
|
| 13 | +import io.swagger.v3.core.oas.models.ModelWithJacksonEnumField; |
13 | 14 | import io.swagger.v3.oas.models.media.Schema;
|
14 | 15 | import io.swagger.v3.oas.models.media.StringSchema;
|
15 | 16 | import org.testng.annotations.AfterTest;
|
@@ -156,4 +157,25 @@ public void testEnumRefPropertyGlobalNotAffectingNonEnums() {
|
156 | 157 | SerializationMatchers.assertEqualsToYaml(models, yaml);
|
157 | 158 | ModelResolver.enumsAsRef = false;
|
158 | 159 | }
|
| 160 | + |
| 161 | + @Test(description = "it should extract enum values from fields using JsonProperty and JsonValue") |
| 162 | + public void testExtractJacksonEnumFields() { |
| 163 | + final Map<String, Schema> models = ModelConverters.getInstance().read(ModelWithJacksonEnumField.class); |
| 164 | + final Schema model = models.get("ModelWithJacksonEnumField"); |
| 165 | + |
| 166 | + final Schema firstEnumProperty = (Schema) model.getProperties().get("firstEnumValue"); |
| 167 | + assertTrue(firstEnumProperty instanceof StringSchema); |
| 168 | + final StringSchema stringProperty = (StringSchema) firstEnumProperty; |
| 169 | + assertEquals(stringProperty.getEnum(), Arrays.asList("p1", "p2", "SYSTEM", "INVITE_ONLY")); |
| 170 | + |
| 171 | + final Schema secondEnumProperty = (Schema) model.getProperties().get("secondEnumValue"); |
| 172 | + assertTrue(secondEnumProperty instanceof StringSchema); |
| 173 | + final StringSchema secondStringProperty = (StringSchema) secondEnumProperty; |
| 174 | + assertEquals(secondStringProperty.getEnum(), Arrays.asList("one", "two", "three")); |
| 175 | + |
| 176 | + final Schema thirdEnumProperty = (Schema) model.getProperties().get("thirdEnumValue"); |
| 177 | + assertTrue(thirdEnumProperty instanceof StringSchema); |
| 178 | + final StringSchema thirdStringProperty = (StringSchema) thirdEnumProperty; |
| 179 | + assertEquals(thirdStringProperty.getEnum(), Arrays.asList("2", "4", "6")); |
| 180 | + } |
159 | 181 | }
|
0 commit comments