Search in sources :

Example 21 with SpecFilter

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

the class SpecFilterTest method removeUnreferencedDefinitionsOfRecuriveModels.

@Test(description = "recursive models, e.g. A-> A or A-> B and B -> A should not result in stack overflow")
public void removeUnreferencedDefinitionsOfRecuriveModels() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_RECURSIVE_MODELS);
    final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
    final OpenAPI filtered = new SpecFilter().filter(openAPI, remover, null, null, null);
    assertNotNull(filtered.getComponents().getSchemas().get("SelfReferencingModel"));
    assertNotNull(filtered.getComponents().getSchemas().get("IndirectRecursiveModelA"));
    assertNotNull(filtered.getComponents().getSchemas().get("IndirectRecursiveModelB"));
}
Also used : RemoveUnreferencedDefinitionsFilter(io.swagger.v3.core.filter.resources.RemoveUnreferencedDefinitionsFilter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 22 with SpecFilter

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

the class SpecFilterTest method cloneRetainDeperecatedFlags.

@Test(description = "Clone should retain any 'deperecated' flags present on operations")
public void cloneRetainDeperecatedFlags() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_DEPRECATED_OPERATIONS);
    final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
    final OpenAPI filtered = new SpecFilter().filter(openAPI, remover, null, null, null);
    Operation operation = filtered.getPaths().get("/test").getGet();
    Boolean deprectedFlag = operation.getDeprecated();
    assertNotNull(deprectedFlag);
    assertEquals(deprectedFlag, Boolean.TRUE);
}
Also used : RemoveUnreferencedDefinitionsFilter(io.swagger.v3.core.filter.resources.RemoveUnreferencedDefinitionsFilter) Operation(io.swagger.v3.oas.models.Operation) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 23 with SpecFilter

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

the class SpecFilterTest method filterAwaySecretParameters.

@Test(description = "it should filter away secret parameters")
public void filterAwaySecretParameters() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    final RemoveInternalParamsFilter filter = new RemoveInternalParamsFilter();
    final OpenAPI filtered = new SpecFilter().filter(openAPI, filter, null, null, null);
    if (filtered.getPaths() != null) {
        for (Map.Entry<String, PathItem> entry : filtered.getPaths().entrySet()) {
            final Operation get = entry.getValue().getGet();
            if (get != null) {
                for (Parameter param : get.getParameters()) {
                    final String description = param.getDescription();
                    if (StringUtils.isNotBlank(description)) {
                        assertFalse(description.startsWith("secret"));
                    }
                }
            }
        }
    } else {
        fail("paths should not be null");
    }
}
Also used : PathItem(io.swagger.v3.oas.models.PathItem) Parameter(io.swagger.v3.oas.models.parameters.Parameter) Operation(io.swagger.v3.oas.models.Operation) RemoveInternalParamsFilter(io.swagger.v3.core.filter.resources.RemoveInternalParamsFilter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.testng.annotations.Test)

Example 24 with SpecFilter

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

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

the class SpecFilterTest method filterAwayOpenAPI.

@Test(description = "it should filter an openAPI object")
public void filterAwayOpenAPI() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    final OpenAPI filtered = new SpecFilter().filter(openAPI, new NoOpenAPIFilter(), null, null, null);
    assertNull(filtered);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) NoOpenAPIFilter(io.swagger.v3.core.filter.resources.NoOpenAPIFilter) 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