python-restx / flask-restx

Fork of Flask-RESTPlus: Fully featured framework for fast, easy and documented API development with Flask
https://flask-restx.readthedocs.io/en/latest/
Other
2.14k stars 333 forks source link

Performance degrades on swagger after migrante from restplus #558

Open engFelipeMonteiro opened 1 year ago

engFelipeMonteiro commented 1 year ago

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

peter-doggart commented 1 year ago

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.

engFelipeMonteiro commented 1 year ago

How I determine the swagger-ui-dist version on a application?

peter-doggart commented 1 year ago

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"}}
engFelipeMonteiro commented 1 year ago

How I could upgrade or downgrade the swagger-ui-dist version?

peter-doggart commented 1 year ago

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.