Created
May 29, 2020 13:08
-
-
Save remster85/53fe4c18872c3154445975777fd681ae to your computer and use it in GitHub Desktop.
Custom Swagger Flask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
from swagger_ui_bundle import swagger_ui_path | |
import json | |
from flask import Flask, Blueprint, send_from_directory, render_template | |
swagger_bp = Blueprint( | |
'swagger_ui', | |
__name__, | |
static_url_path='', | |
static_folder=swagger_ui_path, | |
template_folder=swagger_ui_path | |
) | |
app = Flask(__name__, static_url_path='') | |
SWAGGER_UI_CONFIG = { | |
"openapi_spec_url": "/docs" | |
} | |
@swagger_bp.route('/') | |
def swagger_ui_index(): | |
return render_template('index.j2', **SWAGGER_UI_CONFIG) | |
@app.route('/docs') | |
def swa(): | |
with open('customswagger.json') as json_file: | |
data = json.load(json_file) | |
return data | |
app.register_blueprint(swagger_bp, url_prefix='/ui') | |
if __name__ == "__main__": | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment