Browse Source

Merge pull request #45 from avianey/oauth2

Support for custom OAUTH2 param definition
pull/46/head
Johannes Schickling 8 years ago
committed by GitHub
parent
commit
b21df79c18
  1. 5
      swagger-ui/Dockerfile
  2. 9
      swagger-ui/README.md
  3. 23
      swagger-ui/run.sh

5
swagger-ui/Dockerfile

@ -5,6 +5,11 @@ ENV VERSION "v2.2.6"
ENV FOLDER "swagger-ui-2.2.6" ENV FOLDER "swagger-ui-2.2.6"
ENV API_URL "http://petstore.swagger.io/v2/swagger.json" ENV API_URL "http://petstore.swagger.io/v2/swagger.json"
ENV API_KEY "**None**" ENV API_KEY "**None**"
ENV OAUTH_CLIENT_ID "**None**"
ENV OAUTH_CLIENT_SECRET "**None**"
ENV OAUTH_REALM "**None**"
ENV OAUTH_APP_NAME "**None**"
ENV OAUTH_ADDITIONAL_PARAMS "**None**"
ENV SWAGGER_JSON "/app/swagger.json" ENV SWAGGER_JSON "/app/swagger.json"
ENV PORT 80 ENV PORT 80

9
swagger-ui/README.md

@ -1,6 +1,6 @@
# swagger-ui # swagger-ui
Swagger UI 2.2.6 with API_URL and API_KEY injection (45 MB)
Swagger UI 2.2.6 with API_URL, API_KEY and OAUTH2 injection (45 MB)
## Usage ## Usage
@ -14,3 +14,10 @@ $ docker run -d -p 80:80 -e API_URL=http://localhost:4000/swagger schickling/swa
* `API_KEY` - Default API Key (optional) * `API_KEY` - Default API Key (optional)
* `PORT` - Default port to run on (optional) * `PORT` - Default port to run on (optional)
* `VALIDATOR_URL` - Swagger validator (optional) * `VALIDATOR_URL` - Swagger validator (optional)
* `OAUTH_CLIENT_ID` - oAuth2 client ID (optional, use empty to remove)
* `OAUTH_CLIENT_SECRET` - oAuth2 client secret (optional, use empty to remove)
* `OAUTH_REALM` - oAuth2 realm (optional, use empty to remove)
* `OAUTH_APP_NAME` - oAuth2 app name (optional, use empty to remove)
* `OAUTH_ADDITIONAL_PARAMS` - oAuth2 query string additional params (optional)
Variable value `**None**` should not be used for above defined variables.

23
swagger-ui/run.sh

@ -2,10 +2,29 @@
set -e set -e
if [ "$API_KEY" != "**None**" ]; then
replace_in_index () {
if [ "$1" != "**None**" ]; then
sed -i "s|/\*||g" index.html sed -i "s|/\*||g" index.html
sed -i "s|\*/||g" index.html sed -i "s|\*/||g" index.html
sed -i "s|myApiKeyXXXX123456789|$API_KEY|g" index.html
sed -i "s|$1|$2|g" index.html
fi
}
replace_or_delete_in_index () {
if [ -z "$2" ]; then
sed -i "/$1/d" index.html
else
replace_in_index $1 $2
fi
}
replace_in_index myApiKeyXXXX123456789 $API_KEY
replace_or_delete_in_index your-client-id $OAUTH_CLIENT_ID
replace_or_delete_in_index your-client-secret-if-required $OAUTH_CLIENT_SECRET
replace_or_delete_in_index your-realms $OAUTH_REALM
replace_or_delete_in_index your-app-name $OAUTH_APP_NAME
if [ "$OAUTH_ADDITIONAL_PARAMS" != "**None**" ]; then
replace_in_index "additionalQueryStringParams: {}" "additionalQueryStringParams: {$OAUTH_ADDITIONAL_PARAMS}"
fi fi
if [[ -f $SWAGGER_JSON ]]; then if [[ -f $SWAGGER_JSON ]]; then

Loading…
Cancel
Save