Skip to content

Commit

Permalink
expose swagger-ui index template variables to app configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
msladecek authored and RobbeSneyders committed Jul 6, 2021
1 parent 1a7d089 commit 41c937b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
3 changes: 2 additions & 1 deletion connexion/apis/aiohttp_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ async def redirect(request):
async def _get_swagger_ui_home(self, req):
base_path = self._base_path_for_prefix(req)
template_variables = {
'openapi_spec_url': (base_path + self.options.openapi_spec_path)
'openapi_spec_url': (base_path + self.options.openapi_spec_path),
**self.options.openapi_console_ui_index_template_variables,
}
if self.options.openapi_console_ui_config is not None:
template_variables['configUrl'] = 'swagger-ui-config.json'
Expand Down
3 changes: 2 additions & 1 deletion connexion/apis/flask_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ def console_ui_home(self):
prefix=escaped
)
template_variables = {
'openapi_spec_url': flask.url_for(openapi_json_route_name)
'openapi_spec_url': flask.url_for(openapi_json_route_name),
**self.options.openapi_console_ui_index_template_variables,
}
if self.options.openapi_console_ui_config is not None:
template_variables['configUrl'] = 'swagger-ui-config.json'
Expand Down
10 changes: 10 additions & 0 deletions connexion/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,16 @@ def openapi_console_ui_config(self):
"""
return self._options.get('swagger_ui_config', None)

@property
def openapi_console_ui_index_template_variables(self):
# type: () -> dict
"""
Custom variables passed to the OpenAPI Console UI template.
Default: {}
"""
return self._options.get('swagger_ui_template_arguments', {})

@property
def uri_parser_class(self):
# type: () -> AbstractURIParser
Expand Down

0 comments on commit 41c937b

Please sign in to comment.