flask-restx
flask-restx copied to clipboard
Allow disabling Swagger UI Syntax Highlighting
Is your feature request related to a problem? Please describe. The Swagger UI somewhat recently added syntax highlighting to the docs page for json responses. I believe this appeared with restx >= 0.3.0. It is nice in some cases. But for larger payloads this can really bog down the browser as it tries to decorate hundreds or thousands of json fields. Turning this off would avoid all that browser CPU thrashing.
Describe the solution you'd like Swagger has a few configuration options to enable or disable the syntax highlighting, documented here under 'Display': https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/
It would be nice to have a straightforward configuration option in flask-restx to configure this. Similar to some of the other options here: https://flask-restx.readthedocs.io/en/latest/swagger.html#customization
e.g.
app.config.SWAGGER_SYNTAX_HIGHLIGHT = False
Describe alternatives you've considered In this somewhat related request: https://github.com/python-restx/flask-restx/issues/300
There was discussion about using a yaml configuration file rather than hardcoding all these configuration options, but it didn't look like it went anywhere?
Additional context n/a
This is where the yaml file idea came from:
https://swagger.io/docs/open-source-tools/swagger-ui/usage/configuration/
I'll have to try and find the issue where I brought it up. I need to look at the customization, but I think it's mostly done inline with the HTML. If you can drop in a swagger-config.yaml
into the swagger directory of your project, it may act as the default for anything not getting passed in. It's worth trying
Hello @j5awry
I had a similar need and tried to use swagger-config.yaml
file. Unfortunately, it doesn't seem to be picked up.
Could you please advice what should be exact location of the file? You said "into swagger directory" while the doc says "the project root directory" - I followed the latter, which may be an issue...
Just for clarity, here is how my swagger-config.yaml
looks like:
---
syntaxHighlight: false
@j5awry This is something I'm running into as well - would be great for some way to expose that syntaxHighlight configuration. Having syntax highlighting on by default is causing lots of performance issues for me
@zbhuiyan There is no way built in to flask-restx
config to do this currently, but you can render a custom Swagger UI template and use it to set any custom options you want without too much work. See this comment for a bit of a how-to: https://github.com/python-restx/flask-restx/issues/430#issuecomment-1104052909