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

jedcunningham pushed a commit to branch v2-5-test
in repository https://gitbox.apache.org/repos/asf/airflow.git

commit 3a7ab400e5debc7697743bfc8f803742b23b6008
Author: Tzu-ping Chung <[email protected]>
AuthorDate: Tue Feb 21 16:38:55 2023 +0800

    Avoid unneeded Connexion constructs (#29631)
    
    (cherry picked from commit 1edaddbb1cec740db2ff2a86fb23a3a676728cb0)
---
 airflow/www/extensions/init_views.py | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/airflow/www/extensions/init_views.py 
b/airflow/www/extensions/init_views.py
index 7db06a06c1..e0636a4326 100644
--- a/airflow/www/extensions/init_views.py
+++ b/airflow/www/extensions/init_views.py
@@ -20,13 +20,14 @@ import logging
 import warnings
 from os import path
 
-from connexion import App, ProblemException
+from connexion import FlaskApi, ProblemException
 from flask import Flask, request
 
 from airflow.api_connexion.exceptions import common_error_handler
 from airflow.configuration import conf
 from airflow.exceptions import RemovedInAirflow3Warning
 from airflow.security import permissions
+from airflow.utils.yaml import safe_load
 
 log = logging.getLogger(__name__)
 
@@ -207,20 +208,21 @@ def init_api_connexion(app: Flask) -> None:
         else:
             return views.method_not_allowed(ex)
 
-    spec_dir = path.join(ROOT_APP_DIR, "api_connexion", "openapi")
-    swagger_ui_dir = path.join(ROOT_APP_DIR, "www", "static", "dist", 
"swagger-ui")
-    options = {
-        "swagger_ui": conf.getboolean("webserver", "enable_swagger_ui", 
fallback=True),
-        "swagger_path": swagger_ui_dir,
-    }
-    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
+    with open(path.join(ROOT_APP_DIR, "api_connexion", "openapi", "v1.yaml")) 
as f:
+        specification = safe_load(f)
+    api_bp = FlaskApi(
+        specification=specification,
+        base_path=base_path,
+        options={
+            "swagger_ui": conf.getboolean("webserver", "enable_swagger_ui", 
fallback=True),
+            "swagger_path": path.join(ROOT_APP_DIR, "www", "static", "dist", 
"swagger-ui"),
+        },
+        strict_validation=True,
+        validate_responses=True,
     ).blueprint
-    # Like "api_bp.after_request", but the BP is already registered, so we have
-    # to register it in the app directly.
-    app.after_request_funcs.setdefault(api_bp.name, 
[]).append(set_cors_headers_on_response)
+    api_bp.after_request(set_cors_headers_on_response)
+
+    app.register_blueprint(api_bp)
     app.register_error_handler(ProblemException, common_error_handler)
     app.extensions["csrf"].exempt(api_bp)
 

Reply via email to