RobbeSneyders commented on code in PR #36052:
URL: https://github.com/apache/airflow/pull/36052#discussion_r1414534535
##########
airflow/www/extensions/init_views.py:
##########
@@ -220,7 +224,7 @@ def resolve(self, operation):
return _LazyResolution(self.resolve_function_from_operation_id,
operation_id)
-class _CustomErrorRequestBodyValidator(RequestBodyValidator):
+class _CustomErrorRequestBodyValidator(AbstractRequestBodyValidator):
Review Comment:
This behavior was contributed to Connexion upstream and is included in
Connexion 3. A custom validator is no longer needed.
##########
airflow/auth/managers/fab/fab_auth_manager.py:
##########
@@ -147,20 +149,22 @@ def get_cli_commands() -> list[CLICommand]:
SYNC_PERM_COMMAND, # not in a command group
]
- def get_api_endpoints(self) -> None | FlaskApi:
+ def get_api_endpoints(self) -> None | FlaskApp:
Review Comment:
This function should not return a `FlaskApp`.
There are two ways to change this so it will work with Connexion 3:
- Pass in a `FlaskApp` and call `add_api` on it in this function
- Return an the arguments for the `add_api` call from this function. They
could be packaged in a class [like this
one](https://github.com/spec-first/connexion/blob/0082d7ad331bde3ad3e598a1fb3d222932edd549/connexion/middleware/main.py#L172).
##########
airflow/www/extensions/init_views.py:
##########
@@ -267,24 +271,30 @@ def init_api_connexion(app: Flask) -> None:
base_path = "/api/v1"
base_paths.append(base_path)
- with ROOT_APP_DIR.joinpath("api_connexion", "openapi", "v1.yaml").open()
as f:
- specification = safe_load(f)
Review Comment:
The specification was preloaded for some speedup in application startup (see
#29631)
##########
setup.cfg:
##########
@@ -85,7 +85,7 @@ install_requires =
# The usage was added in #30596, seemingly only to override and improve
the default error message.
# Either revert that change or find another way, preferably without using
connexion internals.
# This limit can be removed after
https://github.com/apache/airflow/issues/35234 is fixed
- connexion[flask]>=2.10.0,<3.0
+ connexion[flask]>=2.10.0
Review Comment:
I would recommend bumping to 3.0 directly since it would probably be hard to
write code that is completely compatible with both 2.X and 3.0.
##########
airflow/www/extensions/init_views.py:
##########
@@ -267,24 +271,30 @@ def init_api_connexion(app: Flask) -> None:
base_path = "/api/v1"
base_paths.append(base_path)
- with ROOT_APP_DIR.joinpath("api_connexion", "openapi", "v1.yaml").open()
as f:
- specification = safe_load(f)
- api_bp = FlaskApi(
+
+ specification=ROOT_APP_DIR.joinpath("api_connexion", "openapi", "v1.yaml")
+ connexion_app = FlaskApp(
+ import_name=__name__,
+ specification_dir=specification,
+ strict_validation=True,
+ validate_responses=True,
+ resolver=Resolver(),
+ swagger_ui_options=SwaggerUIOptions(
+ swagger_ui=conf.getboolean("webserver", "enable_swagger_ui",
fallback=True),
+ swagger_ui_path=os.fspath(ROOT_APP_DIR.joinpath("www", "static",
"dist", "swagger-ui")),
+ ),
+ )
+ connexion_app.app = app
+ connexion_app.add_api(
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")),
- },
- strict_validation=True,
+ resolver=Resolver(),
validate_responses=True,
- validator_map={"body": _CustomErrorRequestBodyValidator},
- ).blueprint
- api_bp.after_request(set_cors_headers_on_response)
-
- app.register_blueprint(api_bp)
- app.extensions["csrf"].exempt(api_bp)
+ strict_validation=True,
+ )
+ app.after_request_funcs.setdefault(base_path,
[]).append(set_cors_headers_on_response)
+ app.register_error_handler(ProblemException, common_error_handler)
+ app.extensions["csrf"].exempt(base_path)
def init_api_internal(app: Flask, standalone_api: bool = False) -> None:
Review Comment:
Same here, either the Connexion `FlaskApp` needs to be passed in and
`add_api` called, or the `add_api` arguments need to be returned.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]