use of io.swagger.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 Swagger swagger = getSwagger("specFiles/brokenrefmodel.json");
final RemoveUnreferencedDefinitionsFilter remover = new RemoveUnreferencedDefinitionsFilter();
final Swagger filtered = new SpecFilter().filter(swagger, remover, null, null, null);
assertNotNull(filtered.getDefinitions().get("RootModel"));
}
use of io.swagger.core.filter.SpecFilter in project swagger-core by swagger-api.
the class SpecFilterTest method cloneEverythingConcurrent.
@Test(description = "it should clone everything concurrently")
public void cloneEverythingConcurrent() throws IOException {
final Swagger swagger = getSwagger("specFiles/petstore.json");
ThreadGroup tg = new ThreadGroup("SpecFilterTest" + "|" + System.currentTimeMillis());
final Map<String, Swagger> filteredMap = new ConcurrentHashMap<String, Swagger>();
for (int i = 0; i < 10; i++) {
final int id = i;
new Thread(tg, "SpecFilterTest") {
public void run() {
try {
filteredMap.put("filtered " + id, new SpecFilter().filter(swagger, new NoOpOperationsFilter(), null, null, null));
} catch (Exception e) {
e.printStackTrace();
}
}
}.start();
}
new Thread(new FailureHandler(tg, filteredMap, swagger)).start();
}
use of io.swagger.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 Swagger swagger = getSwagger("specFiles/sampleSpec.json");
final InternalModelPropertiesRemoverFilter filter = new InternalModelPropertiesRemoverFilter();
final Swagger filtered = new SpecFilter().filter(swagger, filter, null, null, null);
for (Map.Entry<String, Model> entry : filtered.getDefinitions().entrySet()) {
for (String propName : entry.getValue().getProperties().keySet()) {
assertFalse(propName.startsWith("_"));
}
}
}
use of io.swagger.core.filter.SpecFilter in project swagger-core by swagger-api.
the class SpecFilterTest method filterAwayStoreResource.
@Test(description = "it should filter away the store resource")
public void filterAwayStoreResource() throws IOException {
final Swagger swagger = getSwagger("specFiles/petstore.json");
final NoUserOperationsFilter filter = new NoUserOperationsFilter();
final Swagger filtered = new SpecFilter().filter(swagger, filter, null, null, null);
if (filtered.getPaths() != null) {
for (Map.Entry<String, Path> entry : filtered.getPaths().entrySet()) {
assertNotEquals(entry.getKey(), "/user");
}
} else {
fail("paths should not be null");
}
}
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;
}
Aggregations