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

fix: get raw schema back from flasgger app

parent 55742586
......@@ -120,11 +120,39 @@ def serve():
app.run(debug=False, host=FLASK_HOST, port=FLASK_PORT)
def compile_schema(swagger_config):
"""Extract the output schema from flasgger
The only way I have found to do this is to
use a test client to make the GET request
for the page
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)
route = swagger_config['specs'][0]['route']
client = app.test_client()
response = client.get(route)
spec = response.json
# 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
del spec['definitions']
return spec
def write_schema(swagger_config, file_path):
"""
Dump schema to specified file
"""
json_schema = json.dumps(swagger_config, indent=2)
spec = compile_schema(swagger_config)
json_schema = json.dumps(spec, indent=2)
with open(file_path, "w") as f:
f.write(json_schema)
......
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