diff --git a/samtranslator/open_api/open_api.py b/samtranslator/open_api/open_api.py index 46f685865..14ab3dcac 100644 --- a/samtranslator/open_api/open_api.py +++ b/samtranslator/open_api/open_api.py @@ -90,10 +90,12 @@ def get_integration_function_logical_id(self, path_name, method_name): # Extract the integration uri out of a conditional if necessary uri = integration.get("uri") + if not isinstance(uri, dict): + return "" if self._CONDITIONAL_IF in uri: arn = uri[self._CONDITIONAL_IF][1].get("Fn::Sub") else: - arn = uri.get("Fn::Sub") + arn = uri.get("Fn::Sub", "") # Extract lambda integration (${LambdaName.Arn}) and split ".Arn" off from it regex = "([A-Za-z0-9]+\.Arn)" diff --git a/tests/translator/input/explicit_http_api.yaml b/tests/translator/input/explicit_http_api.yaml index afab76416..d07bc65de 100644 --- a/tests/translator/input/explicit_http_api.yaml +++ b/tests/translator/input/explicit_http_api.yaml @@ -10,10 +10,12 @@ Resources: Type: HttpApi Properties: ApiId: !Ref MyApi - SimpleCase2: + BasePath: Type: HttpApi Properties: ApiId: !Ref MyApi2 + Path: / + Method: get MyApi: Type: AWS::Serverless::HttpApi Properties: @@ -40,4 +42,20 @@ Resources: audience: - MyApi IdentitySource: "$request.querystring.param" - DefaultAuthorizer: OAuth2 \ No newline at end of file + DefaultAuthorizer: OAuth2 + DefinitionBody: + openapi: '3.0' + info: + title: !Sub ${AWS::StackName}-Apiv2 + paths: + /: + get: + responses: {} + $default: + x-amazon-apigateway-any-method: + isDefaultRoute: true + x-amazon-apigateway-integration: + httpMethod: ANY + type: http_proxy + uri: https://www.alphavantage.co/ + payloadFormatVersion: '1.0' \ No newline at end of file diff --git a/tests/translator/output/aws-cn/explicit_http_api.json b/tests/translator/output/aws-cn/explicit_http_api.json index 3672f8b18..2d1e8cec9 100644 --- a/tests/translator/output/aws-cn/explicit_http_api.json +++ b/tests/translator/output/aws-cn/explicit_http_api.json @@ -75,14 +75,29 @@ "Properties": { "Body": { "info": { - "version": "1.0", "title": { - "Ref": "AWS::StackName" + "Fn::Sub": "${AWS::StackName}-Apiv2" } }, "paths": { "$default": { "x-amazon-apigateway-any-method": { + "x-amazon-apigateway-integration": { + "httpMethod": "ANY", + "type": "http_proxy", + "uri": "https://www.alphavantage.co/", + "payloadFormatVersion": "1.0" + }, + "isDefaultRoute": true, + "security": [ + { + "OAuth2": [] + } + ] + } + }, + "/": { + "get": { "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", @@ -91,7 +106,6 @@ }, "payloadFormatVersion": "1.0" }, - "isDefaultRoute": true, "security": [ { "OAuth2": [] @@ -101,7 +115,7 @@ } } }, - "openapi": "3.0.1", + "openapi": "3.0", "components": { "securitySchemes": { "OAuth2": { @@ -158,7 +172,7 @@ ] } }, - "HttpApiFunctionSimpleCase2Permission": { + "HttpApiFunctionBasePathPermission": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", @@ -168,7 +182,7 @@ }, "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__Stage__": "*", "__ApiId__": { diff --git a/tests/translator/output/aws-us-gov/explicit_http_api.json b/tests/translator/output/aws-us-gov/explicit_http_api.json index 0c97ee2c8..5c0e1761e 100644 --- a/tests/translator/output/aws-us-gov/explicit_http_api.json +++ b/tests/translator/output/aws-us-gov/explicit_http_api.json @@ -75,14 +75,29 @@ "Properties": { "Body": { "info": { - "version": "1.0", "title": { - "Ref": "AWS::StackName" + "Fn::Sub": "${AWS::StackName}-Apiv2" } }, "paths": { "$default": { "x-amazon-apigateway-any-method": { + "x-amazon-apigateway-integration": { + "httpMethod": "ANY", + "type": "http_proxy", + "uri": "https://www.alphavantage.co/", + "payloadFormatVersion": "1.0" + }, + "isDefaultRoute": true, + "security": [ + { + "OAuth2": [] + } + ] + } + }, + "/": { + "get": { "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", @@ -91,7 +106,6 @@ }, "payloadFormatVersion": "1.0" }, - "isDefaultRoute": true, "security": [ { "OAuth2": [] @@ -101,7 +115,7 @@ } } }, - "openapi": "3.0.1", + "openapi": "3.0", "components": { "securitySchemes": { "OAuth2": { @@ -158,7 +172,7 @@ ] } }, - "HttpApiFunctionSimpleCase2Permission": { + "HttpApiFunctionBasePathPermission": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", @@ -168,7 +182,7 @@ }, "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__Stage__": "*", "__ApiId__": { diff --git a/tests/translator/output/explicit_http_api.json b/tests/translator/output/explicit_http_api.json index 070bd8935..3f7e4c22e 100644 --- a/tests/translator/output/explicit_http_api.json +++ b/tests/translator/output/explicit_http_api.json @@ -75,14 +75,29 @@ "Properties": { "Body": { "info": { - "version": "1.0", "title": { - "Ref": "AWS::StackName" + "Fn::Sub": "${AWS::StackName}-Apiv2" } }, "paths": { "$default": { "x-amazon-apigateway-any-method": { + "x-amazon-apigateway-integration": { + "httpMethod": "ANY", + "type": "http_proxy", + "uri": "https://www.alphavantage.co/", + "payloadFormatVersion": "1.0" + }, + "isDefaultRoute": true, + "security": [ + { + "OAuth2": [] + } + ] + } + }, + "/": { + "get": { "x-amazon-apigateway-integration": { "httpMethod": "POST", "type": "aws_proxy", @@ -91,7 +106,6 @@ }, "payloadFormatVersion": "1.0" }, - "isDefaultRoute": true, "security": [ { "OAuth2": [] @@ -101,7 +115,7 @@ } } }, - "openapi": "3.0.1", + "openapi": "3.0", "components": { "securitySchemes": { "OAuth2": { @@ -158,7 +172,7 @@ ] } }, - "HttpApiFunctionSimpleCase2Permission": { + "HttpApiFunctionBasePathPermission": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", @@ -168,7 +182,7 @@ }, "SourceArn": { "Fn::Sub": [ - "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/*", + "arn:${AWS::Partition}:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", { "__Stage__": "*", "__ApiId__": {