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
11 changes: 11 additions & 0 deletions samtranslator/open_api/open_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,17 @@ def add_tags(self, tags):
:param dict tags: dictionary of tagName:tagValue pairs.
"""
for name, value in tags.items():
# verify the tags definition is in the right format
if not isinstance(self.tags, list):
raise InvalidDocumentException(
[
InvalidTemplateException(
"Tags in OpenApi DefinitionBody needs to be a list. {} is a {} not a list.".format(
self.tags, type(self.tags).__name__
)
)
]
)
# find an existing tag with this name if it exists
existing_tag = next((existing_tag for existing_tag in self.tags if existing_tag.get("name") == name), None)
if existing_tag:
Expand Down
71 changes: 71 additions & 0 deletions tests/translator/input/error_http_api_invalid_tags_format.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
Conditions:
condition:
Fn::Equals:
- true
- true
Resources:
HttpApiFunction:
Condition: condition
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
MyApi:
Type: AWS::Serverless::HttpApi
Properties:
DefinitionBody:
info:
version: '1.0'
title:
Ref: AWS::StackName
paths:
"/basic":
post:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri:
Fn::Sub: arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations
payloadFormatVersion: '1.0'
security:
- OpenIdAuth:
- scope3
responses: {}
get:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri:
Fn::Sub: arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${DifferentFunction.Arn}/invocations
payloadFormatVersion: '1.0'
responses: {}
openapi: 3.0.1
tags:
name: tag1
components:
securitySchemes:
oauth2Auth:
type: oauth2
x-amazon-apigateway-authorizer:
identitySource: "$request.querystring.param"
type: jwt
jwtConfiguration:
audience:
- MyApi
issuer: https://www.example.com/v1/connect/oidc
OpenIdAuth:
type: openIdConnect
x-amazon-apigateway-authorizer:
identitySource: "$request.querystring.param"
type: jwt
jwtConfiguration:
audience:
- MyApi
issuer: https://www.example.com/v1/connect/oidc
openIdConnectUrl: https://www.example.com/v1/connect
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Structure of the SAM template is invalid. Tags in OpenApi DefinitionBody needs to be a list. {'name': 'tag1'} is a dict not a list.",
"errors": [
{
"errorMessage": "Structure of the SAM template is invalid. Tags in OpenApi DefinitionBody needs to be a list. {'name': 'tag1'} is a dict not a list."
}
]
}