Verified Commit b2177519 authored by Dan Jones's avatar Dan Jones
Browse files

fix: define the flask app once

parent c6addbf6
......@@ -110,20 +110,8 @@ swagger_config = {
},
}
def serve():
"""
Run as local flask app on port 5000
"""
# Replace schema route to remove invalid
# definitions: {}
# Should be fixed if Flassger 0.9.7 is released
#
# The last release of flasgger was Aug 2020
# This bug was fixed in Nov 2021
# There is a pre-release from May 2023
# Until the fix gets released we have to
# remove the invalid definitions object
# from the spec
def configure_flask(swagger_config):
app = Flask(__name__)
Swagger(app, config=swagger_config, merge=True)
......@@ -137,6 +125,24 @@ def serve():
response.data = json.dumps(data)
return response
return app
def serve(swagger_config):
"""
Run as local flask app on port 5000
"""
# Replace schema route to remove invalid
# definitions: {}
# Should be fixed if Flassger 0.9.7 is released
#
# The last release of flasgger was Aug 2020
# This bug was fixed in Nov 2021
# There is a pre-release from May 2023
# Until the fix gets released we have to
# remove the invalid definitions object
# from the spec
app = configure_flask(swagger_config)
app.run(debug=True, host=FLASK_HOST, port=FLASK_PORT)
......@@ -150,8 +156,7 @@ def compile_schema(swagger_config):
The function that returns the definition
can't be called outside the flask app context
"""
app = Flask(__name__)
Swagger(app, config=swagger_config, merge=True)
app = configure_flask(swagger_config)
route = swagger_config['specs'][0]['route']
client = app.test_client()
response = client.get(route)
......@@ -196,4 +201,4 @@ if __name__ == "__main__":
# Run flask app
if config.get("run_flask"):
serve()
serve(swagger_config)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment