Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SWAGGER_FILE env var #2072

Merged
merged 6 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ ADD ./dist/*.css /usr/share/nginx/html/dist/
ADD ./dist/*.png /usr/share/nginx/html/dist/
ADD ./docker-run.sh /usr/share/nginx/

RUN find /usr/share/nginx/html/ -type f -regex ".*\.\(html\|js\|css\)" -exec sh -c "gzip < {} > {}.gz" \;

EXPOSE 8080

CMD ["sh", "/usr/share/nginx/docker-run.sh"]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,12 @@ docker run -d -p 80:8080 swaggerapi/swagger-editor

This will run Swagger Editor (in detached mode) on port 80 on your machine, so you can open it by navigating to `http://localhost` in your browser.

Or you can provide your own `json` or `yaml` definition file on your host

```
docker run -d -p 80:8080 -v $(pwd):/tmp -e SWAGGER_FILE=/tmp/swagger.json swaggerapi/swagger-editor
```

### Building and running an image locally

To build and run a docker image with the code checked out on your machine, run the following from the root directory of the project:
Expand Down
15 changes: 13 additions & 2 deletions docker-run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,19 @@

set -e

INDEX_FILE=/usr/share/nginx/html/index.html
NGINX_ROOT=/usr/share/nginx/html
INDEX_FILE=$NGINX_ROOT/index.html

# TODO: this is empty but we'll be adding configuration values here

exec nginx -g 'daemon off;'
## Adding env var support for swagger file (json or yaml)
if [[ -f $SWAGGER_FILE ]]; then
cp -s $SWAGGER_FILE $NGINX_ROOT
REL_PATH="/$(basename $SWAGGER_FILE)"
sed -i "s|https://petstore.swagger.io/v2/swagger.json|$REL_PATH|g" $INDEX_FILE
fi

# Gzip after replacements
find /usr/share/nginx/html/ -type f -regex ".*\.\(html\|js\|css\)" -exec sh -c "gzip < {} > {}.gz" \;

exec nginx -g 'daemon off;'
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
window.onload = function() {
// Build a system
const editor = SwaggerEditorBundle({
url: "https://petstore.swagger.io/v2/swagger.json",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change necessary? I'd like to avoid loading a url by default, since we have our own methods of providing a default value in the Editor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

petstore example is what I see by default whenever I start the swagger editor. I have seen the default json included with the source code, to be petstore. If url is not a required attrib, you can kindly skip it. I am outside rn, and wont be able to change the source code. Feel free to edit them for me pls

dom_id: '#swagger-editor',
layout: 'StandaloneLayout',
presets: [
Expand Down