Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Raise correct exception when Fn::If value is not a list #2731

Merged
merged 1 commit into from
Dec 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion samtranslator/open_api/base_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ def get_conditional_contents(item: Any) -> List[Any]:
"""
contents = [item]
if isinstance(item, dict) and BaseEditor._CONDITIONAL_IF in item:
contents = item[BaseEditor._CONDITIONAL_IF][1:]
if_parameters = item[BaseEditor._CONDITIONAL_IF]
if not isinstance(if_parameters, list):
raise InvalidDocumentException(
[InvalidTemplateException(f"Value of {BaseEditor._CONDITIONAL_IF} must be a list.")]
)
contents = if_parameters[1:]
contents = [content for content in contents if not is_intrinsic_no_value(content)]
return contents

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
Resources:
MyAuthFn:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/hello.zip
Handler: index.handler
Runtime: nodejs12.x

MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: dev
Auth:
ApiKeyRequired: true
DefinitionBody:
swagger: '2.0'
info:
title: !Sub ${AWS::StackName}-Api
paths:
/post:
Fn::If:
This: should not be a dict
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Value of Fn::If must be a list."
}