Skip to content
Closed
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
12 changes: 11 additions & 1 deletion samtranslator/swagger/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,17 @@ def set_path_default_authorizer(
if add_default_auth_to_preflight or normalized_method_name != "options":
normalized_method_name = self._normalize_method_name(method_name)
# It is possible that the method could have two definitions in a Fn::If block.
for method_definition in self.get_method_contents(self.get_path(path)[normalized_method_name]):
method_dict = self.get_path(path).get(normalized_method_name)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some additional questions which may have already been considered.

can normalized_method_name be anything other than a string?
can path be anything other than a string?

Could we have intrinsics which resolve each of them to a dict instead of a string?

if method_dict is None:
raise InvalidDocumentException(
[
InvalidTemplateException(
"Can't find method definition dictionary for method '{}'".format(normalized_method_name)
)
]
)

for method_definition in self.get_method_contents(method_dict):

# If no integration given, then we don't need to process this definition (could be AWS::NoValue)
if not isinstance(method_definition, dict):
Expand Down
44 changes: 44 additions & 0 deletions tests/translator/input/error_api_invalid_any_method.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
Resources:
HttpApiFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/todo_list.zip
Handler: index.restapi
Runtime: python3.7
Events:
SimpleCase:
Type: HttpApi
Properties:
ApiId: !Ref MyApi
BasePath:
Type: HttpApi
Properties:
ApiId: !Ref MyApi
Path: /
Method: get

MyApi:
Type: AWS::Serverless::Api
Properties:
StageName:
Ref: Stage
Auth:
DefaultAuthorizer: "LambdaAuthorizer"
Authorizers:
LambdaAuthorizer:
FunctionPayloadType: "REQUEST"
Identity:
Headers:
- "Authorization"
DefinitionBody:
openapi: '3.0'
info:
title: !Sub ${AWS::StackName}-Api
paths:
/:
any:
x-amazon-apigateway-integration:
httpMethod: ANY
type: http_proxy
uri: https://www.alphavantage.co/
payloadFormatVersion: '1.0'
3 changes: 3 additions & 0 deletions tests/translator/output/error_api_invalid_any_method.json
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. Can't find method definition dictionary for method 'x-amazon-apigateway-any-method'"
}
1 change: 1 addition & 0 deletions tests/translator/test_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,7 @@ def test_transform_success_no_side_effect(self, testcase, partition_with_region)
"error_api_gateway_responses_nonnumeric_status_code",
"error_api_gateway_responses_unknown_responseparameter",
"error_api_gateway_responses_unknown_responseparameter_property",
"error_api_invalid_any_method",
"error_api_invalid_auth",
"error_api_invalid_path",
"error_api_invalid_definitionuri",
Expand Down