This is an automated email from the ASF dual-hosted git repository.

vincbeck pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git


The following commit(s) were added to refs/heads/main by this push:
     new 79603f9302 Add swagger path to FAB Auth manager and Internal API 
(#37525)
79603f9302 is described below

commit 79603f9302b5344bc480a42ec31dee4be35fb1b8
Author: Andrey Anshin <andrey.ans...@taragol.is>
AuthorDate: Tue Feb 20 03:27:00 2024 +0400

    Add swagger path to FAB Auth manager and Internal API (#37525)
---
 .../providers/fab/auth_manager/fab_auth_manager.py |  5 ++--
 airflow/www/constants.py                           | 28 ++++++++++++++++++++++
 airflow/www/extensions/init_views.py               |  9 +++----
 3 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/airflow/providers/fab/auth_manager/fab_auth_manager.py 
b/airflow/providers/fab/auth_manager/fab_auth_manager.py
index d252b3860c..90109950b3 100644
--- a/airflow/providers/fab/auth_manager/fab_auth_manager.py
+++ b/airflow/providers/fab/auth_manager/fab_auth_manager.py
@@ -84,6 +84,7 @@ from airflow.security.permissions import (
 )
 from airflow.utils.session import NEW_SESSION, provide_session
 from airflow.utils.yaml import safe_load
+from airflow.www.constants import SWAGGER_BUNDLE, SWAGGER_ENABLED
 from airflow.www.extensions.init_views import 
_CustomErrorRequestBodyValidator, _LazyResolver
 
 if TYPE_CHECKING:
@@ -156,9 +157,7 @@ class FabAuthManager(BaseAuthManager):
             specification=specification,
             resolver=_LazyResolver(),
             base_path="/auth/fab/v1",
-            options={
-                "swagger_ui": conf.getboolean("webserver", 
"enable_swagger_ui", fallback=True),
-            },
+            options={"swagger_ui": SWAGGER_ENABLED, "swagger_path": 
SWAGGER_BUNDLE.__fspath__()},
             strict_validation=True,
             validate_responses=True,
             validator_map={"body": _CustomErrorRequestBodyValidator},
diff --git a/airflow/www/constants.py b/airflow/www/constants.py
new file mode 100644
index 0000000000..263caf1576
--- /dev/null
+++ b/airflow/www/constants.py
@@ -0,0 +1,28 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from __future__ import annotations
+
+from pathlib import Path
+
+from airflow.configuration import conf
+
+WWW = Path(__file__).resolve().parent
+# There is a difference with configuring Swagger in Connexion 2.x and 
Connexion 3.x
+# Connexion 2: 
https://connexion.readthedocs.io/en/2.14.2/quickstart.html#the-swagger-ui-console
+# Connexion 3: 
https://connexion.readthedocs.io/en/stable/swagger_ui.html#configuring-the-swagger-ui
+SWAGGER_ENABLED = conf.getboolean("webserver", "enable_swagger_ui", 
fallback=True)
+SWAGGER_BUNDLE = WWW.joinpath("static", "dist", "swagger-ui")
diff --git a/airflow/www/extensions/init_views.py 
b/airflow/www/extensions/init_views.py
index 92f2145764..01a726bd69 100644
--- a/airflow/www/extensions/init_views.py
+++ b/airflow/www/extensions/init_views.py
@@ -17,7 +17,6 @@
 from __future__ import annotations
 
 import logging
-import os
 import warnings
 from functools import cached_property
 from pathlib import Path
@@ -33,6 +32,7 @@ from airflow.configuration import conf
 from airflow.exceptions import RemovedInAirflow3Warning
 from airflow.security import permissions
 from airflow.utils.yaml import safe_load
+from airflow.www.constants import SWAGGER_BUNDLE, SWAGGER_ENABLED
 from airflow.www.extensions.init_auth_manager import get_auth_manager
 
 if TYPE_CHECKING:
@@ -273,10 +273,7 @@ def init_api_connexion(app: Flask) -> None:
         specification=specification,
         resolver=_LazyResolver(),
         base_path=base_path,
-        options={
-            "swagger_ui": conf.getboolean("webserver", "enable_swagger_ui", 
fallback=True),
-            "swagger_path": os.fspath(ROOT_APP_DIR.joinpath("www", "static", 
"dist", "swagger-ui")),
-        },
+        options={"swagger_ui": SWAGGER_ENABLED, "swagger_path": 
SWAGGER_BUNDLE.__fspath__()},
         strict_validation=True,
         validate_responses=True,
         validator_map={"body": _CustomErrorRequestBodyValidator},
@@ -298,7 +295,7 @@ def init_api_internal(app: Flask, standalone_api: bool = 
False) -> None:
     api_bp = FlaskApi(
         specification=specification,
         base_path="/internal_api/v1",
-        options={"swagger_ui": conf.getboolean("webserver", 
"enable_swagger_ui", fallback=True)},
+        options={"swagger_ui": SWAGGER_ENABLED, "swagger_path": 
SWAGGER_BUNDLE.__fspath__()},
         strict_validation=True,
         validate_responses=True,
     ).blueprint

Reply via email to