Search in sources :

Example 6 with RemoveUnreferencedDefinitionsFilter

use of io.swagger.v3.core.filter.resources.RemoveUnreferencedDefinitionsFilter in project swagger-core by swagger-api.

the class SpecFilterTest method retainModelsReferencesFromAdditionalProperties.

@Test(description = "Retain models referenced from additonalProperties")
public void retainModelsReferencesFromAdditionalProperties() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_REFERRED_SCHEMAS);
    final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
    final OpenAPI filtered = new SpecFilter().filter(openAPI, remover, null, null, null);
    assertNotNull(filtered.getComponents().getSchemas().get("Order"));
    assertNotNull(filtered.getComponents().getSchemas().get("ReferredOrder"));
}
Also used : RemoveUnreferencedDefinitionsFilter(io.swagger.v3.core.filter.resources.RemoveUnreferencedDefinitionsFilter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 7 with RemoveUnreferencedDefinitionsFilter

use of io.swagger.v3.core.filter.resources.RemoveUnreferencedDefinitionsFilter in project swagger-core by swagger-api.

the class SpecFilterTest method shouldRemoveBrokenRefs.

@Test
public void shouldRemoveBrokenRefs() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    openAPI.getPaths().get("/pet/{petId}").getGet().getResponses().getDefault().getHeaders().remove("X-Rate-Limit-Limit");
    assertNotNull(openAPI.getComponents().getSchemas().get("PetHeader"));
    final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
    final OpenAPI filtered = new SpecFilter().filter(openAPI, remover, null, null, null);
    assertNull(filtered.getComponents().getSchemas().get("PetHeader"));
    assertNotNull(filtered.getComponents().getSchemas().get("Category"));
    assertNotNull(filtered.getComponents().getSchemas().get("Pet"));
}
Also used : RemoveUnreferencedDefinitionsFilter(io.swagger.v3.core.filter.resources.RemoveUnreferencedDefinitionsFilter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 8 with RemoveUnreferencedDefinitionsFilter

use of io.swagger.v3.core.filter.resources.RemoveUnreferencedDefinitionsFilter in project swagger-core by swagger-api.

the class SpecFilterTest method shouldRemoveBrokenNestedRefs.

@Test
public void shouldRemoveBrokenNestedRefs() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH_3303);
    openAPI.getPaths().get("/pet/{petId}").getGet().getResponses().getDefault().getHeaders().remove("X-Rate-Limit-Limit");
    assertNotNull(openAPI.getComponents().getSchemas().get("PetHeader"));
    final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
    final OpenAPI filtered = new SpecFilter().filter(openAPI, remover, null, null, null);
    assertNull(filtered.getComponents().getSchemas().get("PetHeader"));
    assertNull(filtered.getComponents().getSchemas().get("Bar"));
    assertNotNull(filtered.getComponents().getSchemas().get("Category"));
    assertNotNull(filtered.getComponents().getSchemas().get("Pet"));
    assertNotNull(filtered.getComponents().getSchemas().get("Foo"));
    assertNotNull(filtered.getComponents().getSchemas().get("allOfChild"));
    assertNotNull(filtered.getComponents().getSchemas().get("anyOfChild"));
    assertNotNull(filtered.getComponents().getSchemas().get("oneOfChild"));
    assertNotNull(filtered.getComponents().getSchemas().get("allOfparentA"));
    assertNotNull(filtered.getComponents().getSchemas().get("allOfparentB"));
    assertNotNull(filtered.getComponents().getSchemas().get("anyOfparentA"));
    assertNotNull(filtered.getComponents().getSchemas().get("anyOfparentB"));
    assertNotNull(filtered.getComponents().getSchemas().get("oneOfparentA"));
    assertNotNull(filtered.getComponents().getSchemas().get("oneOfparentB"));
    assertNotNull(filtered.getComponents().getSchemas().get("oneOfNestedParentA"));
    assertNotNull(filtered.getComponents().getSchemas().get("oneOfNestedParentB"));
    assertNotNull(filtered.getComponents().getSchemas().get("discriminatorParent"));
    assertNotNull(filtered.getComponents().getSchemas().get("discriminatorMatchedChildA"));
    assertNotNull(filtered.getComponents().getSchemas().get("discriminatorRefProperty"));
    assertNotNull(filtered.getComponents().getSchemas().get("discriminatorParentRefProperty"));
    assertNotNull(filtered.getComponents().getSchemas().get("discriminatorMatchedChildB"));
}
Also used : RemoveUnreferencedDefinitionsFilter(io.swagger.v3.core.filter.resources.RemoveUnreferencedDefinitionsFilter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Aggregations

RemoveUnreferencedDefinitionsFilter (io.swagger.v3.core.filter.resources.RemoveUnreferencedDefinitionsFilter)8 OpenAPI (io.swagger.v3.oas.models.OpenAPI)8 Test (org.testng.annotations.Test)8 NoOpOperationsFilter (io.swagger.v3.core.filter.resources.NoOpOperationsFilter)1 Operation (io.swagger.v3.oas.models.Operation)1