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");
}
}
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));
}
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("_"));
}
}
}
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"));
}
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"));
}
Aggregations