diff --git a/tests/translator/input/definition_body_intrinsics_support.yaml b/tests/translator/input/definition_body_intrinsics_support.yaml new file mode 100644 index 0000000000..d082c4f655 --- /dev/null +++ b/tests/translator/input/definition_body_intrinsics_support.yaml @@ -0,0 +1,81 @@ +AWSTemplateFormatVersion: '2010-09-09' +Transform: AWS::Serverless-2016-10-31 +Description: > + DefinitionBody currently only supports intrinsics when SwaggerEditor/OpenApiEditor is not used (as of 2022-05-30). + Let's add tests to make sure we keep this support, because we've had a regression where we accidentally + removed this intrinsics support by using the SwaggerEditor. + Note that the only supported intrinsic function for DefinitionBody is Fn::If. Other intrinsics are not supported + because they don't resolve to dictionary. + +Conditions: + FalseCondition: + Fn::Equals: + - true + - false + +Resources: + # Rest Api with DefinitionBody under If intrinsic, SwaggerEditor not used + RestApiIfIntrinsicAndNoSwaggerEditor: + Type: AWS::Serverless::Api + Properties: + StageName: prod + DefinitionBody: + Fn::If: + - FalseCondition + - + swagger: '2.0' + info: + title: !Sub ${AWS::StackName}-Api + paths: + /post: + post: + x-amazon-apigateway-integration: + httpMethod: POST + type: aws_proxy + uri: https://www.alphavantage.co/ + payloadFormatVersion: '1.0' + - + swagger: '2.0' + info: + title: !Sub ${AWS::StackName}-Api + paths: + /post: + post: + x-amazon-apigateway-integration: + httpMethod: POST + type: aws_proxy + uri: https://www.otheruri.co/ + payloadFormatVersion: '1.0' + + # HttpApi with DefinitionBody under If intrinsic, OpenApiEditor not used + HttpApiIfIntrinsicAndNoOpenApiEditor: + Type: AWS::Serverless::HttpApi + Properties: + StageName: prod + DefinitionBody: + Fn::If: + - FalseCondition + - + openapi: '3.0' + info: + title: !Sub ${AWS::StackName}-Api + paths: + /post: + post: + x-amazon-apigateway-integration: + httpMethod: POST + type: aws_proxy + uri: https://www.alphavantage.co/ + payloadFormatVersion: '1.0' + - + openapi: '3.0' + info: + title: !Sub ${AWS::StackName}-Api + paths: + /post: + post: + x-amazon-apigateway-integration: + httpMethod: POST + type: aws_proxy + uri: https://www.otheruri.co/ + payloadFormatVersion: '1.0' diff --git a/tests/translator/output/aws-cn/definition_body_intrinsics_support.json b/tests/translator/output/aws-cn/definition_body_intrinsics_support.json new file mode 100644 index 0000000000..e8693dc49e --- /dev/null +++ b/tests/translator/output/aws-cn/definition_body_intrinsics_support.json @@ -0,0 +1,154 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "DefinitionBody currently only supports intrinsics when SwaggerEditor/OpenApiEditor is not used (as of 2022-05-30). Let's add tests to make sure we keep this support, because we've had a regression where we accidentally removed this intrinsics support by using the SwaggerEditor. Note that the only supported intrinsic function for DefinitionBody is Fn::If. Other intrinsics are not supported because they don't resolve to dictionary. \n", + "Conditions": { + "FalseCondition": { + "Fn::Equals": [ + true, + false + ] + } + }, + "Resources": { + "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "Description": "RestApi deployment id: 2f0411dccde517dcb5c82d3848dbc431e7479ebc", + "RestApiId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" + }, + "StageName": "Stage" + } + }, + "RestApiIfIntrinsicAndNoSwaggerEditorprodStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd" + }, + "RestApiId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" + }, + "StageName": "prod" + } + }, + "HttpApiIfIntrinsicAndNoOpenApiEditorprodStage": { + "Type": "AWS::ApiGatewayV2::Stage", + "Properties": { + "ApiId": { + "Ref": "HttpApiIfIntrinsicAndNoOpenApiEditor" + }, + "StageName": "prod", + "AutoDeploy": true + } + }, + "RestApiIfIntrinsicAndNoSwaggerEditor": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "Fn::If": [ + "FalseCondition", + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/", + "payloadFormatVersion": "1.0" + } + } + } + }, + "swagger": "2.0" + }, + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": "https://www.otheruri.co/", + "payloadFormatVersion": "1.0" + } + } + } + }, + "swagger": "2.0" + } + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + } + } + }, + "HttpApiIfIntrinsicAndNoOpenApiEditor": { + "Type": "AWS::ApiGatewayV2::Api", + "Properties": { + "Body": { + "Fn::If": [ + "FalseCondition", + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/", + "payloadFormatVersion": "1.0" + } + } + } + }, + "openapi": "3.0" + }, + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": "https://www.otheruri.co/", + "payloadFormatVersion": "1.0" + } + } + } + }, + "openapi": "3.0" + } + ] + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/definition_body_intrinsics_support.json b/tests/translator/output/aws-us-gov/definition_body_intrinsics_support.json new file mode 100644 index 0000000000..e8693dc49e --- /dev/null +++ b/tests/translator/output/aws-us-gov/definition_body_intrinsics_support.json @@ -0,0 +1,154 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "DefinitionBody currently only supports intrinsics when SwaggerEditor/OpenApiEditor is not used (as of 2022-05-30). Let's add tests to make sure we keep this support, because we've had a regression where we accidentally removed this intrinsics support by using the SwaggerEditor. Note that the only supported intrinsic function for DefinitionBody is Fn::If. Other intrinsics are not supported because they don't resolve to dictionary. \n", + "Conditions": { + "FalseCondition": { + "Fn::Equals": [ + true, + false + ] + } + }, + "Resources": { + "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "Description": "RestApi deployment id: 2f0411dccde517dcb5c82d3848dbc431e7479ebc", + "RestApiId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" + }, + "StageName": "Stage" + } + }, + "RestApiIfIntrinsicAndNoSwaggerEditorprodStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd" + }, + "RestApiId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" + }, + "StageName": "prod" + } + }, + "HttpApiIfIntrinsicAndNoOpenApiEditorprodStage": { + "Type": "AWS::ApiGatewayV2::Stage", + "Properties": { + "ApiId": { + "Ref": "HttpApiIfIntrinsicAndNoOpenApiEditor" + }, + "StageName": "prod", + "AutoDeploy": true + } + }, + "RestApiIfIntrinsicAndNoSwaggerEditor": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "Fn::If": [ + "FalseCondition", + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/", + "payloadFormatVersion": "1.0" + } + } + } + }, + "swagger": "2.0" + }, + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": "https://www.otheruri.co/", + "payloadFormatVersion": "1.0" + } + } + } + }, + "swagger": "2.0" + } + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + } + } + }, + "HttpApiIfIntrinsicAndNoOpenApiEditor": { + "Type": "AWS::ApiGatewayV2::Api", + "Properties": { + "Body": { + "Fn::If": [ + "FalseCondition", + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/", + "payloadFormatVersion": "1.0" + } + } + } + }, + "openapi": "3.0" + }, + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": "https://www.otheruri.co/", + "payloadFormatVersion": "1.0" + } + } + } + }, + "openapi": "3.0" + } + ] + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/output/definition_body_intrinsics_support.json b/tests/translator/output/definition_body_intrinsics_support.json new file mode 100644 index 0000000000..3d19754b8c --- /dev/null +++ b/tests/translator/output/definition_body_intrinsics_support.json @@ -0,0 +1,146 @@ +{ + "AWSTemplateFormatVersion": "2010-09-09", + "Description": "DefinitionBody currently only supports intrinsics when SwaggerEditor/OpenApiEditor is not used (as of 2022-05-30). Let's add tests to make sure we keep this support, because we've had a regression where we accidentally removed this intrinsics support by using the SwaggerEditor. Note that the only supported intrinsic function for DefinitionBody is Fn::If. Other intrinsics are not supported because they don't resolve to dictionary. \n", + "Conditions": { + "FalseCondition": { + "Fn::Equals": [ + true, + false + ] + } + }, + "Resources": { + "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "Description": "RestApi deployment id: 2f0411dccde517dcb5c82d3848dbc431e7479ebc", + "RestApiId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" + }, + "StageName": "Stage" + } + }, + "RestApiIfIntrinsicAndNoSwaggerEditorprodStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditorDeployment2f0411dccd" + }, + "RestApiId": { + "Ref": "RestApiIfIntrinsicAndNoSwaggerEditor" + }, + "StageName": "prod" + } + }, + "HttpApiIfIntrinsicAndNoOpenApiEditorprodStage": { + "Type": "AWS::ApiGatewayV2::Stage", + "Properties": { + "ApiId": { + "Ref": "HttpApiIfIntrinsicAndNoOpenApiEditor" + }, + "StageName": "prod", + "AutoDeploy": true + } + }, + "RestApiIfIntrinsicAndNoSwaggerEditor": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "Fn::If": [ + "FalseCondition", + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/", + "payloadFormatVersion": "1.0" + } + } + } + }, + "swagger": "2.0" + }, + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": "https://www.otheruri.co/", + "payloadFormatVersion": "1.0" + } + } + } + }, + "swagger": "2.0" + } + ] + } + } + }, + "HttpApiIfIntrinsicAndNoOpenApiEditor": { + "Type": "AWS::ApiGatewayV2::Api", + "Properties": { + "Body": { + "Fn::If": [ + "FalseCondition", + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": "https://www.alphavantage.co/", + "payloadFormatVersion": "1.0" + } + } + } + }, + "openapi": "3.0" + }, + { + "info": { + "title": { + "Fn::Sub": "${AWS::StackName}-Api" + } + }, + "paths": { + "/post": { + "post": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": "https://www.otheruri.co/", + "payloadFormatVersion": "1.0" + } + } + } + }, + "openapi": "3.0" + } + ] + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index e2942b7075..bf11ed7532 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -484,6 +484,7 @@ class TestTranslatorEndToEnd(AbstractTestTranslator): "function_with_function_url_config_with_iam_authorization_type", "function_with_function_url_config_without_cors_config", "function_with_function_url_config_and_autopublishalias", + "definition_body_intrinsics_support", ], [ ("aws", "ap-southeast-1"),