How to use this:
# Make a suitable directory
mkdir whatever && cd whatever
# Set up virtual env
virtualenv --python=python3 venv
source venv/bin/activate
pip install flask flask_restplus
# Download app.py
wget 'https://gist.githubusercontent.com/austinjp/c0c3ed361fd54ed4faf0065eb40502eb/raw/app.py'
# Smoke-test:
python ./app.py # Should produce no output
# Serve on localhost:
FLASK_DEBUG=1 FLASK_ENV=development FLASK_APP=app.py \
flask run --port 4000 --debuggerVisit http://127.0.0.1:4000/api/ and you should see a Swagger page complaining that there are "No operations defined in spec!" which is correct. Check the console wherein you ran Flask, and you should see something like:
* Serving Flask app "app.py" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on https://127.0.0.1:4000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 123-456-789
127.0.0.1 - - [15/Dec/2019 12:53:34] "GET /api/swagger.json HTTP/1.1" 200 -
127.0.0.1 - - [15/Dec/2019 12:53:35] "GET /api/ HTTP/1.1" 200 -
127.0.0.1 - - [15/Dec/2019 12:53:35] "GET /swaggerui/droid-sans.css HTTP/1.1" 304 -
127.0.0.1 - - [15/Dec/2019 12:53:35] "GET /swaggerui/swagger-ui.css HTTP/1.1" 304 -
127.0.0.1 - - [15/Dec/2019 12:53:35] "GET /swaggerui/swagger-ui-bundle.js HTTP/1.1" 304 -
127.0.0.1 - - [15/Dec/2019 12:53:35] "GET /swaggerui/swagger-ui-standalone-preset.js HTTP/1.1" 304 -
127.0.0.1 - - [15/Dec/2019 12:53:35] "GET /api/swagger.json HTTP/1.1" 200 -
Note that swagger.json is located at /api 😃
To test over SSL, do the following. Note, this is not appropriate for production, just for testing on localhost.
pip install pyopenssl
FLASK_DEBUG=1 FLASK_ENV=development FLASK_APP=app.py \
flask run --port 4000 --debugger --cert=adhocVisit https://127.0.0.1:4000/api/ (don't forget the trailing slash) and you will be warned about accepting the certificate. This is fine for testing. Accept, and you'll see the same Swagger page. In the console you should see something like:
* Serving Flask app "app.py" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: on
* Running on https://127.0.0.1:4000/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 123-456-789
127.0.0.1 - - [15/Dec/2019 12:36:15] "GET /api/ HTTP/1.1" 200 -
127.0.0.1 - - [15/Dec/2019 12:36:15] "GET /swaggerui/droid-sans.css HTTP/1.1" 304 -
127.0.0.1 - - [15/Dec/2019 12:36:16] "GET /swaggerui/swagger-ui-standalone-preset.js HTTP/1.1" 304 -
127.0.0.1 - - [15/Dec/2019 12:36:16] "GET /swaggerui/swagger-ui-bundle.js HTTP/1.1" 304 -
127.0.0.1 - - [15/Dec/2019 12:36:16] "GET /swaggerui/swagger-ui.css HTTP/1.1" 304 -
127.0.0.1 - - [15/Dec/2019 12:36:16] "GET /api/swagger.json HTTP/1.1" 200 -
Again, note swagger.json is found at /api.