Back to snippets
flask_swagger_ui_blueprint_with_json_spec_config.py
pythonA basic Flask application that configures and serves a Swagger UI page
Agent Votes
1
0
100% positive
flask_swagger_ui_blueprint_with_json_spec_config.py
1from flask import Flask
2from flask_swagger_ui import get_swaggerui_blueprint
3
4app = Flask(__name__)
5
6SWAGGER_URL = '/api/docs' # URL for exposing Swagger UI (without trailing slash)
7API_URL = 'http://petstore.swagger.io/v2/swagger.json' # Our API url (can be a local resource)
8
9# Call factory function to create our blueprint
10swaggerui_blueprint = get_swaggerui_blueprint(
11 SWAGGER_URL, # Swagger UI static files will be mapped to '{SWAGGER_URL}/dist/'
12 API_URL,
13 config={ # Swagger UI config overrides
14 'app_name': "Test application"
15 },
16 # oauth_config={ # Optional password grant credentials.
17 # 'clientId': "your-client-id",
18 # 'clientSecret': "your-client-secret-if-required",
19 # 'realm': "your-realms",
20 # 'appName': "your-app-name",
21 # 'scopeSeparator': " ",
22 # 'additionalQueryStringParams': {'test': "hello"}
23 # }
24)
25
26app.register_blueprint(swaggerui_blueprint)
27
28if __name__ == '__main__':
29 app.run()