use of org.restlet.routing.TemplateRoute in project pinot by linkedin.
the class SwaggerResource method get.
@Get
@Override
public Representation get() {
try {
// Info
JSONObject info = new JSONObject();
info.put("title", "Pinot Controller");
info.put("version", "0.1");
// Paths
JSONObject paths = new JSONObject();
Router router = PinotRestletApplication.getRouter();
RouteList routeList = router.getRoutes();
for (Route route : routeList) {
if (route instanceof TemplateRoute) {
TemplateRoute templateRoute = (TemplateRoute) route;
JSONObject pathObject = new JSONObject();
String routePath = templateRoute.getTemplate().getPattern();
// Check which methods are present
Restlet routeTarget = templateRoute.getNext();
if (routeTarget instanceof Finder) {
Finder finder = (Finder) routeTarget;
generateSwaggerForFinder(pathObject, routePath, finder);
} else if (routeTarget instanceof Filter) {
do {
Filter filter = (Filter) routeTarget;
routeTarget = filter.getNext();
} while (routeTarget instanceof Filter);
if (routeTarget instanceof Finder) {
Finder finder = (Finder) routeTarget;
generateSwaggerForFinder(pathObject, routePath, finder);
}
}
if (pathObject.keys().hasNext()) {
paths.put(routePath, pathObject);
}
}
}
// Tags
JSONArray tags = new JSONArray();
addTag(tags, "tenant", "Tenant-related operations");
addTag(tags, "instance", "Instance-related operations");
addTag(tags, "table", "Table-related operations");
addTag(tags, "segment", "Segment-related operations");
addTag(tags, "schema", "Schema-related operations");
addTag(tags, "version", "Version-related operations");
// Swagger
JSONObject swagger = new JSONObject();
swagger.put("swagger", "2.0");
swagger.put("info", info);
swagger.put("paths", paths);
swagger.put("tags", tags);
StringRepresentation representation = new StringRepresentation(swagger.toString());
// Set up CORS
Series<Header> responseHeaders = (Series<Header>) getResponse().getAttributes().get("org.restlet.http.headers");
if (responseHeaders == null) {
responseHeaders = new Series(Header.class);
getResponse().getAttributes().put("org.restlet.http.headers", responseHeaders);
}
responseHeaders.add(new Header("Access-Control-Allow-Origin", "*"));
return representation;
} catch (JSONException e) {
return new StringRepresentation(e.toString());
}
}
Aggregations