Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/cloudformation_compatibility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ BinaryMediaTypes All
MinimumCompressionSize All
Cors All
TracingEnabled All
OpenApiVersion All
OpenApiVersion None
================================== ======================== ========================


Expand Down
5 changes: 2 additions & 3 deletions samtranslator/model/api/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
AuthProperties.__new__.__defaults__ = (None, None, None)

GatewayResponseProperties = ["ResponseParameters", "ResponseTemplates", "StatusCode"]
OpenApiVersionsSupportedRegex = r"\A[2-3](\.\d)(\.\d)?$"


class ApiGenerator(object):
Expand Down Expand Up @@ -98,9 +97,9 @@ def _construct_rest_api(self):
"Specify either 'DefinitionUri' or 'DefinitionBody' property and not both")

if self.open_api_version:
if re.match(OpenApiVersionsSupportedRegex, self.open_api_version) is None:
if re.match(SwaggerEditor.get_openapi_versions_supported_regex(), self.open_api_version) is None:
raise InvalidResourceException(
self.logical_id, "The OpenApiVersion value must be of the format 2.x.x or 3.x.x")
self.logical_id, "The OpenApiVersion value must be 3.0.0")

self._add_cors()
self._add_auth()
Expand Down
5 changes: 3 additions & 2 deletions samtranslator/plugins/globals/globals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from samtranslator.public.sdk.resource import SamResourceType
from samtranslator.public.intrinsics import is_intrinsics
from samtranslator.swagger.swagger import SwaggerEditor
import re


Expand All @@ -15,7 +16,6 @@ class Globals(object):
_OPENAPIVERSION = "OpenApiVersion"
_API_TYPE = "AWS::Serverless::Api"
_MANAGE_SWAGGER = "__MANAGE_SWAGGER"
_OPENAPIVERSION_REGEX = r"\A3(\.\d)(\.\d)?$"

supported_properties = {
# Everything on Serverless::Function except Role, Policies, FunctionName, Events
Expand Down Expand Up @@ -135,7 +135,8 @@ def fix_openapi_definitions(cls, template):
if ("Type" in resource) and (resource["Type"] == cls._API_TYPE):
properties = resource["Properties"]
if (cls._OPENAPIVERSION in properties) and (cls._MANAGE_SWAGGER in properties) and \
(re.match(cls._OPENAPIVERSION_REGEX, properties[cls._OPENAPIVERSION]) is not None):
(re.match(SwaggerEditor.get_openapi_version_3_regex(),
properties[cls._OPENAPIVERSION]) is not None):
if "DefinitionBody" in properties:
definition_body = properties['DefinitionBody']
definition_body['openapi'] = properties[cls._OPENAPIVERSION]
Expand Down
13 changes: 11 additions & 2 deletions samtranslator/swagger/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,13 +555,12 @@ def is_valid(data):
:param dict data: Data to be validated
:return: True, if data is a Swagger
"""
openapi_version_supported_regex = r"\A3(\.\d)(\.\d)?$"

if bool(data) and isinstance(data, dict) and isinstance(data.get('paths'), dict):
if bool(data.get("swagger")):
return True
elif bool(data.get("openapi")):
return re.search(openapi_version_supported_regex, data["openapi"]) is not None
return re.search(SwaggerEditor.get_openapi_version_3_regex(), data["openapi"]) is not None
return False
return False

Expand Down Expand Up @@ -601,3 +600,13 @@ def _normalize_method_name(method):
return SwaggerEditor._X_ANY_METHOD
else:
return method

@staticmethod
def get_openapi_versions_supported_regex():
openapi_version_supported_regex = r"\A[2-3](\.\d)(\.\d)?$"
return openapi_version_supported_regex

@staticmethod
def get_openapi_version_3_regex():
openapi_version_3_regex = r"\A3(\.\d)(\.\d)?$"
return openapi_version_3_regex
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"errors": [
{
"errorMessage": "Resource with id [MyApi] is invalid. The OpenApiVersion value must be of the format 2.x.x or 3.x.x"
"errorMessage": "Resource with id [MyApi] is invalid. The OpenApiVersion value must be 3.0.0"
}
],
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. The OpenApiVersion value must be of the format 2.x.x or 3.x.x"
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [MyApi] is invalid. The OpenApiVersion value must be 3.0.0"
}