|
7 | 7 | import io.swagger.v3.oas.models.headers.Header; |
8 | 8 | import io.swagger.v3.oas.models.info.Info; |
9 | 9 | import io.swagger.v3.oas.models.media.ArraySchema; |
| 10 | +import io.swagger.v3.oas.models.media.BooleanSchema; |
10 | 11 | import io.swagger.v3.oas.models.media.ComposedSchema; |
11 | 12 | import io.swagger.v3.oas.models.media.IntegerSchema; |
| 13 | +import io.swagger.v3.oas.models.media.StringSchema; |
12 | 14 | import io.swagger.v3.oas.models.media.Schema; |
13 | 15 | import io.swagger.v3.oas.models.parameters.Parameter; |
14 | 16 | import io.swagger.v3.oas.models.parameters.RequestBody; |
@@ -91,6 +93,7 @@ public class V2ConverterTest { |
91 | 93 | private static final String ISSUE_820_YAML = "issue-820.yaml"; |
92 | 94 | private static final String ISSUE_1032_YAML = "issue-1032.yaml"; |
93 | 95 | private static final String ISSUE_1113_YAML = "issue-1113.yaml"; |
| 96 | + private static final String ISSUE_1164_YAML = "issue-1164.yaml"; |
94 | 97 |
|
95 | 98 | private static final String API_BATCH_PATH = "/api/batch/"; |
96 | 99 | private static final String PETS_PATH = "/pets"; |
@@ -790,7 +793,37 @@ public void testIssue1113() throws Exception { |
790 | 793 | assertNotNull(oas.getServers().get(0)); |
791 | 794 | assertEquals(oas.getServers().get(0).getUrl(), "/test"); |
792 | 795 | } |
793 | | - |
| 796 | + |
| 797 | + @Test(description = "OpenAPI v2 converter - uses specialized schema subclasses where available") |
| 798 | + public void testIssue1164() throws Exception { |
| 799 | + final OpenAPI oas = getConvertedOpenAPIFromJsonFile(ISSUE_1164_YAML); |
| 800 | + assertNotNull(oas); |
| 801 | + assertNotNull(oas.getPaths()); |
| 802 | + assertNotNull(oas.getPaths().get("/foo")); |
| 803 | + assertNotNull(oas.getPaths().get("/foo").getGet()); |
| 804 | + assertNotNull(oas.getPaths().get("/foo").getGet().getRequestBody()); |
| 805 | + assertNotNull(oas.getPaths().get("/foo").getGet().getRequestBody().getContent()); |
| 806 | + assertNotNull(oas.getPaths().get("/foo").getGet().getRequestBody().getContent().get("multipart/form-data")); |
| 807 | + Schema formSchema = oas.getPaths().get("/foo").getGet().getRequestBody().getContent().get("multipart/form-data").getSchema(); |
| 808 | + assertNotNull(formSchema); |
| 809 | + assertNotNull(formSchema.getProperties()); |
| 810 | + assertEquals(4, formSchema.getProperties().size()); |
| 811 | + assertTrue(formSchema.getProperties().get("first") instanceof StringSchema); |
| 812 | + |
| 813 | + assertTrue(formSchema.getProperties().get("second") instanceof BooleanSchema); |
| 814 | + |
| 815 | + assertTrue(formSchema.getProperties().get("third") instanceof StringSchema); |
| 816 | + StringSchema third = (StringSchema) formSchema.getProperties().get("third"); |
| 817 | + assertNotNull(third.getFormat()); |
| 818 | + assertTrue("password".equals(third.getFormat())); |
| 819 | + |
| 820 | + assertTrue(formSchema.getProperties().get("fourth") instanceof BooleanSchema); |
| 821 | + Schema fourth = (Schema) formSchema.getProperties().get("fourth"); |
| 822 | + assertNotNull(fourth.getType()); |
| 823 | + assertNotNull(fourth.getFormat()); |
| 824 | + assertTrue("completely-custom".equals(fourth.getFormat())); |
| 825 | + } |
| 826 | + |
794 | 827 | private OpenAPI getConvertedOpenAPIFromJsonFile(String file) throws IOException, URISyntaxException { |
795 | 828 | SwaggerConverter converter = new SwaggerConverter(); |
796 | 829 | String swaggerAsString = new String(Files.readAllBytes(Paths.get(getClass().getClassLoader().getResource(file).toURI()))); |
|
0 commit comments