|
15 | 15 | import io.swagger.v3.core.filter.resources.ReplaceGetOperationsFilter;
|
16 | 16 | import io.swagger.v3.core.matchers.SerializationMatchers;
|
17 | 17 | import io.swagger.v3.core.util.Json;
|
| 18 | +import io.swagger.v3.core.util.Json31; |
18 | 19 | import io.swagger.v3.core.util.ResourceUtils;
|
19 | 20 | import io.swagger.v3.oas.models.Components;
|
20 | 21 | import io.swagger.v3.oas.models.OpenAPI;
|
|
37 | 38 | import static org.testng.Assert.assertNotEquals;
|
38 | 39 | import static org.testng.Assert.assertNotNull;
|
39 | 40 | import static org.testng.Assert.assertNull;
|
| 41 | +import static org.testng.Assert.assertTrue; |
40 | 42 | import static org.testng.Assert.fail;
|
41 | 43 |
|
42 | 44 | public class SpecFilterTest {
|
43 | 45 |
|
44 | 46 | private static final String RESOURCE_RECURSIVE_MODELS = "specFiles/recursivemodels.json";
|
45 | 47 | private static final String RESOURCE_PATH = "specFiles/petstore-3.0-v2.json";
|
46 | 48 | private static final String RESOURCE_PATH_3303 = "specFiles/petstore-3.0-v2-ticket-3303.json";
|
| 49 | + private static final String RESOURCE_PATH_LIST = "specFiles/3.1.0/list-3.1.json"; |
47 | 50 | private static final String RESOURCE_REFERRED_SCHEMAS = "specFiles/petstore-3.0-referred-schemas.json";
|
48 | 51 | private static final String RESOURCE_PATH_WITHOUT_MODELS = "specFiles/petstore-3.0-v2_withoutModels.json";
|
49 | 52 | private static final String RESOURCE_DEPRECATED_OPERATIONS = "specFiles/deprecatedoperationmodel.json";
|
@@ -273,6 +276,16 @@ public void shouldRemoveBrokenNestedRefs() throws IOException {
|
273 | 276 | assertNotNull(filtered.getComponents().getSchemas().get("discriminatorMatchedChildB"));
|
274 | 277 | }
|
275 | 278 |
|
| 279 | + @Test |
| 280 | + public void shouldRemoveBrokenNestedRefsKeepArray() throws IOException { |
| 281 | + final OpenAPI openAPI = getOpenAPI31(RESOURCE_PATH_LIST); |
| 282 | + final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter(); |
| 283 | + final OpenAPI filtered = new SpecFilter().filter(openAPI, remover, null, null, null); |
| 284 | + |
| 285 | + assertEquals(filtered.getComponents().getSchemas().size(), 2, "Expected to have parent and child list schemas"); |
| 286 | + assertTrue(filtered.getComponents().getSchemas().containsKey("SomeChildObject"), "Schemas should contains child list"); |
| 287 | + } |
| 288 | + |
276 | 289 | @Test
|
277 | 290 | public void shouldNotRemoveGoodRefs() throws IOException {
|
278 | 291 | final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
|
@@ -438,4 +451,9 @@ private OpenAPI getOpenAPI(String path) throws IOException {
|
438 | 451 | final String json = ResourceUtils.loadClassResource(getClass(), path);
|
439 | 452 | return Json.mapper().readValue(json, OpenAPI.class);
|
440 | 453 | }
|
| 454 | + |
| 455 | + private OpenAPI getOpenAPI31(String path) throws IOException { |
| 456 | + final String json = ResourceUtils.loadClassResource(getClass(), path); |
| 457 | + return Json31.mapper().readValue(json, OpenAPI.class); |
| 458 | + } |
441 | 459 | }
|
0 commit comments