Search in sources :

Example 6 with SpecFilter

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

the class SpecFilterTest method retainNonBrokenReferenceModelComposedProperties.

@Test(description = "it should retain non-broken reference model composed properties")
public void retainNonBrokenReferenceModelComposedProperties() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_REFERRED_SCHEMAS);
    assertNotNull(openAPI.getComponents().getSchemas().get("User"));
    final NoOpOperationsFilter noOperationsFilter = new NoOpOperationsFilter();
    OpenAPI filtered = new SpecFilter().filter(openAPI, noOperationsFilter, null, null, null);
    assertNotNull(filtered.getComponents().getSchemas().get("User"));
    final RemoveUnreferencedDefinitionsFilter refFilter = new RemoveUnreferencedDefinitionsFilter();
    filtered = new SpecFilter().filter(openAPI, refFilter, null, null, null);
    assertNotNull(filtered.getComponents().getSchemas().get("User"));
    assertNotNull(filtered.getComponents().getSchemas().get("Pet"));
}
Also used : RemoveUnreferencedDefinitionsFilter(io.swagger.v3.core.filter.resources.RemoveUnreferencedDefinitionsFilter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) NoOpOperationsFilter(io.swagger.v3.core.filter.resources.NoOpOperationsFilter) Test(org.testng.annotations.Test)

Example 7 with SpecFilter

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

the class SpecFilterTest method filterWithNullDefinitions.

@Test(description = "it should filter with null definitions")
public void filterWithNullDefinitions() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    openAPI.getComponents().setSchemas(null);
    final InternalModelPropertiesRemoverFilter filter = new InternalModelPropertiesRemoverFilter();
    final OpenAPI filtered = new SpecFilter().filter(openAPI, filter, null, null, null);
    assertNotNull(filtered);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) InternalModelPropertiesRemoverFilter(io.swagger.v3.core.filter.resources.InternalModelPropertiesRemoverFilter) Test(org.testng.annotations.Test)

Example 8 with SpecFilter

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

the class SpecFilterTest method changeGetResources.

@Test(description = "it should change away with a new operation")
public void changeGetResources() throws IOException {
    final OpenAPI openAPI = getOpenAPI(RESOURCE_PATH);
    OpenAPI filter = new SpecFilter().filter(openAPI, new ChangeGetOperationsFilter(), null, null, null);
    assertOperations(filter, CHANGED_OPERATION_ID, CHANGED_OPERATION_DESCRIPTION);
}
Also used : ChangeGetOperationsFilter(io.swagger.v3.core.filter.resources.ChangeGetOperationsFilter) OpenAPI(io.swagger.v3.oas.models.OpenAPI) Test(org.testng.annotations.Test)

Example 9 with SpecFilter

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

the class SpecFilterTest method cloneWithoutModels.

@Test(description = "it should clone everything from JSON without models")
public void cloneWithoutModels() throws IOException {
    final String json = ResourceUtils.loadClassResource(getClass(), RESOURCE_PATH_WITHOUT_MODELS);
    final OpenAPI openAPI = Json.mapper().readValue(json, OpenAPI.class);
    final OpenAPI filtered = new SpecFilter().filter(openAPI, new NoOpOperationsFilter(), null, null, null);
    SerializationMatchers.assertEqualsToJson(filtered, json);
}
Also used : OpenAPI(io.swagger.v3.oas.models.OpenAPI) NoOpOperationsFilter(io.swagger.v3.core.filter.resources.NoOpOperationsFilter) Test(org.testng.annotations.Test)

Example 10 with SpecFilter

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

the class SpecFilterTest method removeUnreferencedModelOverride.

@Test(description = "broken references should not result in NPE")
public void removeUnreferencedModelOverride() 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"));
}
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