Search in sources :

Example 1 with SpecFilter

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

the class SpecFilterTest method filterAwayPathItemWithoutRef.

@Test(description = "it should filter any PathItem objects without Ref")
public void filterAwayPathItemWithoutRef() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    final OpenAPI filtered = new SpecFilter().filter(openAPI, new NoPathItemFilter(), null, null, null);
    assertEquals(0, filtered.getPaths().size());
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) NoPathItemFilter(io.swagger.v3.core.filter.resources.NoPathItemFilter) Test(org.testng.annotations.Test)

Example 2 with SpecFilter

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

the class SpecFilterTest method cloneEverythingConcurrent.

@Test(description = "it should clone everything concurrently")
public void cloneEverythingConcurrent() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    ThreadGroup tg = new ThreadGroup("SpecFilterTest" + "|" + System.currentTimeMillis());
    final Map<String, OpenAPI> filteredMap = new ConcurrentHashMap<>();
    for (int i = 0; i < 10; i++) {
        final int id = i;
        new Thread(tg, "SpecFilterTest") {

            public void run() {
                try {
                    filteredMap.put("filtered " + id, new SpecFilter().filter(openAPI, new NoOpOperationsFilter(), null, null, null));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
    }
    new Thread(new FailureHandler(tg, filteredMap, openAPI)).start();
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) OpenAPI(io.swagger.v3.oas.models.OpenAPI) NoOpOperationsFilter(io.swagger.v3.core.filter.resources.NoOpOperationsFilter) IOException(java.io.IOException) Test(org.testng.annotations.Test)

Example 3 with SpecFilter

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

the class SpecFilterTest method filterAwayQueryParameters.

@Test(description = "it should filter any query parameter")
public void filterAwayQueryParameters() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    final OpenAPI filtered = new SpecFilter().filter(openAPI, new NoParametersWithoutQueryInFilter(), null, null, null);
    if (filtered.getPaths() != null) {
        for (Map.Entry<String, PathItem> entry : filtered.getPaths().entrySet()) {
            validateParameters(entry.getValue().getGet());
            validateParameters(entry.getValue().getPost());
            validateParameters(entry.getValue().getPut());
            validateParameters(entry.getValue().getPatch());
            validateParameters(entry.getValue().getHead());
            validateParameters(entry.getValue().getDelete());
            validateParameters(entry.getValue().getOptions());
        }
    }
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) NoParametersWithoutQueryInFilter(io.swagger.v3.core.filter.resources.NoParametersWithoutQueryInFilter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.testng.annotations.Test)

Example 4 with SpecFilter

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

the class SpecFilterTest method shouldNotRemoveGoodRefs.

@Test
public void shouldNotRemoveGoodRefs() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    assertNotNull(openAPI.getComponents().getSchemas().get("PetHeader"));
    final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
    final OpenAPI filtered = new SpecFilter().filter(openAPI, remover, null, null, null);
    assertNotNull(filtered.getComponents().getSchemas().get("PetHeader"));
    assertNotNull(filtered.getComponents().getSchemas().get("Category"));
}
Also used : RemoveUnreferencedDefinitionsFilter(io.swagger.v3.core.filter.resources.RemoveUnreferencedDefinitionsFilter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 5 with SpecFilter

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

the class SpecFilterTest method replaceGetResources.

@Test(description = "it should replace away with a new operation")
public void replaceGetResources() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    OpenAPI filter = new SpecFilter().filter(openAPI, new ReplaceGetOperationsFilter(), null, null, null);
    assertOperations(filter, NEW_OPERATION_ID, NEW_OPERATION_DESCRIPTION);
}
Also used : ReplaceGetOperationsFilter(io.swagger.v3.core.filter.resources.ReplaceGetOperationsFilter) 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