Thomas Vachuska

Added redirect for the /onos/v1/docs Swagger UI URL. Added onos-rsdocs tool to …

…launch REST API docs UI from shell.

Change-Id: Ifb839e0205e5b176ebc7bb48644925eaa3675fd9
......@@ -30,6 +30,11 @@ export PATH="$PATH:$MAVEN/bin:$KARAF_ROOT/bin"
# Setup cell enviroment
export ONOS_CELL=${ONOS_CELL:-local}
# Setup default web user; for local dev execution use Karaf defaults
export ONOS_WEB_USER=${ONOS_WEB_USER:-karaf}
export ONOS_WEB_PASS=${ONOS_WEB_PASS:-karaf}
# Setup default location of test scenarios
export ONOS_SCENARIOS=$ONOS_ROOT/tools/test/scenarios
# Convenience utility to warp to various ONOS source projects
......@@ -78,8 +83,9 @@ alias ole='olo "ERROR|WARN|Exception|Error"'
# Pretty-print JSON output
alias pp='python -m json.tool'
# Short-hand to launch API docs and sample topology viewer GUI
# Short-hand to launch Java API docs, REST API docs and ONOS GUI
alias docs='open $ONOS_ROOT/docs/target/site/apidocs/index.html'
alias rsdocs='onos-rsdocs'
alias gui='onos-gui'
......
#!/bin/bash
# -----------------------------------------------------------------------------
# Launches ONOS REST API docs GUI on the specified node.
# -----------------------------------------------------------------------------
host=${1:-$OCI}
host=${host:-localhost}
open http://$host:8181/onos/v1/docs
......@@ -23,15 +23,20 @@ import org.onosproject.rest.ApiDocService;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.SequenceInputStream;
import java.net.URI;
import java.net.URISyntaxException;
import static com.google.common.collect.ImmutableList.of;
import static com.google.common.io.ByteStreams.toByteArray;
import static javax.ws.rs.core.MediaType.*;
import static javax.ws.rs.core.Response.temporaryRedirect;
import static org.onlab.util.Tools.nullIsNotFound;
/**
......@@ -48,6 +53,9 @@ public class ApiDocResource extends AbstractInjectionResource {
private static final String INJECT_START = "<!-- {API-START} -->";
private static final String INJECT_END = "<!-- {API-END} -->";
@Context
private UriInfo uriInfo;
/**
* Get all registered REST API docs.
* Returns array of all registered API docs.
......@@ -102,8 +110,9 @@ public class ApiDocResource extends AbstractInjectionResource {
*/
@GET
@Path("/")
public Response getDefault() throws IOException {
return getIndex();
public Response getDefault() throws IOException, URISyntaxException {
return uriInfo.getPath().endsWith("/") ? getIndex() :
temporaryRedirect(new URI(uriInfo.getPath() + "/")).build();
}
/**
......