Skip to content

Instantly share code, notes, and snippets.

@remster85
Created May 29, 2020 13:08
Show Gist options
  • Save remster85/53fe4c18872c3154445975777fd681ae to your computer and use it in GitHub Desktop.
Save remster85/53fe4c18872c3154445975777fd681ae to your computer and use it in GitHub Desktop.
Custom Swagger Flask
#!/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