-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Flask restx is not compatible with StrictUndefined mode of jinja #565
Labels
bug
Something isn't working
Comments
sloschert
changed the title
Swagger docs crash when running Flask with "StrictUndefined" jinja environment
Flask restx is not compatible with StrictUndefined mode of jinja
Jan 30, 2024
sloschert
added a commit
to sloschert/flask-restx
that referenced
this issue
Jan 30, 2024
* Add jinja test for potentially undefined variable in `swagger-ui.html`. Compatibility with jinja's StrictUndefined mode. * Add CHANGELOG.rst entry
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Repro Steps (if applicable)
/api/v1/doc/
Expected Behavior
The docs page should load even with Flask's jinja enviroment being "StrictUndefined".
Actual Behavior
The app crashes.
Error Messages/Stack Trace
Environment
Additional Context
The template
swagger-ui.html
contains in two places the following problematic jinja expression:{% if config.SWAGGER_UI_OAUTH_CLIENT_ID -%}
It is problematic because it makes the docs page crash if the config variable
SWAGGER_UI_OAUTH_CLIENT_ID
is undefined and flask jinja environment is running in StrictUndefined mode (app.jinja_env.undefined = StrictUndefined
).There is no place in the flask restx documentation that specifies that the config variable has to be set or that StrictUndefined mode cannot be used.
The expression should be replaced with:
{% if config.SWAGGER_UI_OAUTH_CLIENT_ID is defined and config.SWAGGER_UI_OAUTH_CLIENT_ID -%}
This should fix the bug.
The text was updated successfully, but these errors were encountered: