diff --git a/samtranslator/model/api/api_generator.py b/samtranslator/model/api/api_generator.py index a04352243e..c582a1048b 100644 --- a/samtranslator/model/api/api_generator.py +++ b/samtranslator/model/api/api_generator.py @@ -1128,6 +1128,15 @@ def _openapi_postprocess(self, definition_body: Dict[str, Any]) -> Dict[str, Any if definition_body.get("openapi") is not None and self.open_api_version is None: self.open_api_version = definition_body.get("openapi") + if ( + definition_body.get("openapi") is not None + and self.open_api_version is not None + and definition_body.get("openapi") != self.open_api_version + ): + raise InvalidResourceException( + self.logical_id, "OpenApiVersion property doesn't match openapi value in 'DefinitionBody'." + ) + if self.open_api_version and SwaggerEditor.safe_compare_regex_with_string( SwaggerEditor._OPENAPI_VERSION_3_REGEX, self.open_api_version ): diff --git a/tests/translator/input/api_open_api_version_match.yaml b/tests/translator/input/api_open_api_version_match.yaml new file mode 100644 index 0000000000..7be62a78c1 --- /dev/null +++ b/tests/translator/input/api_open_api_version_match.yaml @@ -0,0 +1,457 @@ +Transform: +- AWS::Serverless-2016-10-31 +Resources: + ApiGatewayCognitoExecutionRole4F7CB5C8: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + Service: apigateway.amazonaws.com + Version: '2012-10-17' + Policies: + - PolicyDocument: + Statement: + - Action: lambda:Invoke* + Effect: Allow + Resource: + Fn::GetAtt: + - LambdaFunction7804BD21 + - Arn + Version: '2012-10-17' + PolicyName: apigInvokeLambda + LambdaFunctionServiceRoleD6E423C9: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + Service: lambda.amazonaws.com + Version: '2012-10-17' + ManagedPolicyArns: + - Fn::Join: + - '' + - - 'arn:' + - Ref: AWS::Partition + - :iam::aws:policy/service-role/AWSLambdaBasicExecutionRole + LambdaFunctionServiceRoleDefaultPolicyF01A7EDC: + Type: AWS::IAM::Policy + Properties: + PolicyDocument: + Statement: + - Action: sns:Publish + Effect: Allow + Resource: '*' + Version: '2012-10-17' + PolicyName: LambdaFunctionServiceRoleDefaultPolicyF01A7EDC + Roles: + - Ref: LambdaFunctionServiceRoleD6E423C9 + LambdaFunction7804BD21: + Type: AWS::Lambda::Function + Properties: + Code: + ZipFile: | + exports.handler = async (event, context, callback) => { + const auth = event.queryStringParameters.authorization + const policyDocument = { + Version: '2012-10-17', + Statement: [{ + Action: 'execute-api:Invoke', + Effect: auth && auth.toLowerCase() === 'allow' ? 'Allow' : 'Deny', + Resource: event.methodArn + }] + } + + return { + principalId: 'user', + context: {}, + policyDocument + } + } + Role: + Fn::GetAtt: + - LambdaFunctionServiceRoleD6E423C9 + - Arn + Handler: index.handler + Runtime: nodejs16.x + MyCognitoUserPool: + Type: AWS::Cognito::UserPool + Properties: + UserPoolName: MyCognitoUserPool + ApiGatewayCognitoService15108F0B: + Type: AWS::Serverless::Api + Properties: + StageName: prod + Auth: + AddDefaultAuthorizerToCorsPreflight: false + Authorizers: + CognitoAuthorizer: + UserPoolArn: + Fn::GetAtt: MyCognitoUserPool.Arn + DefaultAuthorizer: CognitoAuthorizer + DefinitionBody: + openapi: 3.0.2 + info: + title: RxtHofApprovalServiceLambdaCognito + version: '2018-05-10' + paths: + /reviews: + post: + operationId: CreateReview + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateReviewRequestContent' + required: true + responses: + '200': + description: CreateReview 200 response + headers: + Access-Control-Allow-Origin: + schema: + type: string + Access-Control-Expose-Headers: + schema: + type: string + content: + application/json: + schema: + $ref: '#/components/schemas/CreateReviewResponseContent' + x-amazon-apigateway-integration: + type: aws_proxy + httpMethod: POST + uri: + Fn::Sub: arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunction7804BD21.Arn}/invocations + credentials: + Fn::Sub: ${ApiGatewayCognitoExecutionRole4F7CB5C8.Arn} + responses: + default: + statusCode: '200' + responseParameters: + method.response.header.Access-Control-Allow-Origin: "'*'" + method.response.header.Access-Control-Expose-Headers: "'Content-Length,Content-Type,X-Amzn-Errortype,X-Amzn-Requestid'" + components: + schemas: + ApprovalDTO: + type: object + properties: + reviewId: + type: string + revisionNumber: + type: string + reviewer: + type: string + createdAt: + type: number + format: double + modifiedAt: + type: number + format: double + approvalStatus: + $ref: '#/components/schemas/ApprovalStatus' + required: + - reviewId + - reviewer + - revisionNumber + ApprovalStatus: + type: string + enum: + - REVOKED + - APPROVED + CommentDTO: + type: object + properties: + reviewId: + type: string + revisionNumber: + type: string + commentId: + type: string + message: + type: string + author: + type: string + createdAt: + type: number + format: double + modifiedAt: + type: number + format: double + locationId: + type: string + required: + - commentId + - reviewId + - revisionNumber + CreateCommentRequestContent: + type: object + properties: + message: + type: string + author: + type: string + locationId: + type: string + required: + - author + - message + CreateCommentResponseContent: + type: object + properties: + comment: + $ref: '#/components/schemas/CommentDTO' + required: + - comment + CreateReviewRequestContent: + type: object + properties: + reviewId: + type: string + description: If absent, new reviewId will be generated by the service. + If present, new revision number will be generated for the same + reviewId + title: + type: string + description: + type: string + requester: + type: string + reviewers: + type: array + items: + type: string + reviewUrl: + type: string + clientId: + type: string + required: + - clientId + - description + - requester + - reviewUrl + - title + CreateReviewResponseContent: + type: object + properties: + review: + $ref: '#/components/schemas/ReviewDTO' + required: + - review + GetReviewResponseContent: + type: object + properties: + review: + $ref: '#/components/schemas/ReviewDTO' + required: + - review + GetRevisionResponseContent: + type: object + properties: + revision: + $ref: '#/components/schemas/RevisionDTO' + required: + - revision + InvalidInputExceptionResponseContent: + type: object + properties: + message: + type: string + ListApprovalResponseContent: + type: object + properties: + reviewId: + type: string + revisionNumber: + type: string + approvals: + type: array + items: + $ref: '#/components/schemas/ApprovalDTO' + required: + - approvals + - reviewId + - revisionNumber + ListCommentResponseContent: + type: object + properties: + reviewId: + type: string + revisionNumber: + type: string + comments: + type: array + items: + $ref: '#/components/schemas/CommentDTO' + required: + - comments + - reviewId + - revisionNumber + PutApprovalRequestContent: + type: object + properties: + reviewer: + type: string + approvalStatus: + $ref: '#/components/schemas/ApprovalStatus' + required: + - approvalStatus + - reviewer + PutApprovalResponseContent: + type: object + properties: + approval: + $ref: '#/components/schemas/ApprovalDTO' + required: + - approval + ResourceNotExistExceptionResponseContent: + type: object + properties: + message: + type: string + ReviewDTO: + type: object + properties: + reviewId: + type: string + title: + type: string + reviewers: + type: array + items: + type: string + requester: + type: string + createdAt: + type: number + format: double + modifiedBy: + type: string + modifiedAt: + type: number + format: double + revisionList: + type: array + items: + $ref: '#/components/schemas/RevisionDTO' + approvedRevisionNumber: + type: string + reviewStatus: + $ref: '#/components/schemas/ReviewStatus' + required: + - createdAt + - modifiedAt + - modifiedBy + - requester + - reviewId + - reviewStatus + - reviewers + - revisionList + - title + ReviewStatus: + type: string + enum: + - OPEN + - APPROVED + RevisionDTO: + type: object + properties: + reviewId: + type: string + revisionNumber: + type: string + title: + type: string + description: + type: string + reviewUrl: + type: string + createdBy: + type: string + createdAt: + type: number + format: double + modifiedBy: + type: string + modifiedAt: + type: number + format: double + required: + - createdAt + - createdBy + - description + - modifiedAt + - modifiedBy + - reviewId + - reviewUrl + - revisionNumber + - title + echoRequestContent: + type: object + properties: + string: + type: string + echoResponseContent: + type: object + properties: + string: + type: string + securitySchemes: + aws.auth.sigv4: + type: apiKey + description: AWS Signature Version 4 authentication + name: Authorization + in: header + x-amazon-apigateway-authtype: awsSigv4 + security: + - aws.auth.sigv4: [] + x-amazon-apigateway-gateway-responses: + DEFAULT_4XX: + responseTemplates: + application/json: '{"message":$context.error.messageString}' + responseParameters: + gatewayresponse.header.Access-Control-Allow-Origin: "'*'" + DEFAULT_5XX: + responseTemplates: + application/json: '{"message":$context.error.messageString}' + responseParameters: + gatewayresponse.header.Access-Control-Allow-Origin: "'*'" + MethodSettings: + - DataTraceEnabled: false + LoggingLevel: INFO + ResourcePath: /* + MetricsEnabled: false + HttpMethod: '*' + OpenApiVersion: 3.0.2 + TracingEnabled: true + DependsOn: + - ApiGatewayCognitoAccount64FCB056 + ApiGatewayCognitoCloudwatchLoggingRole0DECE2B1: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + Service: apigateway.amazonaws.com + Version: '2012-10-17' + ManagedPolicyArns: + - Fn::Join: + - '' + - - 'arn:' + - Ref: AWS::Partition + - :iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs + Metadata: + aws:cdk:path: ApprovalServiceBackendLambdaStack-prod/ApiGatewayCognito/CloudwatchLoggingRole/Resource + ApiGatewayCognitoAccount64FCB056: + Type: AWS::ApiGateway::Account + Properties: + CloudWatchRoleArn: + Fn::GetAtt: + - ApiGatewayCognitoCloudwatchLoggingRole0DECE2B1 + - Arn diff --git a/tests/translator/input/error_api_open_api_version_not_match.yaml b/tests/translator/input/error_api_open_api_version_not_match.yaml new file mode 100644 index 0000000000..ea46444b04 --- /dev/null +++ b/tests/translator/input/error_api_open_api_version_not_match.yaml @@ -0,0 +1,457 @@ +Transform: +- AWS::Serverless-2016-10-31 +Resources: + ApiGatewayCognitoExecutionRole4F7CB5C8: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + Service: apigateway.amazonaws.com + Version: '2012-10-17' + Policies: + - PolicyDocument: + Statement: + - Action: lambda:Invoke* + Effect: Allow + Resource: + Fn::GetAtt: + - LambdaFunction7804BD21 + - Arn + Version: '2012-10-17' + PolicyName: apigInvokeLambda + LambdaFunctionServiceRoleD6E423C9: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + Service: lambda.amazonaws.com + Version: '2012-10-17' + ManagedPolicyArns: + - Fn::Join: + - '' + - - 'arn:' + - Ref: AWS::Partition + - :iam::aws:policy/service-role/AWSLambdaBasicExecutionRole + LambdaFunctionServiceRoleDefaultPolicyF01A7EDC: + Type: AWS::IAM::Policy + Properties: + PolicyDocument: + Statement: + - Action: sns:Publish + Effect: Allow + Resource: '*' + Version: '2012-10-17' + PolicyName: LambdaFunctionServiceRoleDefaultPolicyF01A7EDC + Roles: + - Ref: LambdaFunctionServiceRoleD6E423C9 + LambdaFunction7804BD21: + Type: AWS::Lambda::Function + Properties: + Code: + ZipFile: | + exports.handler = async (event, context, callback) => { + const auth = event.queryStringParameters.authorization + const policyDocument = { + Version: '2012-10-17', + Statement: [{ + Action: 'execute-api:Invoke', + Effect: auth && auth.toLowerCase() === 'allow' ? 'Allow' : 'Deny', + Resource: event.methodArn + }] + } + + return { + principalId: 'user', + context: {}, + policyDocument + } + } + Role: + Fn::GetAtt: + - LambdaFunctionServiceRoleD6E423C9 + - Arn + Handler: index.handler + Runtime: nodejs16.x + MyCognitoUserPool: + Type: AWS::Cognito::UserPool + Properties: + UserPoolName: MyCognitoUserPool + ApiGatewayCognitoService15108F0B: + Type: AWS::Serverless::Api + Properties: + StageName: prod + Auth: + AddDefaultAuthorizerToCorsPreflight: false + Authorizers: + CognitoAuthorizer: + UserPoolArn: + Fn::GetAtt: MyCognitoUserPool.Arn + DefaultAuthorizer: CognitoAuthorizer + DefinitionBody: + openapi: 3.0.2 + info: + title: RxtHofApprovalServiceLambdaCognito + version: '2018-05-10' + paths: + /reviews: + post: + operationId: CreateReview + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/CreateReviewRequestContent' + required: true + responses: + '200': + description: CreateReview 200 response + headers: + Access-Control-Allow-Origin: + schema: + type: string + Access-Control-Expose-Headers: + schema: + type: string + content: + application/json: + schema: + $ref: '#/components/schemas/CreateReviewResponseContent' + x-amazon-apigateway-integration: + type: aws_proxy + httpMethod: POST + uri: + Fn::Sub: arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunction7804BD21.Arn}/invocations + credentials: + Fn::Sub: ${ApiGatewayCognitoExecutionRole4F7CB5C8.Arn} + responses: + default: + statusCode: '200' + responseParameters: + method.response.header.Access-Control-Allow-Origin: "'*'" + method.response.header.Access-Control-Expose-Headers: "'Content-Length,Content-Type,X-Amzn-Errortype,X-Amzn-Requestid'" + components: + schemas: + ApprovalDTO: + type: object + properties: + reviewId: + type: string + revisionNumber: + type: string + reviewer: + type: string + createdAt: + type: number + format: double + modifiedAt: + type: number + format: double + approvalStatus: + $ref: '#/components/schemas/ApprovalStatus' + required: + - reviewId + - reviewer + - revisionNumber + ApprovalStatus: + type: string + enum: + - REVOKED + - APPROVED + CommentDTO: + type: object + properties: + reviewId: + type: string + revisionNumber: + type: string + commentId: + type: string + message: + type: string + author: + type: string + createdAt: + type: number + format: double + modifiedAt: + type: number + format: double + locationId: + type: string + required: + - commentId + - reviewId + - revisionNumber + CreateCommentRequestContent: + type: object + properties: + message: + type: string + author: + type: string + locationId: + type: string + required: + - author + - message + CreateCommentResponseContent: + type: object + properties: + comment: + $ref: '#/components/schemas/CommentDTO' + required: + - comment + CreateReviewRequestContent: + type: object + properties: + reviewId: + type: string + description: If absent, new reviewId will be generated by the service. + If present, new revision number will be generated for the same + reviewId + title: + type: string + description: + type: string + requester: + type: string + reviewers: + type: array + items: + type: string + reviewUrl: + type: string + clientId: + type: string + required: + - clientId + - description + - requester + - reviewUrl + - title + CreateReviewResponseContent: + type: object + properties: + review: + $ref: '#/components/schemas/ReviewDTO' + required: + - review + GetReviewResponseContent: + type: object + properties: + review: + $ref: '#/components/schemas/ReviewDTO' + required: + - review + GetRevisionResponseContent: + type: object + properties: + revision: + $ref: '#/components/schemas/RevisionDTO' + required: + - revision + InvalidInputExceptionResponseContent: + type: object + properties: + message: + type: string + ListApprovalResponseContent: + type: object + properties: + reviewId: + type: string + revisionNumber: + type: string + approvals: + type: array + items: + $ref: '#/components/schemas/ApprovalDTO' + required: + - approvals + - reviewId + - revisionNumber + ListCommentResponseContent: + type: object + properties: + reviewId: + type: string + revisionNumber: + type: string + comments: + type: array + items: + $ref: '#/components/schemas/CommentDTO' + required: + - comments + - reviewId + - revisionNumber + PutApprovalRequestContent: + type: object + properties: + reviewer: + type: string + approvalStatus: + $ref: '#/components/schemas/ApprovalStatus' + required: + - approvalStatus + - reviewer + PutApprovalResponseContent: + type: object + properties: + approval: + $ref: '#/components/schemas/ApprovalDTO' + required: + - approval + ResourceNotExistExceptionResponseContent: + type: object + properties: + message: + type: string + ReviewDTO: + type: object + properties: + reviewId: + type: string + title: + type: string + reviewers: + type: array + items: + type: string + requester: + type: string + createdAt: + type: number + format: double + modifiedBy: + type: string + modifiedAt: + type: number + format: double + revisionList: + type: array + items: + $ref: '#/components/schemas/RevisionDTO' + approvedRevisionNumber: + type: string + reviewStatus: + $ref: '#/components/schemas/ReviewStatus' + required: + - createdAt + - modifiedAt + - modifiedBy + - requester + - reviewId + - reviewStatus + - reviewers + - revisionList + - title + ReviewStatus: + type: string + enum: + - OPEN + - APPROVED + RevisionDTO: + type: object + properties: + reviewId: + type: string + revisionNumber: + type: string + title: + type: string + description: + type: string + reviewUrl: + type: string + createdBy: + type: string + createdAt: + type: number + format: double + modifiedBy: + type: string + modifiedAt: + type: number + format: double + required: + - createdAt + - createdBy + - description + - modifiedAt + - modifiedBy + - reviewId + - reviewUrl + - revisionNumber + - title + echoRequestContent: + type: object + properties: + string: + type: string + echoResponseContent: + type: object + properties: + string: + type: string + securitySchemes: + aws.auth.sigv4: + type: apiKey + description: AWS Signature Version 4 authentication + name: Authorization + in: header + x-amazon-apigateway-authtype: awsSigv4 + security: + - aws.auth.sigv4: [] + x-amazon-apigateway-gateway-responses: + DEFAULT_4XX: + responseTemplates: + application/json: '{"message":$context.error.messageString}' + responseParameters: + gatewayresponse.header.Access-Control-Allow-Origin: "'*'" + DEFAULT_5XX: + responseTemplates: + application/json: '{"message":$context.error.messageString}' + responseParameters: + gatewayresponse.header.Access-Control-Allow-Origin: "'*'" + MethodSettings: + - DataTraceEnabled: false + LoggingLevel: INFO + ResourcePath: /* + MetricsEnabled: false + HttpMethod: '*' + OpenApiVersion: '2.0' + TracingEnabled: true + DependsOn: + - ApiGatewayCognitoAccount64FCB056 + ApiGatewayCognitoCloudwatchLoggingRole0DECE2B1: + Type: AWS::IAM::Role + Properties: + AssumeRolePolicyDocument: + Statement: + - Action: sts:AssumeRole + Effect: Allow + Principal: + Service: apigateway.amazonaws.com + Version: '2012-10-17' + ManagedPolicyArns: + - Fn::Join: + - '' + - - 'arn:' + - Ref: AWS::Partition + - :iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs + Metadata: + aws:cdk:path: ApprovalServiceBackendLambdaStack-prod/ApiGatewayCognito/CloudwatchLoggingRole/Resource + ApiGatewayCognitoAccount64FCB056: + Type: AWS::ApiGateway::Account + Properties: + CloudWatchRoleArn: + Fn::GetAtt: + - ApiGatewayCognitoCloudwatchLoggingRole0DECE2B1 + - Arn diff --git a/tests/translator/output/api_open_api_version_match.json b/tests/translator/output/api_open_api_version_match.json new file mode 100644 index 0000000000..f0c614bc09 --- /dev/null +++ b/tests/translator/output/api_open_api_version_match.json @@ -0,0 +1,694 @@ +{ + "Resources": { + "ApiGatewayCognitoAccount64FCB056": { + "Properties": { + "CloudWatchRoleArn": { + "Fn::GetAtt": [ + "ApiGatewayCognitoCloudwatchLoggingRole0DECE2B1", + "Arn" + ] + } + }, + "Type": "AWS::ApiGateway::Account" + }, + "ApiGatewayCognitoCloudwatchLoggingRole0DECE2B1": { + "Metadata": { + "aws:cdk:path": "ApprovalServiceBackendLambdaStack-prod/ApiGatewayCognito/CloudwatchLoggingRole/Resource" + }, + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "apigateway.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs" + ] + ] + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ApiGatewayCognitoExecutionRole4F7CB5C8": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "apigateway.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:Invoke*", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "LambdaFunction7804BD21", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "apigInvokeLambda" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ApiGatewayCognitoService15108F0B": { + "DependsOn": [ + "ApiGatewayCognitoAccount64FCB056" + ], + "Properties": { + "Body": { + "components": { + "schemas": { + "ApprovalDTO": { + "properties": { + "approvalStatus": { + "$ref": "#/components/schemas/ApprovalStatus" + }, + "createdAt": { + "format": "double", + "type": "number" + }, + "modifiedAt": { + "format": "double", + "type": "number" + }, + "reviewId": { + "type": "string" + }, + "reviewer": { + "type": "string" + }, + "revisionNumber": { + "type": "string" + } + }, + "required": [ + "reviewId", + "reviewer", + "revisionNumber" + ], + "type": "object" + }, + "ApprovalStatus": { + "enum": [ + "REVOKED", + "APPROVED" + ], + "type": "string" + }, + "CommentDTO": { + "properties": { + "author": { + "type": "string" + }, + "commentId": { + "type": "string" + }, + "createdAt": { + "format": "double", + "type": "number" + }, + "locationId": { + "type": "string" + }, + "message": { + "type": "string" + }, + "modifiedAt": { + "format": "double", + "type": "number" + }, + "reviewId": { + "type": "string" + }, + "revisionNumber": { + "type": "string" + } + }, + "required": [ + "commentId", + "reviewId", + "revisionNumber" + ], + "type": "object" + }, + "CreateCommentRequestContent": { + "properties": { + "author": { + "type": "string" + }, + "locationId": { + "type": "string" + }, + "message": { + "type": "string" + } + }, + "required": [ + "author", + "message" + ], + "type": "object" + }, + "CreateCommentResponseContent": { + "properties": { + "comment": { + "$ref": "#/components/schemas/CommentDTO" + } + }, + "required": [ + "comment" + ], + "type": "object" + }, + "CreateReviewRequestContent": { + "properties": { + "clientId": { + "type": "string" + }, + "description": { + "type": "string" + }, + "requester": { + "type": "string" + }, + "reviewId": { + "description": "If absent, new reviewId will be generated by the service. If present, new revision number will be generated for the same reviewId", + "type": "string" + }, + "reviewUrl": { + "type": "string" + }, + "reviewers": { + "items": { + "type": "string" + }, + "type": "array" + }, + "title": { + "type": "string" + } + }, + "required": [ + "clientId", + "description", + "requester", + "reviewUrl", + "title" + ], + "type": "object" + }, + "CreateReviewResponseContent": { + "properties": { + "review": { + "$ref": "#/components/schemas/ReviewDTO" + } + }, + "required": [ + "review" + ], + "type": "object" + }, + "GetReviewResponseContent": { + "properties": { + "review": { + "$ref": "#/components/schemas/ReviewDTO" + } + }, + "required": [ + "review" + ], + "type": "object" + }, + "GetRevisionResponseContent": { + "properties": { + "revision": { + "$ref": "#/components/schemas/RevisionDTO" + } + }, + "required": [ + "revision" + ], + "type": "object" + }, + "InvalidInputExceptionResponseContent": { + "properties": { + "message": { + "type": "string" + } + }, + "type": "object" + }, + "ListApprovalResponseContent": { + "properties": { + "approvals": { + "items": { + "$ref": "#/components/schemas/ApprovalDTO" + }, + "type": "array" + }, + "reviewId": { + "type": "string" + }, + "revisionNumber": { + "type": "string" + } + }, + "required": [ + "approvals", + "reviewId", + "revisionNumber" + ], + "type": "object" + }, + "ListCommentResponseContent": { + "properties": { + "comments": { + "items": { + "$ref": "#/components/schemas/CommentDTO" + }, + "type": "array" + }, + "reviewId": { + "type": "string" + }, + "revisionNumber": { + "type": "string" + } + }, + "required": [ + "comments", + "reviewId", + "revisionNumber" + ], + "type": "object" + }, + "PutApprovalRequestContent": { + "properties": { + "approvalStatus": { + "$ref": "#/components/schemas/ApprovalStatus" + }, + "reviewer": { + "type": "string" + } + }, + "required": [ + "approvalStatus", + "reviewer" + ], + "type": "object" + }, + "PutApprovalResponseContent": { + "properties": { + "approval": { + "$ref": "#/components/schemas/ApprovalDTO" + } + }, + "required": [ + "approval" + ], + "type": "object" + }, + "ResourceNotExistExceptionResponseContent": { + "properties": { + "message": { + "type": "string" + } + }, + "type": "object" + }, + "ReviewDTO": { + "properties": { + "approvedRevisionNumber": { + "type": "string" + }, + "createdAt": { + "format": "double", + "type": "number" + }, + "modifiedAt": { + "format": "double", + "type": "number" + }, + "modifiedBy": { + "type": "string" + }, + "requester": { + "type": "string" + }, + "reviewId": { + "type": "string" + }, + "reviewStatus": { + "$ref": "#/components/schemas/ReviewStatus" + }, + "reviewers": { + "items": { + "type": "string" + }, + "type": "array" + }, + "revisionList": { + "items": { + "$ref": "#/components/schemas/RevisionDTO" + }, + "type": "array" + }, + "title": { + "type": "string" + } + }, + "required": [ + "createdAt", + "modifiedAt", + "modifiedBy", + "requester", + "reviewId", + "reviewStatus", + "reviewers", + "revisionList", + "title" + ], + "type": "object" + }, + "ReviewStatus": { + "enum": [ + "OPEN", + "APPROVED" + ], + "type": "string" + }, + "RevisionDTO": { + "properties": { + "createdAt": { + "format": "double", + "type": "number" + }, + "createdBy": { + "type": "string" + }, + "description": { + "type": "string" + }, + "modifiedAt": { + "format": "double", + "type": "number" + }, + "modifiedBy": { + "type": "string" + }, + "reviewId": { + "type": "string" + }, + "reviewUrl": { + "type": "string" + }, + "revisionNumber": { + "type": "string" + }, + "title": { + "type": "string" + } + }, + "required": [ + "createdAt", + "createdBy", + "description", + "modifiedAt", + "modifiedBy", + "reviewId", + "reviewUrl", + "revisionNumber", + "title" + ], + "type": "object" + }, + "echoRequestContent": { + "properties": { + "string": { + "type": "string" + } + }, + "type": "object" + }, + "echoResponseContent": { + "properties": { + "string": { + "type": "string" + } + }, + "type": "object" + } + }, + "securitySchemes": { + "CognitoAuthorizer": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + { + "Fn::GetAtt": "MyCognitoUserPool.Arn" + } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "info": { + "title": "RxtHofApprovalServiceLambdaCognito", + "version": "2018-05-10" + }, + "openapi": "3.0.2", + "paths": { + "/reviews": { + "post": { + "operationId": "CreateReview", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreateReviewRequestContent" + } + } + }, + "required": true + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreateReviewResponseContent" + } + } + }, + "description": "CreateReview 200 response", + "headers": { + "Access-Control-Allow-Origin": { + "schema": { + "type": "string" + } + }, + "Access-Control-Expose-Headers": { + "schema": { + "type": "string" + } + } + } + } + }, + "security": [ + { + "CognitoAuthorizer": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::Sub": "${ApiGatewayCognitoExecutionRole4F7CB5C8.Arn}" + }, + "httpMethod": "POST", + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Origin": "'*'", + "method.response.header.Access-Control-Expose-Headers": "'Content-Length,Content-Type,X-Amzn-Errortype,X-Amzn-Requestid'" + }, + "statusCode": "200" + } + }, + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunction7804BD21.Arn}/invocations" + } + } + } + } + }, + "security": [ + { + "aws.auth.sigv4": [] + } + ], + "x-amazon-apigateway-gateway-responses": { + "DEFAULT_4XX": { + "responseParameters": { + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'" + }, + "responseTemplates": { + "application/json": "{\"message\":$context.error.messageString}" + } + }, + "DEFAULT_5XX": { + "responseParameters": { + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'" + }, + "responseTemplates": { + "application/json": "{\"message\":$context.error.messageString}" + } + } + } + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiGatewayCognitoService15108F0BDeployment2d7acebec7": { + "Properties": { + "Description": "RestApi deployment id: 2d7acebec776defc9c575e70508921389b9d7697", + "RestApiId": { + "Ref": "ApiGatewayCognitoService15108F0B" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ApiGatewayCognitoService15108F0BprodStage": { + "Properties": { + "DeploymentId": { + "Ref": "ApiGatewayCognitoService15108F0BDeployment2d7acebec7" + }, + "MethodSettings": [ + { + "DataTraceEnabled": false, + "HttpMethod": "*", + "LoggingLevel": "INFO", + "MetricsEnabled": false, + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ApiGatewayCognitoService15108F0B" + }, + "StageName": "prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" + }, + "LambdaFunction7804BD21": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event, context, callback) => {\n const auth = event.queryStringParameters.authorization\n const policyDocument = {\n Version: '2012-10-17',\n Statement: [{\n Action: 'execute-api:Invoke',\n Effect: auth && auth.toLowerCase() === 'allow' ? 'Allow' : 'Deny',\n Resource: event.methodArn\n }]\n }\n \n return {\n principalId: 'user',\n context: {},\n policyDocument\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "LambdaFunctionServiceRoleD6E423C9", + "Arn" + ] + }, + "Runtime": "nodejs16.x" + }, + "Type": "AWS::Lambda::Function" + }, + "LambdaFunctionServiceRoleD6E423C9": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "LambdaFunctionServiceRoleDefaultPolicyF01A7EDC": { + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "sns:Publish", + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "LambdaFunctionServiceRoleDefaultPolicyF01A7EDC", + "Roles": [ + { + "Ref": "LambdaFunctionServiceRoleD6E423C9" + } + ] + }, + "Type": "AWS::IAM::Policy" + }, + "MyCognitoUserPool": { + "Properties": { + "UserPoolName": "MyCognitoUserPool" + }, + "Type": "AWS::Cognito::UserPool" + } + } +} diff --git a/tests/translator/output/aws-cn/api_open_api_version_match.json b/tests/translator/output/aws-cn/api_open_api_version_match.json new file mode 100644 index 0000000000..1676d10f8f --- /dev/null +++ b/tests/translator/output/aws-cn/api_open_api_version_match.json @@ -0,0 +1,702 @@ +{ + "Resources": { + "ApiGatewayCognitoAccount64FCB056": { + "Properties": { + "CloudWatchRoleArn": { + "Fn::GetAtt": [ + "ApiGatewayCognitoCloudwatchLoggingRole0DECE2B1", + "Arn" + ] + } + }, + "Type": "AWS::ApiGateway::Account" + }, + "ApiGatewayCognitoCloudwatchLoggingRole0DECE2B1": { + "Metadata": { + "aws:cdk:path": "ApprovalServiceBackendLambdaStack-prod/ApiGatewayCognito/CloudwatchLoggingRole/Resource" + }, + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "apigateway.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs" + ] + ] + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ApiGatewayCognitoExecutionRole4F7CB5C8": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "apigateway.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:Invoke*", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "LambdaFunction7804BD21", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "apigInvokeLambda" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ApiGatewayCognitoService15108F0B": { + "DependsOn": [ + "ApiGatewayCognitoAccount64FCB056" + ], + "Properties": { + "Body": { + "components": { + "schemas": { + "ApprovalDTO": { + "properties": { + "approvalStatus": { + "$ref": "#/components/schemas/ApprovalStatus" + }, + "createdAt": { + "format": "double", + "type": "number" + }, + "modifiedAt": { + "format": "double", + "type": "number" + }, + "reviewId": { + "type": "string" + }, + "reviewer": { + "type": "string" + }, + "revisionNumber": { + "type": "string" + } + }, + "required": [ + "reviewId", + "reviewer", + "revisionNumber" + ], + "type": "object" + }, + "ApprovalStatus": { + "enum": [ + "REVOKED", + "APPROVED" + ], + "type": "string" + }, + "CommentDTO": { + "properties": { + "author": { + "type": "string" + }, + "commentId": { + "type": "string" + }, + "createdAt": { + "format": "double", + "type": "number" + }, + "locationId": { + "type": "string" + }, + "message": { + "type": "string" + }, + "modifiedAt": { + "format": "double", + "type": "number" + }, + "reviewId": { + "type": "string" + }, + "revisionNumber": { + "type": "string" + } + }, + "required": [ + "commentId", + "reviewId", + "revisionNumber" + ], + "type": "object" + }, + "CreateCommentRequestContent": { + "properties": { + "author": { + "type": "string" + }, + "locationId": { + "type": "string" + }, + "message": { + "type": "string" + } + }, + "required": [ + "author", + "message" + ], + "type": "object" + }, + "CreateCommentResponseContent": { + "properties": { + "comment": { + "$ref": "#/components/schemas/CommentDTO" + } + }, + "required": [ + "comment" + ], + "type": "object" + }, + "CreateReviewRequestContent": { + "properties": { + "clientId": { + "type": "string" + }, + "description": { + "type": "string" + }, + "requester": { + "type": "string" + }, + "reviewId": { + "description": "If absent, new reviewId will be generated by the service. If present, new revision number will be generated for the same reviewId", + "type": "string" + }, + "reviewUrl": { + "type": "string" + }, + "reviewers": { + "items": { + "type": "string" + }, + "type": "array" + }, + "title": { + "type": "string" + } + }, + "required": [ + "clientId", + "description", + "requester", + "reviewUrl", + "title" + ], + "type": "object" + }, + "CreateReviewResponseContent": { + "properties": { + "review": { + "$ref": "#/components/schemas/ReviewDTO" + } + }, + "required": [ + "review" + ], + "type": "object" + }, + "GetReviewResponseContent": { + "properties": { + "review": { + "$ref": "#/components/schemas/ReviewDTO" + } + }, + "required": [ + "review" + ], + "type": "object" + }, + "GetRevisionResponseContent": { + "properties": { + "revision": { + "$ref": "#/components/schemas/RevisionDTO" + } + }, + "required": [ + "revision" + ], + "type": "object" + }, + "InvalidInputExceptionResponseContent": { + "properties": { + "message": { + "type": "string" + } + }, + "type": "object" + }, + "ListApprovalResponseContent": { + "properties": { + "approvals": { + "items": { + "$ref": "#/components/schemas/ApprovalDTO" + }, + "type": "array" + }, + "reviewId": { + "type": "string" + }, + "revisionNumber": { + "type": "string" + } + }, + "required": [ + "approvals", + "reviewId", + "revisionNumber" + ], + "type": "object" + }, + "ListCommentResponseContent": { + "properties": { + "comments": { + "items": { + "$ref": "#/components/schemas/CommentDTO" + }, + "type": "array" + }, + "reviewId": { + "type": "string" + }, + "revisionNumber": { + "type": "string" + } + }, + "required": [ + "comments", + "reviewId", + "revisionNumber" + ], + "type": "object" + }, + "PutApprovalRequestContent": { + "properties": { + "approvalStatus": { + "$ref": "#/components/schemas/ApprovalStatus" + }, + "reviewer": { + "type": "string" + } + }, + "required": [ + "approvalStatus", + "reviewer" + ], + "type": "object" + }, + "PutApprovalResponseContent": { + "properties": { + "approval": { + "$ref": "#/components/schemas/ApprovalDTO" + } + }, + "required": [ + "approval" + ], + "type": "object" + }, + "ResourceNotExistExceptionResponseContent": { + "properties": { + "message": { + "type": "string" + } + }, + "type": "object" + }, + "ReviewDTO": { + "properties": { + "approvedRevisionNumber": { + "type": "string" + }, + "createdAt": { + "format": "double", + "type": "number" + }, + "modifiedAt": { + "format": "double", + "type": "number" + }, + "modifiedBy": { + "type": "string" + }, + "requester": { + "type": "string" + }, + "reviewId": { + "type": "string" + }, + "reviewStatus": { + "$ref": "#/components/schemas/ReviewStatus" + }, + "reviewers": { + "items": { + "type": "string" + }, + "type": "array" + }, + "revisionList": { + "items": { + "$ref": "#/components/schemas/RevisionDTO" + }, + "type": "array" + }, + "title": { + "type": "string" + } + }, + "required": [ + "createdAt", + "modifiedAt", + "modifiedBy", + "requester", + "reviewId", + "reviewStatus", + "reviewers", + "revisionList", + "title" + ], + "type": "object" + }, + "ReviewStatus": { + "enum": [ + "OPEN", + "APPROVED" + ], + "type": "string" + }, + "RevisionDTO": { + "properties": { + "createdAt": { + "format": "double", + "type": "number" + }, + "createdBy": { + "type": "string" + }, + "description": { + "type": "string" + }, + "modifiedAt": { + "format": "double", + "type": "number" + }, + "modifiedBy": { + "type": "string" + }, + "reviewId": { + "type": "string" + }, + "reviewUrl": { + "type": "string" + }, + "revisionNumber": { + "type": "string" + }, + "title": { + "type": "string" + } + }, + "required": [ + "createdAt", + "createdBy", + "description", + "modifiedAt", + "modifiedBy", + "reviewId", + "reviewUrl", + "revisionNumber", + "title" + ], + "type": "object" + }, + "echoRequestContent": { + "properties": { + "string": { + "type": "string" + } + }, + "type": "object" + }, + "echoResponseContent": { + "properties": { + "string": { + "type": "string" + } + }, + "type": "object" + } + }, + "securitySchemes": { + "CognitoAuthorizer": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + { + "Fn::GetAtt": "MyCognitoUserPool.Arn" + } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "info": { + "title": "RxtHofApprovalServiceLambdaCognito", + "version": "2018-05-10" + }, + "openapi": "3.0.2", + "paths": { + "/reviews": { + "post": { + "operationId": "CreateReview", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreateReviewRequestContent" + } + } + }, + "required": true + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreateReviewResponseContent" + } + } + }, + "description": "CreateReview 200 response", + "headers": { + "Access-Control-Allow-Origin": { + "schema": { + "type": "string" + } + }, + "Access-Control-Expose-Headers": { + "schema": { + "type": "string" + } + } + } + } + }, + "security": [ + { + "CognitoAuthorizer": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::Sub": "${ApiGatewayCognitoExecutionRole4F7CB5C8.Arn}" + }, + "httpMethod": "POST", + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Origin": "'*'", + "method.response.header.Access-Control-Expose-Headers": "'Content-Length,Content-Type,X-Amzn-Errortype,X-Amzn-Requestid'" + }, + "statusCode": "200" + } + }, + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunction7804BD21.Arn}/invocations" + } + } + } + } + }, + "security": [ + { + "aws.auth.sigv4": [] + } + ], + "x-amazon-apigateway-gateway-responses": { + "DEFAULT_4XX": { + "responseParameters": { + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'" + }, + "responseTemplates": { + "application/json": "{\"message\":$context.error.messageString}" + } + }, + "DEFAULT_5XX": { + "responseParameters": { + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'" + }, + "responseTemplates": { + "application/json": "{\"message\":$context.error.messageString}" + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiGatewayCognitoService15108F0BDeployment2d7acebec7": { + "Properties": { + "Description": "RestApi deployment id: 2d7acebec776defc9c575e70508921389b9d7697", + "RestApiId": { + "Ref": "ApiGatewayCognitoService15108F0B" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ApiGatewayCognitoService15108F0BprodStage": { + "Properties": { + "DeploymentId": { + "Ref": "ApiGatewayCognitoService15108F0BDeployment2d7acebec7" + }, + "MethodSettings": [ + { + "DataTraceEnabled": false, + "HttpMethod": "*", + "LoggingLevel": "INFO", + "MetricsEnabled": false, + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ApiGatewayCognitoService15108F0B" + }, + "StageName": "prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" + }, + "LambdaFunction7804BD21": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event, context, callback) => {\n const auth = event.queryStringParameters.authorization\n const policyDocument = {\n Version: '2012-10-17',\n Statement: [{\n Action: 'execute-api:Invoke',\n Effect: auth && auth.toLowerCase() === 'allow' ? 'Allow' : 'Deny',\n Resource: event.methodArn\n }]\n }\n \n return {\n principalId: 'user',\n context: {},\n policyDocument\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "LambdaFunctionServiceRoleD6E423C9", + "Arn" + ] + }, + "Runtime": "nodejs16.x" + }, + "Type": "AWS::Lambda::Function" + }, + "LambdaFunctionServiceRoleD6E423C9": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "LambdaFunctionServiceRoleDefaultPolicyF01A7EDC": { + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "sns:Publish", + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "LambdaFunctionServiceRoleDefaultPolicyF01A7EDC", + "Roles": [ + { + "Ref": "LambdaFunctionServiceRoleD6E423C9" + } + ] + }, + "Type": "AWS::IAM::Policy" + }, + "MyCognitoUserPool": { + "Properties": { + "UserPoolName": "MyCognitoUserPool" + }, + "Type": "AWS::Cognito::UserPool" + } + } +} diff --git a/tests/translator/output/aws-us-gov/api_open_api_version_match.json b/tests/translator/output/aws-us-gov/api_open_api_version_match.json new file mode 100644 index 0000000000..1676d10f8f --- /dev/null +++ b/tests/translator/output/aws-us-gov/api_open_api_version_match.json @@ -0,0 +1,702 @@ +{ + "Resources": { + "ApiGatewayCognitoAccount64FCB056": { + "Properties": { + "CloudWatchRoleArn": { + "Fn::GetAtt": [ + "ApiGatewayCognitoCloudwatchLoggingRole0DECE2B1", + "Arn" + ] + } + }, + "Type": "AWS::ApiGateway::Account" + }, + "ApiGatewayCognitoCloudwatchLoggingRole0DECE2B1": { + "Metadata": { + "aws:cdk:path": "ApprovalServiceBackendLambdaStack-prod/ApiGatewayCognito/CloudwatchLoggingRole/Resource" + }, + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "apigateway.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs" + ] + ] + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ApiGatewayCognitoExecutionRole4F7CB5C8": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "apigateway.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "Policies": [ + { + "PolicyDocument": { + "Statement": [ + { + "Action": "lambda:Invoke*", + "Effect": "Allow", + "Resource": { + "Fn::GetAtt": [ + "LambdaFunction7804BD21", + "Arn" + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "apigInvokeLambda" + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "ApiGatewayCognitoService15108F0B": { + "DependsOn": [ + "ApiGatewayCognitoAccount64FCB056" + ], + "Properties": { + "Body": { + "components": { + "schemas": { + "ApprovalDTO": { + "properties": { + "approvalStatus": { + "$ref": "#/components/schemas/ApprovalStatus" + }, + "createdAt": { + "format": "double", + "type": "number" + }, + "modifiedAt": { + "format": "double", + "type": "number" + }, + "reviewId": { + "type": "string" + }, + "reviewer": { + "type": "string" + }, + "revisionNumber": { + "type": "string" + } + }, + "required": [ + "reviewId", + "reviewer", + "revisionNumber" + ], + "type": "object" + }, + "ApprovalStatus": { + "enum": [ + "REVOKED", + "APPROVED" + ], + "type": "string" + }, + "CommentDTO": { + "properties": { + "author": { + "type": "string" + }, + "commentId": { + "type": "string" + }, + "createdAt": { + "format": "double", + "type": "number" + }, + "locationId": { + "type": "string" + }, + "message": { + "type": "string" + }, + "modifiedAt": { + "format": "double", + "type": "number" + }, + "reviewId": { + "type": "string" + }, + "revisionNumber": { + "type": "string" + } + }, + "required": [ + "commentId", + "reviewId", + "revisionNumber" + ], + "type": "object" + }, + "CreateCommentRequestContent": { + "properties": { + "author": { + "type": "string" + }, + "locationId": { + "type": "string" + }, + "message": { + "type": "string" + } + }, + "required": [ + "author", + "message" + ], + "type": "object" + }, + "CreateCommentResponseContent": { + "properties": { + "comment": { + "$ref": "#/components/schemas/CommentDTO" + } + }, + "required": [ + "comment" + ], + "type": "object" + }, + "CreateReviewRequestContent": { + "properties": { + "clientId": { + "type": "string" + }, + "description": { + "type": "string" + }, + "requester": { + "type": "string" + }, + "reviewId": { + "description": "If absent, new reviewId will be generated by the service. If present, new revision number will be generated for the same reviewId", + "type": "string" + }, + "reviewUrl": { + "type": "string" + }, + "reviewers": { + "items": { + "type": "string" + }, + "type": "array" + }, + "title": { + "type": "string" + } + }, + "required": [ + "clientId", + "description", + "requester", + "reviewUrl", + "title" + ], + "type": "object" + }, + "CreateReviewResponseContent": { + "properties": { + "review": { + "$ref": "#/components/schemas/ReviewDTO" + } + }, + "required": [ + "review" + ], + "type": "object" + }, + "GetReviewResponseContent": { + "properties": { + "review": { + "$ref": "#/components/schemas/ReviewDTO" + } + }, + "required": [ + "review" + ], + "type": "object" + }, + "GetRevisionResponseContent": { + "properties": { + "revision": { + "$ref": "#/components/schemas/RevisionDTO" + } + }, + "required": [ + "revision" + ], + "type": "object" + }, + "InvalidInputExceptionResponseContent": { + "properties": { + "message": { + "type": "string" + } + }, + "type": "object" + }, + "ListApprovalResponseContent": { + "properties": { + "approvals": { + "items": { + "$ref": "#/components/schemas/ApprovalDTO" + }, + "type": "array" + }, + "reviewId": { + "type": "string" + }, + "revisionNumber": { + "type": "string" + } + }, + "required": [ + "approvals", + "reviewId", + "revisionNumber" + ], + "type": "object" + }, + "ListCommentResponseContent": { + "properties": { + "comments": { + "items": { + "$ref": "#/components/schemas/CommentDTO" + }, + "type": "array" + }, + "reviewId": { + "type": "string" + }, + "revisionNumber": { + "type": "string" + } + }, + "required": [ + "comments", + "reviewId", + "revisionNumber" + ], + "type": "object" + }, + "PutApprovalRequestContent": { + "properties": { + "approvalStatus": { + "$ref": "#/components/schemas/ApprovalStatus" + }, + "reviewer": { + "type": "string" + } + }, + "required": [ + "approvalStatus", + "reviewer" + ], + "type": "object" + }, + "PutApprovalResponseContent": { + "properties": { + "approval": { + "$ref": "#/components/schemas/ApprovalDTO" + } + }, + "required": [ + "approval" + ], + "type": "object" + }, + "ResourceNotExistExceptionResponseContent": { + "properties": { + "message": { + "type": "string" + } + }, + "type": "object" + }, + "ReviewDTO": { + "properties": { + "approvedRevisionNumber": { + "type": "string" + }, + "createdAt": { + "format": "double", + "type": "number" + }, + "modifiedAt": { + "format": "double", + "type": "number" + }, + "modifiedBy": { + "type": "string" + }, + "requester": { + "type": "string" + }, + "reviewId": { + "type": "string" + }, + "reviewStatus": { + "$ref": "#/components/schemas/ReviewStatus" + }, + "reviewers": { + "items": { + "type": "string" + }, + "type": "array" + }, + "revisionList": { + "items": { + "$ref": "#/components/schemas/RevisionDTO" + }, + "type": "array" + }, + "title": { + "type": "string" + } + }, + "required": [ + "createdAt", + "modifiedAt", + "modifiedBy", + "requester", + "reviewId", + "reviewStatus", + "reviewers", + "revisionList", + "title" + ], + "type": "object" + }, + "ReviewStatus": { + "enum": [ + "OPEN", + "APPROVED" + ], + "type": "string" + }, + "RevisionDTO": { + "properties": { + "createdAt": { + "format": "double", + "type": "number" + }, + "createdBy": { + "type": "string" + }, + "description": { + "type": "string" + }, + "modifiedAt": { + "format": "double", + "type": "number" + }, + "modifiedBy": { + "type": "string" + }, + "reviewId": { + "type": "string" + }, + "reviewUrl": { + "type": "string" + }, + "revisionNumber": { + "type": "string" + }, + "title": { + "type": "string" + } + }, + "required": [ + "createdAt", + "createdBy", + "description", + "modifiedAt", + "modifiedBy", + "reviewId", + "reviewUrl", + "revisionNumber", + "title" + ], + "type": "object" + }, + "echoRequestContent": { + "properties": { + "string": { + "type": "string" + } + }, + "type": "object" + }, + "echoResponseContent": { + "properties": { + "string": { + "type": "string" + } + }, + "type": "object" + } + }, + "securitySchemes": { + "CognitoAuthorizer": { + "in": "header", + "name": "Authorization", + "type": "apiKey", + "x-amazon-apigateway-authorizer": { + "providerARNs": [ + { + "Fn::GetAtt": "MyCognitoUserPool.Arn" + } + ], + "type": "cognito_user_pools" + }, + "x-amazon-apigateway-authtype": "cognito_user_pools" + } + } + }, + "info": { + "title": "RxtHofApprovalServiceLambdaCognito", + "version": "2018-05-10" + }, + "openapi": "3.0.2", + "paths": { + "/reviews": { + "post": { + "operationId": "CreateReview", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreateReviewRequestContent" + } + } + }, + "required": true + }, + "responses": { + "200": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/CreateReviewResponseContent" + } + } + }, + "description": "CreateReview 200 response", + "headers": { + "Access-Control-Allow-Origin": { + "schema": { + "type": "string" + } + }, + "Access-Control-Expose-Headers": { + "schema": { + "type": "string" + } + } + } + } + }, + "security": [ + { + "CognitoAuthorizer": [] + } + ], + "x-amazon-apigateway-integration": { + "credentials": { + "Fn::Sub": "${ApiGatewayCognitoExecutionRole4F7CB5C8.Arn}" + }, + "httpMethod": "POST", + "responses": { + "default": { + "responseParameters": { + "method.response.header.Access-Control-Allow-Origin": "'*'", + "method.response.header.Access-Control-Expose-Headers": "'Content-Length,Content-Type,X-Amzn-Errortype,X-Amzn-Requestid'" + }, + "statusCode": "200" + } + }, + "type": "aws_proxy", + "uri": { + "Fn::Sub": "arn:${AWS::Partition}:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${LambdaFunction7804BD21.Arn}/invocations" + } + } + } + } + }, + "security": [ + { + "aws.auth.sigv4": [] + } + ], + "x-amazon-apigateway-gateway-responses": { + "DEFAULT_4XX": { + "responseParameters": { + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'" + }, + "responseTemplates": { + "application/json": "{\"message\":$context.error.messageString}" + } + }, + "DEFAULT_5XX": { + "responseParameters": { + "gatewayresponse.header.Access-Control-Allow-Origin": "'*'" + }, + "responseTemplates": { + "application/json": "{\"message\":$context.error.messageString}" + } + } + } + }, + "EndpointConfiguration": { + "Types": [ + "REGIONAL" + ] + }, + "Parameters": { + "endpointConfigurationTypes": "REGIONAL" + } + }, + "Type": "AWS::ApiGateway::RestApi" + }, + "ApiGatewayCognitoService15108F0BDeployment2d7acebec7": { + "Properties": { + "Description": "RestApi deployment id: 2d7acebec776defc9c575e70508921389b9d7697", + "RestApiId": { + "Ref": "ApiGatewayCognitoService15108F0B" + } + }, + "Type": "AWS::ApiGateway::Deployment" + }, + "ApiGatewayCognitoService15108F0BprodStage": { + "Properties": { + "DeploymentId": { + "Ref": "ApiGatewayCognitoService15108F0BDeployment2d7acebec7" + }, + "MethodSettings": [ + { + "DataTraceEnabled": false, + "HttpMethod": "*", + "LoggingLevel": "INFO", + "MetricsEnabled": false, + "ResourcePath": "/*" + } + ], + "RestApiId": { + "Ref": "ApiGatewayCognitoService15108F0B" + }, + "StageName": "prod", + "TracingEnabled": true + }, + "Type": "AWS::ApiGateway::Stage" + }, + "LambdaFunction7804BD21": { + "Properties": { + "Code": { + "ZipFile": "exports.handler = async (event, context, callback) => {\n const auth = event.queryStringParameters.authorization\n const policyDocument = {\n Version: '2012-10-17',\n Statement: [{\n Action: 'execute-api:Invoke',\n Effect: auth && auth.toLowerCase() === 'allow' ? 'Allow' : 'Deny',\n Resource: event.methodArn\n }]\n }\n \n return {\n principalId: 'user',\n context: {},\n policyDocument\n }\n}\n" + }, + "Handler": "index.handler", + "Role": { + "Fn::GetAtt": [ + "LambdaFunctionServiceRoleD6E423C9", + "Arn" + ] + }, + "Runtime": "nodejs16.x" + }, + "Type": "AWS::Lambda::Function" + }, + "LambdaFunctionServiceRoleD6E423C9": { + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + }, + "Type": "AWS::IAM::Role" + }, + "LambdaFunctionServiceRoleDefaultPolicyF01A7EDC": { + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "sns:Publish", + "Effect": "Allow", + "Resource": "*" + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "LambdaFunctionServiceRoleDefaultPolicyF01A7EDC", + "Roles": [ + { + "Ref": "LambdaFunctionServiceRoleD6E423C9" + } + ] + }, + "Type": "AWS::IAM::Policy" + }, + "MyCognitoUserPool": { + "Properties": { + "UserPoolName": "MyCognitoUserPool" + }, + "Type": "AWS::Cognito::UserPool" + } + } +} diff --git a/tests/translator/output/error_api_open_api_version_not_match.json b/tests/translator/output/error_api_open_api_version_not_match.json new file mode 100644 index 0000000000..98385d9f20 --- /dev/null +++ b/tests/translator/output/error_api_open_api_version_not_match.json @@ -0,0 +1,14 @@ +{ + "_autoGeneratedBreakdownErrorMessage": [ + "Invalid Serverless Application Specification document. ", + "Number of errors found: 1. ", + "Resource with id [ApiGatewayCognitoService15108F0B] is invalid. ", + "OpenApiVersion property doesn't match openapi value in 'DefinitionBody'." + ], + "errorMessage": "Invalid Serverless Application Specification document. Number of errors found: 1. Resource with id [ApiGatewayCognitoService15108F0B] is invalid. OpenApiVersion property doesn't match openapi value in 'DefinitionBody'.", + "errors": [ + { + "errorMessage": "Resource with id [ApiGatewayCognitoService15108F0B] is invalid. OpenApiVersion property doesn't match openapi value in 'DefinitionBody'." + } + ] +}