Demo of using Swagger UI for API documentation for any codebase without library dependencies. Here, we provide a demo using Flask and Python.
Check out my blog post for more details and explanations, especially on how to generalize this to work across different languages & frameworks.
To save some installation effort, you can follow the instructions in this section to build and run a Docker image that has everything you need.
The following command builds a Docker image tagged swagger-demo
:
./build-docker.sh
To run it (you have to be in the top level of this repo):
./run-docker.sh
Then go to http://127.0.0.1:5000/swagger-ui
.
You can modify api-docs.yml
and refresh to see the updates.
Install any version of Python 3.x using pyenv and nodejs 8.x using nvm. Details using concrete examples below.
For pyenv and npm, follow the instructions on their GitHub READMEs.
pyenv install 3.6.3
pyenv virtualenv 3.6.3 swagger-demo
pyenv activate swagger-demo
pip install -r requirements.txt
pyenv activate swagger-demo
python server.py
Go to http://127.0.0.1:5000/swagger-ui to see the swagger ui. Update api-docs.yml and refresh to see the changes
All files except:
- files in /swagger-ui-dist
- the
nocache
function in server.py
are under the MIT License, Copyright (c) 2017-2018 Pang Yan Han