Skip to content

Commit

Permalink
Render correct template in API (#1404)
Browse files Browse the repository at this point in the history
* Explicitly render templates of correct blueprint

* Remove unused constant
  • Loading branch information
RobbeSneyders authored Jul 24, 2021
1 parent 803cf63 commit 2229831
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 8 additions & 1 deletion connexion/apis/flask_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""

import logging
import pathlib
import warnings
from typing import Any

Expand Down Expand Up @@ -296,7 +297,13 @@ def console_ui_home(self):
}
if self.options.openapi_console_ui_config is not None:
template_variables['configUrl'] = 'swagger-ui-config.json'
return flask.render_template('index.j2', **template_variables)

# Use `render_template_string` instead of `render_template` to circumvent the flask
# template lookup mechanism and explicitly render the template of the current blueprint.
# https://github.com/zalando/connexion/issues/1289#issuecomment-884105076
template_dir = pathlib.Path(self.options.openapi_console_ui_from_dir)
index_path = template_dir / 'index.j2'
return flask.render_template_string(index_path.read_text(), **template_variables)

def console_ui_static_files(self, filename):
"""
Expand Down
2 changes: 0 additions & 2 deletions connexion/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

import logging
import pathlib
from typing import Optional # NOQA

try:
Expand All @@ -13,7 +12,6 @@

from connexion.decorators.uri_parsing import AbstractURIParser

MODULE_PATH = pathlib.Path(__file__).absolute().parent
NO_UI_MSG = """The swagger_ui directory could not be found.
Please install connexion with extra install: pip install connexion[swagger-ui]
or provide the path to your local installation by passing swagger_path=<your path>
Expand Down

0 comments on commit 2229831

Please sign in to comment.