Skip to content

Commit

Permalink
handle missing swagger config
Browse files Browse the repository at this point in the history
  • Loading branch information
dchhabda committed Feb 29, 2024
1 parent 4302b11 commit 1a3be8d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions pybossa/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1014,12 +1014,16 @@ def setup_http_signer(app):


def setup_swagger(app):
swagger_path = app.config.get('SWAGGER_HEADER_PATH')
if not swagger_path:
return

try:
with open(app.config.get('SWAGGER_HEADER_PATH'), 'r') as file:
with open(swagger_path, 'r') as file:
html_as_string = file.read()
app.config.get('SWAGGER_TEMPLATE')['head_text'] = html_as_string
except (FileNotFoundError, TypeError):
msg = "WARNING: Swagger custom header file not found."
except (FileNotFoundError, TypeError) as ex:
msg = f"WARNING: Swagger custom header file not found. {ex}"
app.logger.warning(msg)
Swagger.DEFAULT_CONFIG.update(app.config.get('SWAGGER_TEMPLATE'))
Swagger(app, template=app.config.get('SWAGGER_TEMPLATE'))

0 comments on commit 1a3be8d

Please sign in to comment.