Skip to content

How to run swagger-ui with local code changes AND my own swagger.json? #3675

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

Closed
HaraldNordgren opened this issue Sep 16, 2017 · 7 comments
Closed

Comments

@HaraldNordgren
Copy link

The Readme specifies that Swagger-UI can be run with your own file like this

docker run -p 80:8080 -e SWAGGER_JSON=/foo/swagger.json -v /bar:/foo swaggerapi/swagger-ui

which works I if I translate it to

docker build . -t swagger-ui-local && \
  docker run -p 80:8080 -e SWAGGER_JSON=/foo/my-file.json -v $PWD:/foo swagger-ui-local

This, however, ignores my local changes.

I can run my local changes with

npm run dev

but I can't figure out how to get this dev server to run anything else than the Petstore example.

Can anyone help me combine the two, so I can run swagger-ui with local code changes AND my own swagger.json?

@HaraldNordgren
Copy link
Author

I think I figured it out for npm run dev:

Place my-file.json in the dev-helpers folder. Then it's available from the search bar in on http://localhost:3200/.

To load it automatically when opening the server, alter dev-helpers/index.html by changing

url: "http://petstore.swagger.io/v2/swagger.json"

to

url: "my-file.json"

@owenconti
Copy link
Contributor

@HaraldNordgren What I do is open http://localhost:3200?url=myfile.json

@1am
Copy link

1am commented Sep 21, 2017

None of things which I've seen so far worked for me so I've made this bash script for starting docker swagger-ui container with my host file linked (and not copied) for live updates of what I'm working on. Maybe it will be helpful for other people looking for option to preview their file edited from host (eg. some text editor you like).

LOCAL_PORT=8080
LOCAL_SWAGGER_FILE=`pwd`/api.yml;

docker run \
    -p ${LOCAL_PORT}:8080 \
    -e SWAGGER_JSON=/usr/share/nginx/html/swagger.json \
    -v ${LOCAL_SWAGGER_FILE}:/usr/share/nginx/html/swagger.json \
    swaggerapi/swagger-ui \
    /bin/sh -c 'sed -i "s|cp \$SWAGGER_JSON \$NGINX_ROOT|\# cp \$SWAGGER_JSON \$NGINX_ROOT|g" /usr/share/nginx/docker-run.sh && . /usr/share/nginx/docker-run.sh'

What it does is essentially commenting out copy statement from docker-run.sh which makes the docker container fail to start because of copying the file specified in SWAGGER_JSON.

@sachinjain024
Copy link

sachinjain024 commented Dec 7, 2017

@HaraldNordgren I recently struggled with the same problem and found a simple trick to solve this situation.

Sharing it here - https://medium.com/@requestly_ext/check-swagger-api-specs-without-hosting-swagger-ui-934861c004de

Maybe it will help you and others. But this is only helpful if you want to view specs on your machine only and not share the IP of your machine with others. But its worth looking at as it minimizes some of the development cycles.

@sal-pal
Copy link

sal-pal commented Jan 24, 2018

@HaraldNordgren Thanks!

@garrettjohnston
Copy link

Make sure you are volume mounting correctly! Check out my answer in this Stack Overflow post https://stackoverflow.com/a/50264343/3838892

@lock
Copy link

lock bot commented Jul 2, 2019

Locking due to inactivity.

This is done to avoid resurrecting old issues and bumping long threads with new, possibly unrelated content.

If you think you're experiencing something similar to what you've found here: please open a new issue, follow the template, and reference this issue in your report.

Thanks!

@lock lock bot locked and limited conversation to collaborators Jul 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants