From 1d283d7ba8b4bfc3c572eae7523963e4ab03c107 Mon Sep 17 00:00:00 2001 From: Giacomo Marciani Date: Wed, 27 Nov 2024 13:25:12 +0100 Subject: [PATCH] [UNSTABLE] [Dependencies] Apply changes required by the upgrade of Connexion to version 3.1.x. Signed-off-by: Giacomo Marciani --- cli/requirements.txt | 2 +- cli/setup.py | 2 +- cli/src/pcluster/api/encoder.py | 7 ++++--- cli/src/pcluster/api/flask_app.py | 4 ++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cli/requirements.txt b/cli/requirements.txt index 10cf42c1b5..b0f5ac3fc4 100644 --- a/cli/requirements.txt +++ b/cli/requirements.txt @@ -16,7 +16,7 @@ aws-cdk.core~=1.164 aws_cdk.aws-cloudwatch~=1.164 aws_cdk.aws-lambda~=1.164 boto3>=1.16.14 -connexion~=3.1 +connexion[flask]~=3.1.0 flask>=2.2.5,<2.3 jinja2~=3.0 jmespath~=0.10 diff --git a/cli/setup.py b/cli/setup.py index 0ce8f280e1..08b7a8c4bb 100644 --- a/cli/setup.py +++ b/cli/setup.py @@ -47,7 +47,7 @@ def readme(): "aws-cdk.aws-sqs~=" + CDK_VERSION, "aws-cdk.aws-cloudformation~=" + CDK_VERSION, "werkzeug==3.1.3", - "connexion~=3.1", + "connexion[flask]~=3.1.0", "flask>=2.2.5,<2.3", "jmespath~=0.10", "jsii==1.85.0", diff --git a/cli/src/pcluster/api/encoder.py b/cli/src/pcluster/api/encoder.py index 750d3d0a28..44f45a05d2 100644 --- a/cli/src/pcluster/api/encoder.py +++ b/cli/src/pcluster/api/encoder.py @@ -11,13 +11,13 @@ import datetime import six -from connexion.apps.flask_app import FlaskJSONEncoder +from connexion.apps.flask import Jsonifier from pcluster.api.models.base_model_ import Model from pcluster.utils import to_iso_timestr -class JSONEncoder(FlaskJSONEncoder): +class JSONEncoder(Jsonifier): """Make the model objects JSON serializable.""" include_nulls = False @@ -34,5 +34,6 @@ def default(self, obj): # pylint: disable=arguments-renamed dikt[attr] = value return dikt elif isinstance(obj, datetime.date): + # FIXME Expected type 'datetime', got 'date' instead. This issue exists before the upgrade from Connexion 2 to Connexion 3 return to_iso_timestr(obj) - return FlaskJSONEncoder.default(self, obj) + return Jsonifier.default(self, obj) diff --git a/cli/src/pcluster/api/flask_app.py b/cli/src/pcluster/api/flask_app.py index 0c1e23cca4..dfb3f188d1 100644 --- a/cli/src/pcluster/api/flask_app.py +++ b/cli/src/pcluster/api/flask_app.py @@ -10,7 +10,7 @@ import connexion from connexion import ProblemException -from connexion.decorators.validation import ParameterValidator +from connexion.validators.parameter import ParameterValidator from flask import Response, jsonify, request from werkzeug.exceptions import HTTPException @@ -74,7 +74,7 @@ def __init__(self, swagger_ui: bool = False, validate_responses=False): assert_valid_node_js() options = {"swagger_ui": swagger_ui} - self.app = connexion.FlaskApp(__name__, specification_dir="openapi/", skip_error_handlers=True) + self.app = connexion.FlaskApp(__name__, specification_dir="openapi/") self.flask_app = self.app.app self.flask_app.json_encoder = encoder.JSONEncoder self.app.add_api(