diff --git a/airflow/config_templates/config.yml b/airflow/config_templates/config.yml index 21d787cb56840..9005a54885263 100644 --- a/airflow/config_templates/config.yml +++ b/airflow/config_templates/config.yml @@ -1513,6 +1513,13 @@ type: string example: "dagrun_cleared,failed" default: ~ + - name: enable_swagger_ui + description: | + Boolean for running SwaggerUI in the webserver. + version_added: 2.6.0 + type: boolean + example: ~ + default: "True" - name: run_internal_api description: | Boolean for running Internal API in the webserver. diff --git a/airflow/config_templates/default_airflow.cfg b/airflow/config_templates/default_airflow.cfg index a3aff78e952e3..4bd2883563f11 100644 --- a/airflow/config_templates/default_airflow.cfg +++ b/airflow/config_templates/default_airflow.cfg @@ -771,6 +771,9 @@ audit_view_excluded_events = gantt,landing_times,tries,duration,calendar,graph,g # Example: audit_view_included_events = dagrun_cleared,failed # audit_view_included_events = +# Boolean for running SwaggerUI in the webserver. +enable_swagger_ui = True + # Boolean for running Internal API in the webserver. run_internal_api = False diff --git a/airflow/www/extensions/init_appbuilder_links.py b/airflow/www/extensions/init_appbuilder_links.py index 619d302fb322b..67bd1f6bb411c 100644 --- a/airflow/www/extensions/init_appbuilder_links.py +++ b/airflow/www/extensions/init_appbuilder_links.py @@ -16,6 +16,7 @@ # under the License. from __future__ import annotations +from airflow.configuration import conf from airflow.utils.docs import get_docs_url @@ -36,12 +37,14 @@ def init_appbuilder_links(app): appbuilder.add_link( name="Documentation", label="GitHub Repo", href="https://github.com/apache/airflow", category="Docs" ) - appbuilder.add_link( - name="Documentation", - label="REST API Reference (Swagger UI)", - href="/api/v1./api/v1_swagger_ui_index", - category="Docs", - ) + + if conf.getboolean("webserver", "enable_swagger_ui", fallback=True): + appbuilder.add_link( + name="Documentation", + label="REST API Reference (Swagger UI)", + href="/api/v1./api/v1_swagger_ui_index", + category="Docs", + ) appbuilder.add_link( name="Documentation", label="REST API Reference (Redoc)", href="RedocView.redoc", category="Docs" ) diff --git a/airflow/www/extensions/init_views.py b/airflow/www/extensions/init_views.py index 86f94d2f229ce..ca4ef6cd5ec62 100644 --- a/airflow/www/extensions/init_views.py +++ b/airflow/www/extensions/init_views.py @@ -208,7 +208,8 @@ def _handle_method_not_allowed(ex): return views.method_not_allowed(ex) spec_dir = path.join(ROOT_APP_DIR, "api_connexion", "openapi") - connexion_app = App(__name__, specification_dir=spec_dir, skip_error_handlers=True) + options = {"swagger_ui": conf.getboolean("webserver", "enable_swagger_ui", fallback=True)} + connexion_app = App(__name__, specification_dir=spec_dir, skip_error_handlers=True, options=options) connexion_app.app = app api_bp = connexion_app.add_api( specification="v1.yaml", base_path=base_path, validate_responses=True, strict_validation=True @@ -227,7 +228,8 @@ def init_api_internal(app: Flask) -> None: base_path = "/internal_api/v1" spec_dir = path.join(ROOT_APP_DIR, "api_internal", "openapi") - internal_app = App(__name__, specification_dir=spec_dir, skip_error_handlers=True) + options = {"swagger_ui": conf.getboolean("webserver", "enable_swagger_ui", fallback=True)} + internal_app = App(__name__, specification_dir=spec_dir, skip_error_handlers=True, options=options) internal_app.app = app api_bp = internal_app.add_api( specification="internal_api_v1.yaml",