diff --git a/samtranslator/model/eventsources/push.py b/samtranslator/model/eventsources/push.py index 93ed5592f..7d1dd0fb8 100644 --- a/samtranslator/model/eventsources/push.py +++ b/samtranslator/model/eventsources/push.py @@ -541,6 +541,7 @@ class Api(PushEventSource): "Auth": PropertyType(False, is_type(dict)), "RequestModel": PropertyType(False, is_type(dict)), "RequestParameters": PropertyType(False, is_type(list)), + "RequestValidators": PropertyType(False, is_type(dict)), } def resources_to_link(self, resources): @@ -657,6 +658,33 @@ def _get_permission(self, resources_to_link, stage, suffix): return self._construct_permission(resources_to_link["function"], source_arn=source_arn, suffix=suffix) + def _add_validators(self, editor, validate_body, validate_parameters): + # Checking if any of the fields are defined as it can be false we are checking if the field are not None + if validate_body is not None or validate_parameters is not None: + + # as we are setting two different fields we are here setting as default False + # In case one of them are not defined + validate_body = False if validate_body is None else validate_body + validate_parameters = False if validate_parameters is None else validate_parameters + + # If not type None but any other type it should explicitly invalidate the Spec + # Those fields should be only a boolean + if not isinstance(validate_body, bool) or not isinstance(validate_parameters, bool): + raise InvalidEventException( + self.relative_id, + "Unable to set Validator on API method [{method}] for path [{path}] " + "ValidateBody and ValidateParameters must be a boolean type, strings or intrinsics are not supported.".format( + method=self.Method, path=self.Path + ), + ) + + editor.add_request_validator_to_method( + path=self.Path, + method_name=self.Method, + validate_body=validate_body, + validate_parameters=validate_parameters, + ) + def _add_swagger_integration(self, api, function, intrinsics_resolver): """Adds the path and method for this Api event source to the Swagger body for the provided RestApi. @@ -800,31 +828,16 @@ def _add_swagger_integration(self, api, function, intrinsics_resolver): validate_body = self.RequestModel.get("ValidateBody") validate_parameters = self.RequestModel.get("ValidateParameters") - # Checking if any of the fields are defined as it can be false we are checking if the field are not None - if validate_body is not None or validate_parameters is not None: - - # as we are setting two different fields we are here setting as default False - # In case one of them are not defined - validate_body = False if validate_body is None else validate_body - validate_parameters = False if validate_parameters is None else validate_parameters + self._add_validators(editor, validate_body, validate_parameters) - # If not type None but any other type it should explicitly invalidate the Spec - # Those fields should be only a boolean - if not isinstance(validate_body, bool) or not isinstance(validate_parameters, bool): - raise InvalidEventException( - self.relative_id, - "Unable to set Validator to RequestModel [{model}] on API method [{method}] for path [{path}] " - "ValidateBody and ValidateParameters must be a boolean type, strings or intrinsics are not supported.".format( - model=method_model, method=self.Method, path=self.Path - ), - ) - - editor.add_request_validator_to_method( - path=self.Path, - method_name=self.Method, - validate_body=validate_body, - validate_parameters=validate_parameters, - ) + if self.RequestValidators: + # default is no Validators + # if we have validator configured to a request parameter + # we want to add it to the editor but remove it from original dict before it iterates + # If validators is present or not, this method will handle the check + self._add_validators( + editor, self.RequestValidators.get("ValidateBody"), self.RequestValidators.get("ValidateParameters") + ) if self.RequestParameters: diff --git a/tests/translator/input/api_request_parameters_with_validator.yaml b/tests/translator/input/api_request_parameters_with_validator.yaml new file mode 100644 index 000000000..507af2589 --- /dev/null +++ b/tests/translator/input/api_request_parameters_with_validator.yaml @@ -0,0 +1,203 @@ +Resources: + HtmlFunction: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs12.x + Events: + GetHtml: + Type: Api + Properties: + RestApiId: HtmlApi + Path: / + Method: get + RequestModel: + Model: User + Required: true + ValidateBody: true + ValidateParameters: true + + HtmlFunctionNoValidation: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs12.x + Events: + GetHtml: + Type: Api + Properties: + RestApiId: HtmlApi + Path: /no-validation + Method: get + RequestModel: + Model: User + Required: true + ValidateBody: false + ValidateParameters: false + + HtmlFunctionMixinValidation: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs12.x + Events: + GetHtml: + Type: Api + Properties: + RestApiId: HtmlApi + Path: /mixin + Method: get + RequestModel: + Model: User + Required: true + ValidateBody: true + ValidateParameters: false + + HtmlFunctionOnlyBodyDefinition: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs12.x + Events: + GetHtml: + Type: Api + Properties: + RestApiId: HtmlApi + Path: /only-body-true + Method: get + RequestModel: + Model: User + Required: true + ValidateBody: true + + HtmlFunctionOnlyRequestDefinition: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs12.x + Events: + GetHtml: + Type: Api + Properties: + RestApiId: HtmlApi + Path: /only-request-true + Method: get + RequestValidators: + ValidateParameters: true + RequestModel: + Model: User + Required: true + + HtmlFunctionOnlyRequestDefinitionFalse: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs12.x + Events: + GetHtml: + Type: Api + Properties: + RestApiId: HtmlApi + Path: /only-request-false + Method: get + RequestModel: + Model: User + Required: true + ValidateParameters: false + + HtmlFunctionOnlyBodyDefinitionFalse: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs12.x + Events: + GetHtml: + Type: Api + Properties: + RestApiId: HtmlApi + Path: /only-body-false + Method: get + RequestModel: + Model: User + Required: true + ValidateBody: false + + HtmlFunctionApiRequestParameterAndValidators: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs12.x + Events: + GetHtml: + Type: Api + Properties: + RestApiId: HtmlApi + Path: /only-body-false-and-validator + Method: get + RequestValidators: + ValidateParameters: true + RequestParameters: + - method.request.header.Authorization: + Required: true + Caching: true + + HtmlFunctionApiRequestParameterValidatorsAndModelBody: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs12.x + Events: + GetHtml: + Type: Api + Properties: + RestApiId: HtmlApi + Path: /only-body-false-and-validator-and-model + Method: get + RequestValidators: + ValidateParameters: false + RequestParameters: + - method.request.header.Authorization: + Required: true + Caching: true + RequestModel: + Model: User + Required: true + ValidateBody: true + ValidateParameters: true + + HtmlFunctionNotDefinedValidation: + Type: AWS::Serverless::Function + Properties: + CodeUri: s3://sam-demo-bucket/member_portal.zip + Handler: index.gethtml + Runtime: nodejs12.x + Events: + GetHtml: + Type: Api + Properties: + RestApiId: HtmlApi + Path: /not-defined + Method: get + RequestModel: + Model: User + Required: true + + HtmlApi: + Type: AWS::Serverless::Api + Properties: + StageName: Prod + Models: + User: + type: object + properties: + username: + type: string \ No newline at end of file diff --git a/tests/translator/output/api_request_parameters_with_validator.json b/tests/translator/output/api_request_parameters_with_validator.json new file mode 100644 index 000000000..da9d3337c --- /dev/null +++ b/tests/translator/output/api_request_parameters_with_validator.json @@ -0,0 +1,1029 @@ +{ + "Resources": { + "HtmlFunctionOnlyBodyDefinitionFalse": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionOnlyBodyDefinitionFalseRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionApiRequestParameterValidatorsAndModelBodyRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionNotDefinedValidationRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyRequestDefinitionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlApiDeployment8ae899f70f": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "Description": "RestApi deployment id: 8ae899f70f5342d3cde2e11f76202d3492f8481f", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + } + }, + "HtmlFunctionApiRequestParameterAndValidatorsRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionNotDefinedValidation": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionNotDefinedValidationRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyBodyDefinitionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionOnlyBodyDefinition" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-true", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionMixinValidationRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionApiRequestParameterValidatorsAndModelBody": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionApiRequestParameterValidatorsAndModelBodyRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlApiProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeployment8ae899f70f" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + } + }, + "HtmlApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/only-request-true": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinition.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "params-only", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/only-body-false-and-validator-and-model": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionApiRequestParameterValidatorsAndModelBody.Arn}/invocations" + }, + "cacheKeyParameters": [ + "method.request.header.Authorization" + ] + }, + "x-amazon-apigateway-request-validator": "no-validation", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + }, + { + "required": true, + "type": "string", + "name": "Authorization", + "in": "header" + } + ] + } + }, + "/": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "body-and-params", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/only-request-false": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinitionFalse.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "no-validation", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/mixin": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionMixinValidation.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "body-only", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/not-defined": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNotDefinedValidation.Arn}/invocations" + } + }, + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/only-body-true": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinition.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "body-only", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/no-validation": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNoValidation.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "no-validation", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/only-body-false": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinitionFalse.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "no-validation", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/only-body-false-and-validator": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionApiRequestParameterAndValidators.Arn}/invocations" + }, + "cacheKeyParameters": [ + "method.request.header.Authorization" + ] + }, + "x-amazon-apigateway-request-validator": "params-only", + "responses": {}, + "parameters": [ + { + "required": true, + "type": "string", + "name": "Authorization", + "in": "header" + } + ] + } + } + }, + "swagger": "2.0", + "x-amazon-apigateway-request-validators": { + "params-only": { + "validateRequestParameters": true, + "validateRequestBody": false + }, + "body-and-params": { + "validateRequestParameters": true, + "validateRequestBody": true + }, + "no-validation": { + "validateRequestParameters": false, + "validateRequestBody": false + }, + "body-only": { + "validateRequestParameters": false, + "validateRequestBody": true + } + }, + "definitions": { + "user": { + "type": "object", + "properties": { + "username": { + "type": "string" + } + } + } + } + } + } + }, + "HtmlFunctionOnlyBodyDefinitionFalseRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyRequestDefinitionFalse": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionOnlyRequestDefinitionFalseRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionNoValidationGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionNoValidation" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/no-validation", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionOnlyRequestDefinitionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionOnlyRequestDefinition" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-true", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionApiRequestParameterAndValidatorsGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionApiRequestParameterAndValidators" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-false-and-validator", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionApiRequestParameterValidatorsAndModelBodyGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionApiRequestParameterValidatorsAndModelBody" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-false-and-validator-and-model", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionOnlyRequestDefinition": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionOnlyRequestDefinitionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionNoValidation": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionNoValidationRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyBodyDefinition": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionOnlyBodyDefinitionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyRequestDefinitionFalseGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionOnlyRequestDefinitionFalse" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-false", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionNoValidationRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionMixinValidationGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionMixinValidation" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/mixin", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionMixinValidation": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionMixinValidationRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyRequestDefinitionFalseRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyBodyDefinitionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyBodyDefinitionFalseGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionOnlyBodyDefinitionFalse" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-false", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionNotDefinedValidationGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionNotDefinedValidation" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/not-defined", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionApiRequestParameterAndValidators": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionApiRequestParameterAndValidatorsRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/output/aws-cn/api_request_parameters_with_validator.json b/tests/translator/output/aws-cn/api_request_parameters_with_validator.json new file mode 100644 index 000000000..7f6212194 --- /dev/null +++ b/tests/translator/output/aws-cn/api_request_parameters_with_validator.json @@ -0,0 +1,1037 @@ +{ + "Resources": { + "HtmlFunctionOnlyBodyDefinitionFalse": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionOnlyBodyDefinitionFalseRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionApiRequestParameterValidatorsAndModelBodyRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionNotDefinedValidationRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyRequestDefinitionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionApiRequestParameterAndValidatorsRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionNotDefinedValidation": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionNotDefinedValidationRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyBodyDefinitionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionOnlyBodyDefinition" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-true", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionMixinValidationRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionApiRequestParameterValidatorsAndModelBody": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionApiRequestParameterValidatorsAndModelBodyRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlApiProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeployment9619c19528" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + } + }, + "HtmlApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/only-request-true": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinition.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "params-only", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/only-body-false-and-validator-and-model": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionApiRequestParameterValidatorsAndModelBody.Arn}/invocations" + }, + "cacheKeyParameters": [ + "method.request.header.Authorization" + ] + }, + "x-amazon-apigateway-request-validator": "no-validation", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + }, + { + "required": true, + "type": "string", + "name": "Authorization", + "in": "header" + } + ] + } + }, + "/": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "body-and-params", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/only-request-false": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinitionFalse.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "no-validation", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/mixin": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionMixinValidation.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "body-only", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/not-defined": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNotDefinedValidation.Arn}/invocations" + } + }, + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/only-body-true": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinition.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "body-only", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/no-validation": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNoValidation.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "no-validation", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/only-body-false": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinitionFalse.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "no-validation", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/only-body-false-and-validator": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-cn:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionApiRequestParameterAndValidators.Arn}/invocations" + }, + "cacheKeyParameters": [ + "method.request.header.Authorization" + ] + }, + "x-amazon-apigateway-request-validator": "params-only", + "responses": {}, + "parameters": [ + { + "required": true, + "type": "string", + "name": "Authorization", + "in": "header" + } + ] + } + } + }, + "swagger": "2.0", + "x-amazon-apigateway-request-validators": { + "params-only": { + "validateRequestParameters": true, + "validateRequestBody": false + }, + "body-and-params": { + "validateRequestParameters": true, + "validateRequestBody": true + }, + "no-validation": { + "validateRequestParameters": false, + "validateRequestBody": false + }, + "body-only": { + "validateRequestParameters": false, + "validateRequestBody": true + } + }, + "definitions": { + "user": { + "type": "object", + "properties": { + "username": { + "type": "string" + } + } + } + } + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + } + } + }, + "HtmlFunctionOnlyBodyDefinitionFalseRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyRequestDefinitionFalse": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionOnlyRequestDefinitionFalseRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlApiDeployment9619c19528": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "Description": "RestApi deployment id: 9619c19528f40f108a0c46d8a4b91cf5a11844a3", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + } + }, + "HtmlFunctionNoValidationGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionNoValidation" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/no-validation", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionOnlyRequestDefinitionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionOnlyRequestDefinition" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-true", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionApiRequestParameterAndValidatorsGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionApiRequestParameterAndValidators" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-false-and-validator", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionApiRequestParameterValidatorsAndModelBodyGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionApiRequestParameterValidatorsAndModelBody" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-false-and-validator-and-model", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionOnlyRequestDefinition": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionOnlyRequestDefinitionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionNoValidation": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionNoValidationRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyBodyDefinition": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionOnlyBodyDefinitionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyRequestDefinitionFalseGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionOnlyRequestDefinitionFalse" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-false", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionNoValidationRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionMixinValidationGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionMixinValidation" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/mixin", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionMixinValidation": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionMixinValidationRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyRequestDefinitionFalseRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyBodyDefinitionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-cn:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyBodyDefinitionFalseGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionOnlyBodyDefinitionFalse" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-false", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionNotDefinedValidationGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionNotDefinedValidation" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/not-defined", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionApiRequestParameterAndValidators": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionApiRequestParameterAndValidatorsRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-cn:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/output/aws-us-gov/api_request_parameters_with_validator.json b/tests/translator/output/aws-us-gov/api_request_parameters_with_validator.json new file mode 100644 index 000000000..7d85ae348 --- /dev/null +++ b/tests/translator/output/aws-us-gov/api_request_parameters_with_validator.json @@ -0,0 +1,1037 @@ +{ + "Resources": { + "HtmlFunctionOnlyBodyDefinitionFalse": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionOnlyBodyDefinitionFalseRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionApiRequestParameterValidatorsAndModelBodyRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionNotDefinedValidationRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyRequestDefinitionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionApiRequestParameterAndValidatorsRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionNotDefinedValidation": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionNotDefinedValidationRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyBodyDefinitionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionOnlyBodyDefinition" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-true", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionMixinValidationRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionApiRequestParameterValidatorsAndModelBody": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionApiRequestParameterValidatorsAndModelBodyRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlApiProdStage": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "DeploymentId": { + "Ref": "HtmlApiDeployment505d3e449e" + }, + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Prod" + } + }, + "HtmlApi": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "info": { + "version": "1.0", + "title": { + "Ref": "AWS::StackName" + } + }, + "paths": { + "/only-request-true": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinition.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "params-only", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/only-body-false-and-validator-and-model": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionApiRequestParameterValidatorsAndModelBody.Arn}/invocations" + }, + "cacheKeyParameters": [ + "method.request.header.Authorization" + ] + }, + "x-amazon-apigateway-request-validator": "no-validation", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + }, + { + "required": true, + "type": "string", + "name": "Authorization", + "in": "header" + } + ] + } + }, + "/": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunction.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "body-and-params", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/only-request-false": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyRequestDefinitionFalse.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "no-validation", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/mixin": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionMixinValidation.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "body-only", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/not-defined": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNotDefinedValidation.Arn}/invocations" + } + }, + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/only-body-true": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinition.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "body-only", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/no-validation": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionNoValidation.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "no-validation", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/only-body-false": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionOnlyBodyDefinitionFalse.Arn}/invocations" + } + }, + "x-amazon-apigateway-request-validator": "no-validation", + "responses": {}, + "parameters": [ + { + "required": true, + "in": "body", + "name": "user", + "schema": { + "$ref": "#/definitions/user" + } + } + ] + } + }, + "/only-body-false-and-validator": { + "get": { + "x-amazon-apigateway-integration": { + "httpMethod": "POST", + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:aws-us-gov:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HtmlFunctionApiRequestParameterAndValidators.Arn}/invocations" + }, + "cacheKeyParameters": [ + "method.request.header.Authorization" + ] + }, + "x-amazon-apigateway-request-validator": "params-only", + "responses": {}, + "parameters": [ + { + "required": true, + "type": "string", + "name": "Authorization", + "in": "header" + } + ] + } + } + }, + "swagger": "2.0", + "x-amazon-apigateway-request-validators": { + "params-only": { + "validateRequestParameters": true, + "validateRequestBody": false + }, + "body-and-params": { + "validateRequestParameters": true, + "validateRequestBody": true + }, + "no-validation": { + "validateRequestParameters": false, + "validateRequestBody": false + }, + "body-only": { + "validateRequestParameters": false, + "validateRequestBody": true + } + }, + "definitions": { + "user": { + "type": "object", + "properties": { + "username": { + "type": "string" + } + } + } + } + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + } + } + }, + "HtmlFunctionOnlyBodyDefinitionFalseRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyRequestDefinitionFalse": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionOnlyRequestDefinitionFalseRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunction": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionNoValidationGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionNoValidation" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/no-validation", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionOnlyRequestDefinitionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionOnlyRequestDefinition" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-true", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionApiRequestParameterAndValidatorsGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionApiRequestParameterAndValidators" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-false-and-validator", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionApiRequestParameterValidatorsAndModelBodyGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionApiRequestParameterValidatorsAndModelBody" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-false-and-validator-and-model", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionOnlyRequestDefinition": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionOnlyRequestDefinitionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionNoValidation": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionNoValidationRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyBodyDefinition": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionOnlyBodyDefinitionRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyRequestDefinitionFalseGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionOnlyRequestDefinitionFalse" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-request-false", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionNoValidationRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionMixinValidationGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionMixinValidation" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/mixin", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlApiDeployment505d3e449e": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "Description": "RestApi deployment id: 505d3e449ec3b0328c51f89559c5908d1ec1407a", + "RestApiId": { + "Ref": "HtmlApi" + }, + "StageName": "Stage" + } + }, + "HtmlFunctionMixinValidation": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionMixinValidationRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyRequestDefinitionFalseRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyBodyDefinitionRole": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Version": "2012-10-17", + "Statement": [ + { + "Action": [ + "sts:AssumeRole" + ], + "Effect": "Allow", + "Principal": { + "Service": [ + "lambda.amazonaws.com" + ] + } + } + ] + }, + "ManagedPolicyArns": [ + "arn:aws-us-gov:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ], + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionOnlyBodyDefinitionFalseGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionOnlyBodyDefinitionFalse" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/only-body-false", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionNotDefinedValidationGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunctionNotDefinedValidation" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/not-defined", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + }, + "HtmlFunctionApiRequestParameterAndValidators": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "S3Bucket": "sam-demo-bucket", + "S3Key": "member_portal.zip" + }, + "Handler": "index.gethtml", + "Role": { + "Fn::GetAtt": [ + "HtmlFunctionApiRequestParameterAndValidatorsRole", + "Arn" + ] + }, + "Runtime": "nodejs12.x", + "Tags": [ + { + "Key": "lambda:createdBy", + "Value": "SAM" + } + ] + } + }, + "HtmlFunctionGetHtmlPermissionProd": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Ref": "HtmlFunction" + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Sub": [ + "arn:aws-us-gov:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/", + { + "__ApiId__": "HtmlApi", + "__Stage__": "*" + } + ] + } + } + } + } +} \ No newline at end of file diff --git a/tests/translator/output/error_api_request_model_with_intrinsics_validator.json b/tests/translator/output/error_api_request_model_with_intrinsics_validator.json index c51ae4c45..2b3718f27 100644 --- a/tests/translator/output/error_api_request_model_with_intrinsics_validator.json +++ b/tests/translator/output/error_api_request_model_with_intrinsics_validator.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 3. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Unable to set Validator to RequestModel [User] on API method [get] for path [/] ValidateBody and ValidateParameters must be a boolean type, strings or intrinsics are not supported. Resource with id [HtmlFunctionNoValue] is invalid. Event with id [GetHtml] is invalid. Unable to set Validator to RequestModel [User] on API method [get] for path [/novalue] ValidateBody and ValidateParameters must be a boolean type, strings or intrinsics are not supported. Resource with id [HtmlFunctionWithIfIntrinsics] is invalid. Event with id [GetHtml] is invalid. Unable to set Validator to RequestModel [User] on API method [get] for path [/if/intrinics] ValidateBody and ValidateParameters must be a boolean type, strings or intrinsics are not supported." + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 3. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Unable to set Validator on API method [get] for path [/] ValidateBody and ValidateParameters must be a boolean type, strings or intrinsics are not supported. Resource with id [HtmlFunctionNoValue] is invalid. Event with id [GetHtml] is invalid. Unable to set Validator on API method [get] for path [/novalue] ValidateBody and ValidateParameters must be a boolean type, strings or intrinsics are not supported. Resource with id [HtmlFunctionWithIfIntrinsics] is invalid. Event with id [GetHtml] is invalid. Unable to set Validator on API method [get] for path [/if/intrinics] ValidateBody and ValidateParameters must be a boolean type, strings or intrinsics are not supported." } diff --git a/tests/translator/output/error_api_request_model_with_strings_validator.json b/tests/translator/output/error_api_request_model_with_strings_validator.json index 92b765259..cf62e3a95 100644 --- a/tests/translator/output/error_api_request_model_with_strings_validator.json +++ b/tests/translator/output/error_api_request_model_with_strings_validator.json @@ -1,3 +1,3 @@ { - "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Unable to set Validator to RequestModel [User] on API method [get] for path [/] ValidateBody and ValidateParameters must be a boolean type, strings or intrinsics are not supported." + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [HtmlFunction] is invalid. Event with id [GetHtml] is invalid. Unable to set Validator on API method [get] for path [/] ValidateBody and ValidateParameters must be a boolean type, strings or intrinsics are not supported." } diff --git a/tests/translator/test_translator.py b/tests/translator/test_translator.py index a0b102879..a403c538a 100644 --- a/tests/translator/test_translator.py +++ b/tests/translator/test_translator.py @@ -293,6 +293,7 @@ def test_transform_success(self, testcase, partition_with_region): "api_with_swagger_and_openapi_with_auth", "api_with_openapi_definition_body_no_flag", "api_request_model_with_validator_openapi_3", + "api_request_parameters_with_validator", "api_request_model_openapi_3", "api_with_apikey_required_openapi_3", "api_with_basic_custom_domain",