use of io.swagger.core.filter.SwaggerSpecFilter 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.SwaggerSpecFilter in project ORCID-Source by ORCID.
the class SwaggerJSONResource method getListingYaml.
@GET
@Produces("application/yaml")
@Path(OrcidApiConstants.SWAGGER_FILE_YAML)
@ApiOperation(value = "The swagger definition in YAML", hidden = true)
public Response getListingYaml(@Context Application app, @Context HttpHeaders headers, @Context UriInfo uriInfo) {
Swagger swagger = (Swagger) context.getAttribute("swagger");
if (!initialized) {
swagger = scan(app);
}
try {
if (swagger != null) {
SwaggerSpecFilter filterImpl = FilterFactory.getFilter();
LOGGER.debug("using filter " + filterImpl);
if (filterImpl != null) {
SpecFilter f = new SpecFilter();
swagger = f.filter(swagger, filterImpl, getQueryParams(uriInfo.getQueryParameters()), getCookies(headers), getHeaders(headers));
}
String yaml = Yaml.mapper().writeValueAsString(swagger);
String[] parts = yaml.split("\n");
StringBuilder b = new StringBuilder();
for (String part : parts) {
//int pos = part.indexOf("!<");
//int endPos = part.indexOf(">");
b.append(part);
b.append("\n");
}
return Response.ok().entity(b.toString()).type("application/yaml").build();
}
} catch (Exception e) {
e.printStackTrace();
}
return Response.status(404).build();
}
use of io.swagger.core.filter.SwaggerSpecFilter in project ORCID-Source by ORCID.
the class SwaggerJSONResource method getListingJson.
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path(OrcidApiConstants.SWAGGER_FILE)
@ApiOperation(value = "The swagger definition in JSON", hidden = true)
public Response getListingJson(@Context Application app, @Context HttpHeaders headers, @Context UriInfo uriInfo) {
Swagger swagger = (Swagger) context.getAttribute("swagger");
if (!initialized) {
swagger = scan(app);
}
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 Response.ok().entity(swagger).build();
} else {
return Response.status(404).build();
}
}
Aggregations