Search in sources :

Example 1 with RemoveUnreferencedDefinitionsFilter

use of io.swagger.v3.core.filter.resources.RemoveUnreferencedDefinitionsFilter 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 2 with RemoveUnreferencedDefinitionsFilter

use of io.swagger.v3.core.filter.resources.RemoveUnreferencedDefinitionsFilter 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 3 with RemoveUnreferencedDefinitionsFilter

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

Example 4 with RemoveUnreferencedDefinitionsFilter

use of io.swagger.v3.core.filter.resources.RemoveUnreferencedDefinitionsFilter 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 5 with RemoveUnreferencedDefinitionsFilter

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

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