use of io.swagger.core.filter.SpecFilter in project swagger-core by swagger-api.
the class BaseApiListingResource method process.
protected Swagger process(Application app, ServletContext servletContext, ServletConfig sc, HttpHeaders headers, UriInfo uriInfo) {
SwaggerContextService ctxService = new SwaggerContextService().withServletConfig(sc).withBasePath(getBasePath(uriInfo));
Swagger swagger = ctxService.getSwagger();
synchronized (ApiListingResource.class) {
if (SwaggerContextService.isScannerIdInitParamDefined(sc)) {
if (!initializedScanner.containsKey(sc.getServletName() + "_" + SwaggerContextService.getScannerIdFromInitParam(sc))) {
swagger = scan(app, servletContext, sc, uriInfo);
}
} else {
if (SwaggerContextService.isConfigIdInitParamDefined(sc)) {
if (!initializedConfig.containsKey(sc.getServletName() + "_" + SwaggerContextService.getConfigIdFromInitParam(sc))) {
swagger = scan(app, servletContext, sc, uriInfo);
}
} else if (SwaggerContextService.isUsePathBasedConfigInitParamDefined(sc)) {
if (!initializedConfig.containsKey(sc.getServletName() + "_" + ctxService.getBasePath())) {
swagger = scan(app, servletContext, sc, uriInfo);
}
} else if (!initialized) {
swagger = scan(app, servletContext, sc, uriInfo);
}
}
}
if (swagger != null) {
SwaggerSpecFilter filterImpl = FilterFactory.getFilter();
if (filterImpl != null) {
SpecFilter f = new SpecFilter();
swagger = f.filter(swagger, filterImpl, getQueryParams(uriInfo.getQueryParameters()), getCookies(headers), getHeaders(headers));
}
}
return swagger;
}
use of io.swagger.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 Swagger swagger = getSwagger("specFiles/deprecatedoperationmodel.json");
final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
final Swagger filtered = new SpecFilter().filter(swagger, remover, null, null, null);
Operation operation = filtered.getPath("/test").getOperations().get(0);
Boolean deprectedFlag = operation.isDeprecated();
assertNotNull(deprectedFlag);
assertEquals(deprectedFlag, Boolean.TRUE);
}
use of io.swagger.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 Swagger swagger = getSwagger("specFiles/petstore.json");
final NoGetOperationsFilter filter = new NoGetOperationsFilter();
final Swagger filtered = new SpecFilter().filter(swagger, filter, null, null, null);
if (filtered.getPaths() != null) {
for (Map.Entry<String, Path> entry : filtered.getPaths().entrySet()) {
assertNull(entry.getValue().getGet());
}
} else {
fail("paths should not be null");
}
}
use of io.swagger.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 Swagger swagger = getSwagger("specFiles/recursivemodels.json");
final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
final Swagger filtered = new SpecFilter().filter(swagger, remover, null, null, null);
assertNotNull(filtered.getDefinitions().get("SelfReferencingModel"));
assertNotNull(filtered.getDefinitions().get("IndirectRecursiveModelA"));
assertNotNull(filtered.getDefinitions().get("IndirectRecursiveModelB"));
}
use of io.swagger.core.filter.SpecFilter in project swagger-core by swagger-api.
the class SpecFilterTest method filterNoPropertiesModels.
@Test(description = "it should filter models where some fields have no properties")
public void filterNoPropertiesModels() throws IOException {
final String modelName = "Array";
final ModelImpl model = new ModelImpl().type(ModelImpl.OBJECT).name(modelName);
final Swagger swagger = new Swagger();
swagger.addDefinition(modelName, model);
final Map<String, Model> filtered = new SpecFilter().filterDefinitions(new NoOpOperationsFilter(), swagger.getDefinitions(), null, null, null);
if (filtered.size() != 1) {
fail("ModelImpl with no properties failed to filter");
}
}
Aggregations