From 20e7c0708a38e237682f4cba1b31a544c0acec8b Mon Sep 17 00:00:00 2001 From: Franz Wong Date: Sat, 3 Jun 2017 13:01:11 +0900 Subject: [PATCH 1/2] Copy swagger.json to nginx directory --- README.md | 6 ++++++ docker-run.sh | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ba8db614..36ef9d0a 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,12 @@ docker run -p 80:8080 swaggerapi/swagger-ui Will start nginx with swagger-ui on port 80. +Or you can provide your own swagger.json on your host + +``` +docker run -p 80:8080 -e "SWAGGER_JSON=/foo/swagger.json" -v /bar:/foo swaggerapi/swagger-ui +``` + ##### Prerequisites - Node 6.x - NPM 3.x diff --git a/docker-run.sh b/docker-run.sh index aa547321..f8086bd1 100644 --- a/docker-run.sh +++ b/docker-run.sh @@ -2,7 +2,8 @@ set -e -INDEX_FILE=/usr/share/nginx/html/index.html +NGINX_ROOT=/usr/share/nginx/html +INDEX_FILE=$NGINX_ROOT/index.html replace_in_index () { if [ "$1" != "**None**" ]; then @@ -30,6 +31,7 @@ if [ "$OAUTH_ADDITIONAL_PARAMS" != "**None**" ]; then fi if [[ -f $SWAGGER_JSON ]]; then + cp $SWAGGER_JSON $NGINX_ROOT sed -i "s|http://petstore.swagger.io/v2/swagger.json|swagger.json|g" $INDEX_FILE sed -i "s|http://example.com/api|swagger.json|g" $INDEX_FILE else From 08c691894d954a767c8b2aa29e0f1e042293191f Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Fri, 9 Jun 2017 11:40:33 -0700 Subject: [PATCH 2/2] extract basename from $SWAGGER_JSON file --- docker-run.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docker-run.sh b/docker-run.sh index f8086bd1..896994e4 100644 --- a/docker-run.sh +++ b/docker-run.sh @@ -32,8 +32,9 @@ fi if [[ -f $SWAGGER_JSON ]]; then cp $SWAGGER_JSON $NGINX_ROOT - sed -i "s|http://petstore.swagger.io/v2/swagger.json|swagger.json|g" $INDEX_FILE - sed -i "s|http://example.com/api|swagger.json|g" $INDEX_FILE + REL_PATH="/$(basename $SWAGGER_JSON)" + sed -i "s|http://petstore.swagger.io/v2/swagger.json|$REL_PATH|g" $INDEX_FILE + sed -i "s|http://example.com/api|$REL_PATH|g" $INDEX_FILE else sed -i "s|http://petstore.swagger.io/v2/swagger.json|$API_URL|g" $INDEX_FILE sed -i "s|http://example.com/api|$API_URL|g" $INDEX_FILE