Search in sources :

Example 26 with SpecFilter

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

the class SpecFilterTest method filterAwayGetOperations.

@Test(description = "it should filter away get operations in a resource")
public void filterAwayGetOperations() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    final NoGetOperationsFilter filter = new NoGetOperationsFilter();
    final OpenAPI filtered = new SpecFilter().filter(openAPI, filter, null, null, null);
    if (filtered.getPaths() != null) {
        for (Map.Entry<String, PathItem> entry : filtered.getPaths().entrySet()) {
            assertNull(entry.getValue().getGet());
        }
    } else {
        fail("paths should not be null");
    }
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) NoGetOperationsFilter(io.swagger.v3.core.filter.resources.NoGetOperationsFilter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.testng.annotations.Test)

Example 27 with SpecFilter

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

the class SpecFilterTest method shouldNotContainTopLevelUserTags.

@Test(description = "it should not contain user tags in the top level OpenAPI object")
public void shouldNotContainTopLevelUserTags() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_REFERRED_SCHEMAS);
    final NoPetOperationsFilter filter = new NoPetOperationsFilter();
    final OpenAPI filtered = new SpecFilter().filter(openAPI, filter, null, null, null);
    assertEquals(getTagNames(filtered), Sets.newHashSet(USER_TAG, STORE_TAG));
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) NoPetOperationsFilter(io.swagger.v3.core.filter.resources.NoPetOperationsFilter) Test(org.testng.annotations.Test)

Example 28 with SpecFilter

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

the class SpecFilterTest method filterAwayInternalModelProperties.

@Test(description = "it should filter away internal model properties")
public void filterAwayInternalModelProperties() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    final InternalModelPropertiesRemoverFilter filter = new InternalModelPropertiesRemoverFilter();
    final OpenAPI filtered = new SpecFilter().filter(openAPI, filter, null, null, null);
    for (Map.Entry<String, Schema> entry : filtered.getComponents().getSchemas().entrySet()) {
        for (String propName : (Set<String>) entry.getValue().getProperties().keySet()) {
            assertFalse(propName.startsWith("_"));
        }
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) Schema(io.swagger.v3.oas.models.media.Schema) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) InternalModelPropertiesRemoverFilter(io.swagger.v3.core.filter.resources.InternalModelPropertiesRemoverFilter) Test(org.testng.annotations.Test)

Example 29 with SpecFilter

use of io.swagger.v3.core.filter.SpecFilter 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 30 with SpecFilter

use of io.swagger.v3.core.filter.SpecFilter 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

OpenAPI (io.swagger.v3.oas.models.OpenAPI)32 Test (org.testng.annotations.Test)28 OpenAPISpecFilter (io.swagger.v3.core.filter.OpenAPISpecFilter)8 SpecFilter (io.swagger.v3.core.filter.SpecFilter)8 RemoveUnreferencedDefinitionsFilter (io.swagger.v3.core.filter.resources.RemoveUnreferencedDefinitionsFilter)8 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)6 NoOpOperationsFilter (io.swagger.v3.core.filter.resources.NoOpOperationsFilter)5 Map (java.util.Map)5 DefaultPrettyPrinter (com.fasterxml.jackson.core.util.DefaultPrettyPrinter)4 AbstractSpecFilter (io.swagger.v3.core.filter.AbstractSpecFilter)4 OpenApiContext (io.swagger.v3.oas.integration.api.OpenApiContext)4 Components (io.swagger.v3.oas.models.Components)4 PathItem (io.swagger.v3.oas.models.PathItem)4 Info (io.swagger.v3.oas.models.info.Info)4 OpenApiConfigurationException (io.swagger.v3.oas.integration.OpenApiConfigurationException)3 IOException (java.io.IOException)3 InternalModelPropertiesRemoverFilter (io.swagger.v3.core.filter.resources.InternalModelPropertiesRemoverFilter)2 NoPetOperationsFilter (io.swagger.v3.core.filter.resources.NoPetOperationsFilter)2 JaxrsOpenApiContextBuilder (io.swagger.v3.jaxrs2.integration.JaxrsOpenApiContextBuilder)2 GenericOpenApiContextBuilder (io.swagger.v3.oas.integration.GenericOpenApiContextBuilder)2