diff --git a/samtranslator/model/eventsources/push.py b/samtranslator/model/eventsources/push.py index 751e0e40b9..93ed5592f2 100644 --- a/samtranslator/model/eventsources/push.py +++ b/samtranslator/model/eventsources/push.py @@ -1121,7 +1121,7 @@ def _get_permission(self, resources_to_link, stage): editor = OpenApiEditor(resources_to_link["explicit_api"].get("DefinitionBody")) except InvalidDocumentException as e: api_logical_id = self.ApiId.get("Ref") if isinstance(self.ApiId, dict) else self.ApiId - raise InvalidResourceException(api_logical_id, e) + raise InvalidResourceException(api_logical_id, " ".join(ex.message for ex in e.causes)) # If this is using the new $default path, keep path blank and add a * permission if path == OpenApiEditor._DEFAULT_PATH: diff --git a/samtranslator/open_api/open_api.py b/samtranslator/open_api/open_api.py index fa67499a9e..da6b7cdf06 100644 --- a/samtranslator/open_api/open_api.py +++ b/samtranslator/open_api/open_api.py @@ -41,8 +41,11 @@ def __init__(self, doc): """ if not OpenApiEditor.is_valid(doc): raise InvalidDocumentException( - "Invalid OpenApi document. " - "Invalid values or missing keys for 'openapi' or 'paths' in 'DefinitionBody'." + [ + InvalidTemplateException( + "Invalid OpenApi document. Invalid values or missing keys for 'openapi' or 'paths' in 'DefinitionBody'." + ) + ] ) self._doc = copy.deepcopy(doc) diff --git a/samtranslator/swagger/swagger.py b/samtranslator/swagger/swagger.py index 4c0ec3e341..28cf84a4fe 100644 --- a/samtranslator/swagger/swagger.py +++ b/samtranslator/swagger/swagger.py @@ -48,7 +48,7 @@ def __init__(self, doc): """ if not SwaggerEditor.is_valid(doc): - raise InvalidDocumentException("Invalid Swagger document") + raise InvalidDocumentException([InvalidTemplateException("Invalid Swagger document")]) self._doc = copy.deepcopy(doc) self.paths = self._doc["paths"] @@ -187,7 +187,11 @@ def add_lambda_integration( method = self._normalize_method_name(method) if self.has_integration(path, method): raise InvalidDocumentException( - "Lambda integration already exists on Path={}, Method={}".format(path, method) + [ + InvalidTemplateException( + "Lambda integration already exists on Path={}, Method={}".format(path, method) + ) + ] ) self.add_path(path, method) @@ -252,7 +256,9 @@ def add_state_machine_integration( method = self._normalize_method_name(method) if self.has_integration(path, method): - raise InvalidDocumentException("Integration already exists on Path={}, Method={}".format(path, method)) + raise InvalidDocumentException( + [InvalidTemplateException("Integration already exists on Path={}, Method={}".format(path, method))] + ) self.add_path(path, method) @@ -1029,7 +1035,9 @@ def _add_iam_resource_policy_for_method(self, policy_list, effect, resource_list return if effect not in ["Allow", "Deny"]: - raise InvalidDocumentException("Effect must be one of {}".format(["Allow", "Deny"])) + raise InvalidDocumentException( + [InvalidTemplateException("Effect must be one of {}".format(["Allow", "Deny"]))] + ) if not isinstance(policy_list, (dict, list)): raise InvalidDocumentException( @@ -1091,7 +1099,9 @@ def _add_ip_resource_policy_for_method(self, ip_list, conditional, resource_list ip_list = [ip_list] if conditional not in ["IpAddress", "NotIpAddress"]: - raise InvalidDocumentException("Conditional must be one of {}".format(["IpAddress", "NotIpAddress"])) + raise InvalidDocumentException( + [InvalidTemplateException("Conditional must be one of {}".format(["IpAddress", "NotIpAddress"]))] + ) self.resource_policy["Version"] = "2012-10-17" allow_statement = Py27Dict() @@ -1127,7 +1137,9 @@ def _add_vpc_resource_policy_for_method(self, endpoint_dict, conditional, resour """ if conditional not in ["StringNotEquals", "StringEquals"]: - raise InvalidDocumentException("Conditional must be one of {}".format(["StringNotEquals", "StringEquals"])) + raise InvalidDocumentException( + [InvalidTemplateException("Conditional must be one of {}".format(["StringNotEquals", "StringEquals"]))] + ) condition = Py27Dict() string_endpoint_list = endpoint_dict.get("StringEndpointList") diff --git a/tests/translator/output/error_http_api_invalid_openapi.json b/tests/translator/output/error_http_api_invalid_openapi.json index 05782e3c6f..990d3880ad 100644 --- a/tests/translator/output/error_http_api_invalid_openapi.json +++ b/tests/translator/output/error_http_api_invalid_openapi.json @@ -4,5 +4,5 @@ "errorMessage": "Resource with id [Api] is invalid. Invalid OpenApi document. Invalid values or missing keys for 'openapi' or 'paths' in 'DefinitionBody'." } ], - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Api] is invalid. Invalid OpenApi document. Invalid values or missing keys for 'openapi' or 'paths' in 'DefinitionBody'." + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [Api] is invalid. Structure of the SAM template is invalid. Invalid OpenApi document. Invalid values or missing keys for 'openapi' or 'paths' in 'DefinitionBody'." } \ No newline at end of file