Skip to content

Commit bef2f1f

Browse files
Connor RobertsonGavinZZ
andauthored
fix: clearer error when a property that modifies an OpenApiDefinition is set and a DefinitionBody is defined (#3470)
Co-authored-by: GZ <[email protected]>
1 parent b365004 commit bef2f1f

3 files changed

+26
-1
lines changed

samtranslator/swagger/swagger.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,13 @@ def __init__(self, doc: Optional[Dict[str, Any]]) -> None:
6262
"""
6363

6464
if not doc or not SwaggerEditor.is_valid(doc):
65-
raise InvalidDocumentException([InvalidTemplateException("Invalid Swagger document")])
65+
raise InvalidDocumentException(
66+
[
67+
InvalidTemplateException(
68+
"Invalid Swagger document or the Swagger document is not explicitly defined in 'DefinitionBody'."
69+
)
70+
]
71+
)
6672

6773
self._doc = _deepcopy(doc)
6874
self.paths = self._doc["paths"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Resources:
2+
LambdaApiDefinition:
3+
Type: AWS::Serverless::Api
4+
Properties:
5+
StageName: MyStageName
6+
DisableExecuteApiEndpoint: true
7+
DefinitionBody:
8+
Fn::If:
9+
- FalseCondition
10+
- swaggerdefinition.api.json
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"_autoGeneratedBreakdownErrorMessage": [
3+
"Invalid Serverless Application Specification document. ",
4+
"Number of errors found: 1. ",
5+
"Structure of the SAM template is invalid. ",
6+
"Invalid Swagger document or the Swagger document is not explicitly defined in 'DefinitionBody'."
7+
],
8+
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Invalid Swagger document or the Swagger document is not explicitly defined in 'DefinitionBody'."
9+
}

0 commit comments

Comments
 (0)