DmitriiDenisov / Swagger-lab

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Swagger-lab

Instructions:

  1. Copy files from this repo Structure of your project now should be:
.
├── static
|   ├── hello_api.json
│   ├── css
│   │   └── swagger-ui.css
│   ├── img
│   │   ├── favicon-16x16.png
│   │   └── favicon-32x32.png
│   └── js
│       ├── swagger-ui-bundle.js
│       ├── swagger-ui-standalone-preset.js
│       └── swagger-ui.js
└── templates
    ├── swaggerui.html
  1. Write your API spec for Swagger. Go to Swagger Editor and write your API spec in YAML.

  2. Once you are ready go to File->Convert and save as JSON. Example of such json. Also Swagger Editor itself by default gives you a great example

  3. Put your generated json in static/hello_api.json

  4. Return swaggerui.html with flask render_template in your preferred route, example:

@app.route('/api/docs')
def get_docs():
    print('sending docs')
    return render_template('swaggerui.html')

Source

Example of JSON for bank-bot

Hints:

If you change your json config file but don't see any change in Swagger then hold down the Shift button and click the Reload button (because browsers cache some files, this will force it to update config file)

About