@Override public Route find(HttpVerb verb, String path) { return Do.findIn(all()) .first(route -> route.verb().equals(verb) && route.path().equals(path)) .orElse(null); }
@SuppressWarnings("unchecked") public Map<String, Object> getAPIDocs() { Map<String, Object> docs = createRoot(); Map<String, Object> paths = (Map<String, Object>) docs.computeIfAbsent("paths", x -> U.map()); Map<String, Object> components = (Map<String, Object>) docs.computeIfAbsent("components", x -> U.map()); Map<String, Object> schemas = (Map<String, Object>) components.computeIfAbsent("schemas", x -> U.map()); schemas.computeIfAbsent("Error", x -> OpenAPIModel.defaultErrorSchema()); Do.group(findPublishableRoutes()).by(Route::path).forEach((path, routes) -> { paths.put(path, Do.map(routes).toMap( route -> route.verb().name().toLowerCase(), route -> descRoute(route, components) )); }); return docs; }
private static TableTag routesOf(Set<Route> httpRoutes, boolean withHandler) { List<Route> routes = U.list(httpRoutes); sortRoutes(routes); List<Object> rows = U.list(); rows.add(tr(th("Verb"), th("Path"), th("Zone"), th("Content type"), th("MVC"), th("View name"), th("Roles"), withHandler ? th("Handler") : null)); while (!routes.isEmpty()) { Route route = U.first(routes); List<HttpVerb> verbs = U.list(route.verb()); Iterator<Route> it = routes.iterator(); while (it.hasNext()) { Route other = it.next(); if (route == other) { it.remove(); } else if (sameTarget(route, other)) { verbs.add(other.verb()); it.remove(); } } rows.add(routeRow(route, verbs, withHandler)); } return table_(rows); }
@Override public Route find(HttpVerb verb, String path) { for (Route route : all()) { if (route.verb().equals(verb) && route.path().equals(path)) { return route; } } return null; }
public static TableTag routesOf(Set<Route> httpRoutes, boolean withHandler) { List<Route> routes = U.list(httpRoutes); sortRoutes(routes); List<Object> rows = U.list(); rows.add(tr(th("Verb"), th("Path"), th("Zone"), th("Content type"), th("MVC"), th("View name"), th("Roles"), withHandler ? th("Handler") : null)); while (!routes.isEmpty()) { Route route = U.first(routes); List<HttpVerb> verbs = U.list(route.verb()); Iterator<Route> it = routes.iterator(); while (it.hasNext()) { Route other = it.next(); if (route == other) { it.remove(); } else if (sameTarget(route, other)) { verbs.add(other.verb()); it.remove(); } } rows.add(routeRow(route, verbs, withHandler)); } return table_(rows); }