Skip to content
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
13 changes: 11 additions & 2 deletions samtranslator/swagger/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,10 @@ def set_path_default_authorizer(
# We want to ensure only a single Authorizer security entry exists while keeping everything else
for security in existing_security:
SwaggerEditor.validate_is_dict(
security, "{} in Security for path {} is not a valid dictionary.".format(security, path)
security,
"{} in Security for path {} method {} is not a valid dictionary.".format(
security, path, method_name
),
)
if authorizer_names.isdisjoint(security.keys()):
existing_non_authorizer_security.append(security)
Expand Down Expand Up @@ -703,7 +706,7 @@ def set_path_default_apikey_required(self, path):
:param string path: Path name
"""

for _, method_definition in self.iter_on_all_methods_for_path(path):
for method_name, method_definition in self.iter_on_all_methods_for_path(path):
existing_security = method_definition.get("security", [])
apikey_security_names = set(["api_key", "api_key_false"])
existing_non_apikey_security = []
Expand All @@ -714,6 +717,12 @@ def set_path_default_apikey_required(self, path):
# (e.g. sigv4 (AWS_IAM), authorizers, NONE (marker for ignoring default authorizer))
# We want to ensure only a single ApiKey security entry exists while keeping everything else
for security in existing_security:
SwaggerEditor.validate_is_dict(
security,
"{} in Security for path {} method {} is not a valid dictionary.".format(
security, path, method_name
),
)
if apikey_security_names.isdisjoint(security.keys()):
existing_non_apikey_security.append(security)
else:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
transformId: AWS::Serverless-2016-10-31
AWSTemplateFormatVersion: '2010-09-09'
Resources:
AuthFunction:
Type: AWS::Serverless::Function
AccessingPartyAPI:
Type: AWS::Serverless::Api
Properties:
EndpointConfiguration: REGIONAL
StageName: demo
Auth:
ApiKeyRequired: true

DefinitionBody:
paths:
"/path":
put:
responses:
'201':
content:
application/json:
schema:
"$ref": "abcd"
x-amazon-apigateway-integration:
contentHandling: CONVERT_TO_TEXT
responses:
default:
statusCode: '200'
uri:
Fn::Sub: foobar
httpMethod: POST
passthroughBehavior: when_no_match
type: aws_proxy
requestBody:
content:
application/json:
schema:
required:
- readoutId
- status
type: object
security:
- []

openapi: 3.0.3
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. CustomAuthorizer in Security for path /path is not a valid dictionary."
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. CustomAuthorizer in Security for path /path method put is not a valid dictionary."
}
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. [] in Security for path /path method put is not a valid dictionary."
}