Skip to content

Commit

Permalink
Print URL of Swagger if it's in use.
Browse files Browse the repository at this point in the history
Also fixes an issue with not disabling the UI if the applicaiton is
configured not to use it.
  • Loading branch information
aholmes committed Sep 29, 2023
1 parent 45f1583 commit 393893e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/web/BL_Python/web/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Flask entry point.
"""
import logging
from logging import Logger
from os import environ, path
from typing import Any, Optional, cast

Expand All @@ -22,7 +22,7 @@
# from CAP.app.services.user.login_manager import LoginManager
# from CAP.database.models.CAP import Base
from connexion.apps.flask_app import FlaskApp
from flask import Flask
from flask import Flask, url_for
from injector import Module
from lib_programname import get_path_executed_script

Expand Down Expand Up @@ -115,6 +115,14 @@ def create_app(
flask_injector = configure_dependencies(app, application_modules=modules)
app.injector = flask_injector

if config.flask.openapi is not None and config.flask.openapi.use_swagger:
with app.app_context():
# use this logger so we can control where output is sent.
# the default logger retrieved here logs to the console.
app.injector.injector.get(Logger).info(
f"Swagger UI can be accessed at {url_for('/./_swagger_ui_index', _external=True)}"
)

return app


Expand Down Expand Up @@ -166,11 +174,7 @@ def configure_openapi(config: Config, name: Optional[str] = None):
# json_logging.config_root_logger()
app.logger.setLevel(environ.get("LOGLEVEL", "INFO").upper())

options: dict[str, bool] = {}
# TODO document that connexion[swagger-ui] must be installed
# for this to work
if config.flask.openapi.use_swagger:
options["swagger_ui"] = True
options: dict[str, bool] = {"swagger_ui": config.flask.openapi.use_swagger}

connexion_app.add_api(
f"{config.flask.app_name}/{config.flask.openapi.spec_path}",
Expand Down

0 comments on commit 393893e

Please sign in to comment.