|
3 | 3 | from dataclasses import dataclass
|
4 | 4 | from typing import Any, Dict, List, Optional, Set, Tuple, Union, cast
|
5 | 5 |
|
| 6 | +from samtranslator.feature_toggle.feature_toggle import FeatureToggle |
6 | 7 | from samtranslator.metrics.method_decorator import cw_timer
|
7 | 8 | from samtranslator.model import Resource
|
8 | 9 | from samtranslator.model.apigateway import (
|
|
40 | 41 |
|
41 | 42 | LOG = logging.getLogger(__name__)
|
42 | 43 |
|
| 44 | +FEATURE_FLAG_NORMALIZED_OPENAPI_VERSION = "normalized_open_api_version" |
| 45 | + |
43 | 46 | _CORS_WILDCARD = "'*'"
|
44 | 47 | CorsProperties = namedtuple(
|
45 | 48 | "CorsProperties", ["AllowMethods", "AllowHeaders", "AllowOrigin", "MaxAge", "AllowCredentials"]
|
@@ -205,6 +208,7 @@ def __init__( # noqa: PLR0913
|
205 | 208 | mode: Optional[Intrinsicable[str]] = None,
|
206 | 209 | api_key_source_type: Optional[Intrinsicable[str]] = None,
|
207 | 210 | always_deploy: Optional[bool] = False,
|
| 211 | + feature_toggle: Optional[FeatureToggle] = None, |
208 | 212 | ):
|
209 | 213 | """Constructs an API Generator class that generates API Gateway resources
|
210 | 214 |
|
@@ -261,6 +265,7 @@ def __init__( # noqa: PLR0913
|
261 | 265 | self.mode = mode
|
262 | 266 | self.api_key_source_type = api_key_source_type
|
263 | 267 | self.always_deploy = always_deploy
|
| 268 | + self.feature_toggle = feature_toggle |
264 | 269 |
|
265 | 270 | def _construct_rest_api(self) -> ApiGatewayRestApi:
|
266 | 271 | """Constructs and returns the ApiGateway RestApi.
|
@@ -1125,11 +1130,15 @@ def _openapi_postprocess(self, definition_body: Dict[str, Any]) -> Dict[str, Any
|
1125 | 1130 | if definition_body.get("swagger") is not None:
|
1126 | 1131 | return definition_body
|
1127 | 1132 |
|
1128 |
| - if definition_body.get("openapi") is not None and self.open_api_version is None: |
1129 |
| - self.open_api_version = definition_body.get("openapi") |
| 1133 | + if self.feature_toggle and self.feature_toggle.is_enabled(FEATURE_FLAG_NORMALIZED_OPENAPI_VERSION): |
| 1134 | + normalized_open_api_version = definition_body.get("openapi", self.open_api_version) |
| 1135 | + elif definition_body.get("openapi") is not None and self.open_api_version is None: |
| 1136 | + normalized_open_api_version = definition_body.get("openapi") |
| 1137 | + else: |
| 1138 | + normalized_open_api_version = self.open_api_version |
1130 | 1139 |
|
1131 |
| - if self.open_api_version and SwaggerEditor.safe_compare_regex_with_string( |
1132 |
| - SwaggerEditor._OPENAPI_VERSION_3_REGEX, self.open_api_version |
| 1140 | + if normalized_open_api_version and SwaggerEditor.safe_compare_regex_with_string( |
| 1141 | + SwaggerEditor._OPENAPI_VERSION_3_REGEX, normalized_open_api_version |
1133 | 1142 | ):
|
1134 | 1143 | if definition_body.get("securityDefinitions"):
|
1135 | 1144 | components = definition_body.get("components", Py27Dict())
|
|
0 commit comments