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 "ResponseParameters" is not dict #2725

Merged
merged 1 commit into from
Dec 14, 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
8 changes: 6 additions & 2 deletions samtranslator/model/apigateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,12 @@ def _add_prefixes(self, response_parameters): # type: ignore[no-untyped-def]
prefixed_parameters = Py27Dict()

parameter_prefix_pairs = [("Headers", "header."), ("Paths", "path."), ("QueryStrings", "querystring.")]
for parameter, prefix in parameter_prefix_pairs:
for key, value in response_parameters.get(parameter, {}).items():
for parameter_property_name, prefix in parameter_prefix_pairs:
parameter_property_value = response_parameters.get(parameter_property_name, {})
sam_expect(
parameter_property_value, self.api_logical_id, f"ResponseParameters.{parameter_property_name}"
).to_be_a_map()
for key, value in parameter_property_value.items():
param_key = GATEWAY_RESPONSE_PREFIX + prefix + key
if isinstance(key, Py27UniStr):
# if key is from template, we need to convert param_key to Py27UniStr
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
Resources:
Function:
Type: AWS::Serverless::Function
Properties:
CodeUri: s3://sam-demo-bucket/member_portal.zip
Handler: index.gethtml
Runtime: nodejs12.x
Events:
GetHtml:
Type: Api
Properties:
Path: /
Method: get
RestApiId: !Ref ExplicitApi

ExplicitApi:
Type: AWS::Serverless::Api
Properties:
StageName: Prod
GatewayResponses:
UNAUTHORIZED:
StatusCode: 401
ResponseParameters:
- ResponseParameters should not be a list
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. Resource with id [ExplicitApi] is invalid. Property 'GatewayResponses.UNAUTHORIZED.ResponseParameters' should be a map."
}