* URL, given the method name and method definition returned by
* {@link #getMethodForUrl(ApiService, String)}.
*/
@VisibleForTesting
static String createExplorerLink(ApiService service, String url, ApiMethod method) {
UrlBuilder builder = new UrlBuilder();
// Add the basic information to the
builder.addRootNavigationItem(RootNavigationItem.ALL_VERSIONS)
.addService(service.getName(), service.getVersion())
.addMethodName(method.getId());
// Calculate the params from the path template and url.
URLFragment parsed = URLFragment.parseFragment(url);
Multimap<String, String> params = HashMultimap.create();
String pathTemplate = method.getPath();
if (pathTemplate.contains("{")) {
String urlPath = parsed.getPath().replaceFirst(Config.getBaseUrl() + service.basePath(), "");
String[] templateSections = pathTemplate.split("/");
String[] urlSections = urlPath.split("/");
for (int i = 0; i < templateSections.length; i++) {
if (templateSections[i].contains("{")) {
String paramName = templateSections[i].substring(1, templateSections[i].length() - 1);
params.put(paramName, urlSections[i]);
}
}
}
// Apply the params.
String fullUrl = builder.addQueryParams(params).toString();
// Check if the url had query parameters to add.
if (!parsed.getQueryString().isEmpty()) {
fullUrl = fullUrl + parsed.getQueryString();
}