Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Communications Backbone System
backbone-message-format
Commits
c69ad579
Verified
Commit
c69ad579
authored
6 months ago
by
Dan Jones
Browse files
Options
Download
Email Patches
Plain Diff
fix: get raw schema back from flasgger app
parent
55742586
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
1 deletion
+29
-1
generate_schema_config.py
generate_schema_config.py
+29
-1
No files found.
generate_schema_config.py
View file @
c69ad579
...
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment