flask-restx
flask-restx copied to clipboard
Performance degrades on swagger after migrante from restplus
We have a backend service that is developed with restplus, it's works without a problem. After migrated for restx we observed that some endpoints, that have big responses (>3MB) makes the tab of browser crash, and the browser suggests to interrupt We are using restx version 1.1.0.
The response using curl work perfectly
The browser part of flask-restx
is provided externally by npm swagger-ui-dist
and not by anything inside flask-restx
which purely generates the swagger.json
file for the API.
I suspect that given restplus is old, it is using a much earlier version of swagger-ui-dist
hence the difference. We had to move to a newer version of that package to deal with some security vulnerabilities.
If you are rendering extremely long responses, you might want to render a custom template with syntax highlighting disabled (see https://github.com/swagger-api/swagger-ui/issues/3832 and https://github.com/python-restx/flask-restx/issues/430#issuecomment-1104052909) or consider paginating your output.
How I determine the swagger-ui-dist version on a application?
See https://swagger.io/docs/open-source-tools/swagger-ui/usage/version-detection/
If you are using firefox, press Ctrl+Shift+K whilst viewing your swagger docs, then enter JSON.stringify(versions)
on the console. It should echo something like:
{"swaggerUi":{"version":"3.52.0","gitRevision":"gee40b00","gitDirty":true,"buildTimestamp":"Mon, 09 Aug 2021 15:13:17 GMT","machine":"ip-172-31-21-173"}}
How I could upgrade or downgrade the swagger-ui-dist version?
The swagger-ui-dist
files are bundled inside the flask-restx
version that is published on PyPi. The target version of swagger-ui-dist
is detailed in the top level packages.json
and installed during build by an invoke task using npm
to flask_restx/static
. If you download the source distribution from PyPi, you will see the extra files.
Because swagger-ui-dist
is designed to be standalone, you just need to replace the files in flask_restx/static
with the version you want. I would suggest you follow the instructions in CONTRIBUTING.rst to clone the project, update the packages.json
file and then run inv assets
which will fetch the files required.