diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/integ.json deleted file mode 100644 index f9839a21e207c..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/integ.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "version": "36.0.0", - "testCases": { - "restapi-import-deployment-stage/DefaultTest": { - "stacks": [ - "integtest-restapi-import-deployment-stage" - ], - "assertionStack": "restapi-import-deployment-stage/DefaultTest/DeployAssert", - "assertionStackName": "restapiimportdeploymentstageDefaultTestDeployAssertC7BBBF60" - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/integtest-restapi-import-deployment-stage.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/integtest-restapi-import-deployment-stage.template.json deleted file mode 100644 index 8478cc7befcd1..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/integtest-restapi-import-deployment-stage.template.json +++ /dev/null @@ -1,75 +0,0 @@ -{ - "Resources": { - "myapi4C7BF186": { - "Type": "AWS::ApiGateway::RestApi", - "Properties": { - "Name": "my-api" - } - }, - "myapiGETF990CE3C": { - "Type": "AWS::ApiGateway::Method", - "Properties": { - "AuthorizationType": "NONE", - "HttpMethod": "GET", - "Integration": { - "Type": "MOCK" - }, - "ResourceId": { - "Fn::GetAtt": [ - "myapi4C7BF186", - "RootResourceId" - ] - }, - "RestApiId": { - "Ref": "myapi4C7BF186" - } - } - }, - "MyManualDeployment92F2175C6f3141cef1e8fea8ab3b3b8bc90df36d": { - "Type": "AWS::ApiGateway::Deployment", - "Properties": { - "RestApiId": { - "Ref": "myapi4C7BF186" - }, - "StageName": "myStage" - }, - "DependsOn": [ - "myapiGETF990CE3C" - ] - } - }, - "Parameters": { - "BootstrapVersion": { - "Type": "AWS::SSM::Parameter::Value", - "Default": "/cdk-bootstrap/hnb659fds/version", - "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" - } - }, - "Rules": { - "CheckBootstrapVersion": { - "Assertions": [ - { - "Assert": { - "Fn::Not": [ - { - "Fn::Contains": [ - [ - "1", - "2", - "3", - "4", - "5" - ], - { - "Ref": "BootstrapVersion" - } - ] - } - ] - }, - "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." - } - ] - } - } -} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.ts deleted file mode 100644 index ab831188702b9..0000000000000 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.ts +++ /dev/null @@ -1,24 +0,0 @@ -import * as cdk from 'aws-cdk-lib/core'; -import * as apigateway from 'aws-cdk-lib/aws-apigateway'; -import * as integ from '@aws-cdk/integ-tests-alpha'; - -const app = new cdk.App(); -const stack = new cdk.Stack(app, 'integtest-restapi-import-deployment-stage'); - -// Set deploy to false so RestApi does not automatically create a Deployment -const api = new apigateway.RestApi(stack, 'my-api', { - deploy: false, -}); -api.root.addMethod('GET'); - -// Manually create a deployment that deploys to an existing stage -new apigateway.Deployment(stack, 'MyManualDeployment', { - api: api, - stageName: 'myStage', -}); - -new integ.IntegTest(app, 'restapi-import-deployment-stage', { - testCases: [stack], -}); - -app.synth(); \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/cdk.out b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/cdk.out similarity index 100% rename from packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/cdk.out rename to packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/cdk.out diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/integ.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/integ.json new file mode 100644 index 0000000000000..cb8e28c865d4e --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/integ.json @@ -0,0 +1,12 @@ +{ + "version": "36.0.0", + "testCases": { + "specrestapi-import-deployment-stage/DefaultTest": { + "stacks": [ + "integtest-specrestapi-import-deployment-stage" + ], + "assertionStack": "specrestapi-import-deployment-stage/DefaultTest/DeployAssert", + "assertionStackName": "specrestapiimportdeploymentstageDefaultTestDeployAssert410B3AFA" + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/integtest-restapi-import-deployment-stage.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/integtest-specrestapi-import-deployment-stage.assets.json similarity index 63% rename from packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/integtest-restapi-import-deployment-stage.assets.json rename to packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/integtest-specrestapi-import-deployment-stage.assets.json index 872628ace4441..758197d57fc76 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/integtest-restapi-import-deployment-stage.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/integtest-specrestapi-import-deployment-stage.assets.json @@ -1,15 +1,15 @@ { "version": "36.0.0", "files": { - "3bd472ac3fdbd7c291e3c4ef13df0429da6c1e0717dde5b304790b77637a72c3": { + "963d95f2b946c101b476b2c2b3faa935244354f27c8cef2c0d0a8215cc5f816b": { "source": { - "path": "integtest-restapi-import-deployment-stage.template.json", + "path": "integtest-specrestapi-import-deployment-stage.template.json", "packaging": "file" }, "destinations": { "current_account-current_region": { "bucketName": "cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}", - "objectKey": "3bd472ac3fdbd7c291e3c4ef13df0429da6c1e0717dde5b304790b77637a72c3.json", + "objectKey": "963d95f2b946c101b476b2c2b3faa935244354f27c8cef2c0d0a8215cc5f816b.json", "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-file-publishing-role-${AWS::AccountId}-${AWS::Region}" } } diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/integtest-specrestapi-import-deployment-stage.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/integtest-specrestapi-import-deployment-stage.template.json new file mode 100644 index 0000000000000..39f11c55ecd7c --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/integtest-specrestapi-import-deployment-stage.template.json @@ -0,0 +1,100 @@ +{ + "Resources": { + "myapi4C7BF186": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Body": { + "openapi": "3.0.2", + "info": { + "version": "1.0.0", + "title": "Test API for CDK" + }, + "paths": { + "/pets": { + "get": { + "summary": "Test Method", + "operationId": "testMethod", + "responses": { + "200": { + "description": "A paged array of pets", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Empty" + } + } + } + } + }, + "x-amazon-apigateway-integration": { + "responses": { + "default": { + "statusCode": "200" + } + }, + "requestTemplates": { + "application/json": "{\"statusCode\": 200}" + }, + "passthroughBehavior": "when_no_match", + "type": "mock" + } + } + } + }, + "components": { + "schemas": { + "Empty": { + "title": "Empty Schema", + "type": "object" + } + } + } + }, + "Name": "my-api" + } + }, + "MyManualDeployment92F2175C1dcdcb8f1c24d86b6090e78df1fafcd3": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "myapi4C7BF186" + }, + "StageName": "myStage" + } + } + }, + "Parameters": { + "BootstrapVersion": { + "Type": "AWS::SSM::Parameter::Value", + "Default": "/cdk-bootstrap/hnb659fds/version", + "Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]" + } + }, + "Rules": { + "CheckBootstrapVersion": { + "Assertions": [ + { + "Assert": { + "Fn::Not": [ + { + "Fn::Contains": [ + [ + "1", + "2", + "3", + "4", + "5" + ], + { + "Ref": "BootstrapVersion" + } + ] + } + ] + }, + "AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI." + } + ] + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/manifest.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/manifest.json similarity index 61% rename from packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/manifest.json rename to packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/manifest.json index 1193124952547..2159288d8af91 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/manifest.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/manifest.json @@ -1,28 +1,28 @@ { "version": "36.0.0", "artifacts": { - "integtest-restapi-import-deployment-stage.assets": { + "integtest-specrestapi-import-deployment-stage.assets": { "type": "cdk:asset-manifest", "properties": { - "file": "integtest-restapi-import-deployment-stage.assets.json", + "file": "integtest-specrestapi-import-deployment-stage.assets.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" } }, - "integtest-restapi-import-deployment-stage": { + "integtest-specrestapi-import-deployment-stage": { "type": "aws:cloudformation:stack", "environment": "aws://unknown-account/unknown-region", "properties": { - "templateFile": "integtest-restapi-import-deployment-stage.template.json", + "templateFile": "integtest-specrestapi-import-deployment-stage.template.json", "terminationProtection": false, "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", "cloudFormationExecutionRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-cfn-exec-role-${AWS::AccountId}-${AWS::Region}", - "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/3bd472ac3fdbd7c291e3c4ef13df0429da6c1e0717dde5b304790b77637a72c3.json", + "stackTemplateAssetObjectUrl": "s3://cdk-hnb659fds-assets-${AWS::AccountId}-${AWS::Region}/963d95f2b946c101b476b2c2b3faa935244354f27c8cef2c0d0a8215cc5f816b.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ - "integtest-restapi-import-deployment-stage.assets" + "integtest-specrestapi-import-deployment-stage.assets" ], "lookupRole": { "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", @@ -31,64 +31,49 @@ } }, "dependencies": [ - "integtest-restapi-import-deployment-stage.assets" + "integtest-specrestapi-import-deployment-stage.assets" ], "metadata": { - "/integtest-restapi-import-deployment-stage/my-api/Resource": [ + "/integtest-specrestapi-import-deployment-stage/my-api/Resource": [ { "type": "aws:cdk:logicalId", "data": "myapi4C7BF186" } ], - "/integtest-restapi-import-deployment-stage/my-api/Default/GET/Resource": [ + "/integtest-specrestapi-import-deployment-stage/MyManualDeployment/Resource": [ { "type": "aws:cdk:logicalId", - "data": "myapiGETF990CE3C" + "data": "MyManualDeployment92F2175C1dcdcb8f1c24d86b6090e78df1fafcd3" } ], - "/integtest-restapi-import-deployment-stage/MyManualDeployment/Resource": [ - { - "type": "aws:cdk:logicalId", - "data": "MyManualDeployment92F2175C6f3141cef1e8fea8ab3b3b8bc90df36d" - } - ], - "/integtest-restapi-import-deployment-stage/BootstrapVersion": [ + "/integtest-specrestapi-import-deployment-stage/BootstrapVersion": [ { "type": "aws:cdk:logicalId", "data": "BootstrapVersion" } ], - "/integtest-restapi-import-deployment-stage/CheckBootstrapVersion": [ + "/integtest-specrestapi-import-deployment-stage/CheckBootstrapVersion": [ { "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } - ], - "MyManualDeployment92F2175C35a2644115e0765ad867f11b599a51c1": [ - { - "type": "aws:cdk:logicalId", - "data": "MyManualDeployment92F2175C35a2644115e0765ad867f11b599a51c1", - "trace": [ - "!!DESTRUCTIVE_CHANGES: WILL_DESTROY" - ] - } ] }, - "displayName": "integtest-restapi-import-deployment-stage" + "displayName": "integtest-specrestapi-import-deployment-stage" }, - "restapiimportdeploymentstageDefaultTestDeployAssertC7BBBF60.assets": { + "specrestapiimportdeploymentstageDefaultTestDeployAssert410B3AFA.assets": { "type": "cdk:asset-manifest", "properties": { - "file": "restapiimportdeploymentstageDefaultTestDeployAssertC7BBBF60.assets.json", + "file": "specrestapiimportdeploymentstageDefaultTestDeployAssert410B3AFA.assets.json", "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version" } }, - "restapiimportdeploymentstageDefaultTestDeployAssertC7BBBF60": { + "specrestapiimportdeploymentstageDefaultTestDeployAssert410B3AFA": { "type": "aws:cloudformation:stack", "environment": "aws://unknown-account/unknown-region", "properties": { - "templateFile": "restapiimportdeploymentstageDefaultTestDeployAssertC7BBBF60.template.json", + "templateFile": "specrestapiimportdeploymentstageDefaultTestDeployAssert410B3AFA.template.json", "terminationProtection": false, "validateOnSynth": false, "assumeRoleArn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-deploy-role-${AWS::AccountId}-${AWS::Region}", @@ -97,7 +82,7 @@ "requiresBootstrapStackVersion": 6, "bootstrapStackVersionSsmParameter": "/cdk-bootstrap/hnb659fds/version", "additionalDependencies": [ - "restapiimportdeploymentstageDefaultTestDeployAssertC7BBBF60.assets" + "specrestapiimportdeploymentstageDefaultTestDeployAssert410B3AFA.assets" ], "lookupRole": { "arn": "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-hnb659fds-lookup-role-${AWS::AccountId}-${AWS::Region}", @@ -106,23 +91,23 @@ } }, "dependencies": [ - "restapiimportdeploymentstageDefaultTestDeployAssertC7BBBF60.assets" + "specrestapiimportdeploymentstageDefaultTestDeployAssert410B3AFA.assets" ], "metadata": { - "/restapi-import-deployment-stage/DefaultTest/DeployAssert/BootstrapVersion": [ + "/specrestapi-import-deployment-stage/DefaultTest/DeployAssert/BootstrapVersion": [ { "type": "aws:cdk:logicalId", "data": "BootstrapVersion" } ], - "/restapi-import-deployment-stage/DefaultTest/DeployAssert/CheckBootstrapVersion": [ + "/specrestapi-import-deployment-stage/DefaultTest/DeployAssert/CheckBootstrapVersion": [ { "type": "aws:cdk:logicalId", "data": "CheckBootstrapVersion" } ] }, - "displayName": "restapi-import-deployment-stage/DefaultTest/DeployAssert" + "displayName": "specrestapi-import-deployment-stage/DefaultTest/DeployAssert" }, "Tree": { "type": "cdk:tree", diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/restapiimportdeploymentstageDefaultTestDeployAssertC7BBBF60.assets.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/specrestapiimportdeploymentstageDefaultTestDeployAssert410B3AFA.assets.json similarity index 86% rename from packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/restapiimportdeploymentstageDefaultTestDeployAssertC7BBBF60.assets.json rename to packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/specrestapiimportdeploymentstageDefaultTestDeployAssert410B3AFA.assets.json index 6824dd5c38417..66b1d8fe0cbf8 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/restapiimportdeploymentstageDefaultTestDeployAssertC7BBBF60.assets.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/specrestapiimportdeploymentstageDefaultTestDeployAssert410B3AFA.assets.json @@ -3,7 +3,7 @@ "files": { "21fbb51d7b23f6a6c262b46a9caee79d744a3ac019fd45422d988b96d44b2a22": { "source": { - "path": "restapiimportdeploymentstageDefaultTestDeployAssertC7BBBF60.template.json", + "path": "specrestapiimportdeploymentstageDefaultTestDeployAssert410B3AFA.template.json", "packaging": "file" }, "destinations": { diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/restapiimportdeploymentstageDefaultTestDeployAssertC7BBBF60.template.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/specrestapiimportdeploymentstageDefaultTestDeployAssert410B3AFA.template.json similarity index 100% rename from packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/restapiimportdeploymentstageDefaultTestDeployAssertC7BBBF60.template.json rename to packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/specrestapiimportdeploymentstageDefaultTestDeployAssert410B3AFA.template.json diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/tree.json b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/tree.json similarity index 56% rename from packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/tree.json rename to packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/tree.json index 59fa3c93fb757..32f9eed0afe35 100644 --- a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.import-deploymentstage.js.snapshot/tree.json +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.js.snapshot/tree.json @@ -4,20 +4,67 @@ "id": "App", "path": "", "children": { - "integtest-restapi-import-deployment-stage": { - "id": "integtest-restapi-import-deployment-stage", - "path": "integtest-restapi-import-deployment-stage", + "integtest-specrestapi-import-deployment-stage": { + "id": "integtest-specrestapi-import-deployment-stage", + "path": "integtest-specrestapi-import-deployment-stage", "children": { "my-api": { "id": "my-api", - "path": "integtest-restapi-import-deployment-stage/my-api", + "path": "integtest-specrestapi-import-deployment-stage/my-api", "children": { "Resource": { "id": "Resource", - "path": "integtest-restapi-import-deployment-stage/my-api/Resource", + "path": "integtest-specrestapi-import-deployment-stage/my-api/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::ApiGateway::RestApi", "aws:cdk:cloudformation:props": { + "body": { + "openapi": "3.0.2", + "info": { + "version": "1.0.0", + "title": "Test API for CDK" + }, + "paths": { + "/pets": { + "get": { + "summary": "Test Method", + "operationId": "testMethod", + "responses": { + "200": { + "description": "A paged array of pets", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Empty" + } + } + } + } + }, + "x-amazon-apigateway-integration": { + "responses": { + "default": { + "statusCode": "200" + } + }, + "requestTemplates": { + "application/json": "{\"statusCode\": 200}" + }, + "passthroughBehavior": "when_no_match", + "type": "mock" + } + } + } + }, + "components": { + "schemas": { + "Empty": { + "title": "Empty Schema", + "type": "object" + } + } + } + }, "name": "my-api" } }, @@ -28,46 +75,7 @@ }, "Default": { "id": "Default", - "path": "integtest-restapi-import-deployment-stage/my-api/Default", - "children": { - "GET": { - "id": "GET", - "path": "integtest-restapi-import-deployment-stage/my-api/Default/GET", - "children": { - "Resource": { - "id": "Resource", - "path": "integtest-restapi-import-deployment-stage/my-api/Default/GET/Resource", - "attributes": { - "aws:cdk:cloudformation:type": "AWS::ApiGateway::Method", - "aws:cdk:cloudformation:props": { - "authorizationType": "NONE", - "httpMethod": "GET", - "integration": { - "type": "MOCK" - }, - "resourceId": { - "Fn::GetAtt": [ - "myapi4C7BF186", - "RootResourceId" - ] - }, - "restApiId": { - "Ref": "myapi4C7BF186" - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.aws_apigateway.CfnMethod", - "version": "0.0.0" - } - } - }, - "constructInfo": { - "fqn": "aws-cdk-lib.aws_apigateway.Method", - "version": "0.0.0" - } - } - }, + "path": "integtest-specrestapi-import-deployment-stage/my-api/Default", "constructInfo": { "fqn": "aws-cdk-lib.aws_apigateway.ResourceBase", "version": "0.0.0" @@ -75,17 +83,17 @@ } }, "constructInfo": { - "fqn": "aws-cdk-lib.aws_apigateway.RestApi", + "fqn": "aws-cdk-lib.aws_apigateway.SpecRestApi", "version": "0.0.0" } }, "MyManualDeployment": { "id": "MyManualDeployment", - "path": "integtest-restapi-import-deployment-stage/MyManualDeployment", + "path": "integtest-specrestapi-import-deployment-stage/MyManualDeployment", "children": { "Resource": { "id": "Resource", - "path": "integtest-restapi-import-deployment-stage/MyManualDeployment/Resource", + "path": "integtest-specrestapi-import-deployment-stage/MyManualDeployment/Resource", "attributes": { "aws:cdk:cloudformation:type": "AWS::ApiGateway::Deployment", "aws:cdk:cloudformation:props": { @@ -108,7 +116,7 @@ }, "BootstrapVersion": { "id": "BootstrapVersion", - "path": "integtest-restapi-import-deployment-stage/BootstrapVersion", + "path": "integtest-specrestapi-import-deployment-stage/BootstrapVersion", "constructInfo": { "fqn": "aws-cdk-lib.CfnParameter", "version": "0.0.0" @@ -116,7 +124,7 @@ }, "CheckBootstrapVersion": { "id": "CheckBootstrapVersion", - "path": "integtest-restapi-import-deployment-stage/CheckBootstrapVersion", + "path": "integtest-specrestapi-import-deployment-stage/CheckBootstrapVersion", "constructInfo": { "fqn": "aws-cdk-lib.CfnRule", "version": "0.0.0" @@ -128,17 +136,17 @@ "version": "0.0.0" } }, - "restapi-import-deployment-stage": { - "id": "restapi-import-deployment-stage", - "path": "restapi-import-deployment-stage", + "specrestapi-import-deployment-stage": { + "id": "specrestapi-import-deployment-stage", + "path": "specrestapi-import-deployment-stage", "children": { "DefaultTest": { "id": "DefaultTest", - "path": "restapi-import-deployment-stage/DefaultTest", + "path": "specrestapi-import-deployment-stage/DefaultTest", "children": { "Default": { "id": "Default", - "path": "restapi-import-deployment-stage/DefaultTest/Default", + "path": "specrestapi-import-deployment-stage/DefaultTest/Default", "constructInfo": { "fqn": "constructs.Construct", "version": "10.3.0" @@ -146,11 +154,11 @@ }, "DeployAssert": { "id": "DeployAssert", - "path": "restapi-import-deployment-stage/DefaultTest/DeployAssert", + "path": "specrestapi-import-deployment-stage/DefaultTest/DeployAssert", "children": { "BootstrapVersion": { "id": "BootstrapVersion", - "path": "restapi-import-deployment-stage/DefaultTest/DeployAssert/BootstrapVersion", + "path": "specrestapi-import-deployment-stage/DefaultTest/DeployAssert/BootstrapVersion", "constructInfo": { "fqn": "aws-cdk-lib.CfnParameter", "version": "0.0.0" @@ -158,7 +166,7 @@ }, "CheckBootstrapVersion": { "id": "CheckBootstrapVersion", - "path": "restapi-import-deployment-stage/DefaultTest/DeployAssert/CheckBootstrapVersion", + "path": "specrestapi-import-deployment-stage/DefaultTest/DeployAssert/CheckBootstrapVersion", "constructInfo": { "fqn": "aws-cdk-lib.CfnRule", "version": "0.0.0" diff --git a/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.ts b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.ts new file mode 100644 index 0000000000000..c465064381eae --- /dev/null +++ b/packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.spec-restapi.import-deploymentstage.ts @@ -0,0 +1,74 @@ +import * as cdk from 'aws-cdk-lib/core'; +import * as apigateway from 'aws-cdk-lib/aws-apigateway'; +import * as integ from '@aws-cdk/integ-tests-alpha'; + +const app = new cdk.App(); +const stack = new cdk.Stack(app, 'integtest-specrestapi-import-deployment-stage'); + +const apiDefinition = { + openapi: '3.0.2', + info: { + version: '1.0.0', + title: 'Test API for CDK', + }, + paths: { + '/pets': { + get: { + 'summary': 'Test Method', + 'operationId': 'testMethod', + 'responses': { + 200: { + description: 'A paged array of pets', + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/Empty', + }, + }, + }, + }, + }, + 'x-amazon-apigateway-integration': { + responses: { + default: { + statusCode: '200', + }, + }, + requestTemplates: { + 'application/json': '{"statusCode": 200}', + }, + passthroughBehavior: 'when_no_match', + type: 'mock', + }, + }, + }, + }, + components: { + schemas: { + Empty: { + title: 'Empty Schema', + type: 'object', + }, + }, + }, +}; + +// Set deploy to false so SpecRestApi does not automatically create a Deployment +const api = new apigateway.SpecRestApi(stack, 'my-api', { + deploy: false, + apiDefinition: apigateway.ApiDefinition.fromInline(apiDefinition), +}); + +// Manually create a deployment that deploys to an existing stage +const deployment = new apigateway.Deployment(stack, 'MyManualDeployment', { + api: api, + stageName: 'myStage', +}); + +deployment.addToLogicalId(apiDefinition); + +new integ.IntegTest(app, 'specrestapi-import-deployment-stage', { + testCases: [stack], +}); + +app.synth(); \ No newline at end of file diff --git a/packages/aws-cdk-lib/aws-apigateway/README.md b/packages/aws-cdk-lib/aws-apigateway/README.md index 6534c53ef0ff7..9d97646885e5b 100644 --- a/packages/aws-cdk-lib/aws-apigateway/README.md +++ b/packages/aws-cdk-lib/aws-apigateway/README.md @@ -1002,11 +1002,13 @@ const api = new apigateway.RestApi(this, 'books', { ``` ### Deploying to an existing stage -If you want to use an existing stage for a deployment, first set `{ deploy: false }` so that `RestApi` does not automatically create new `Deployment` and `Stage` resources. Then you can manually define a `apigateway.Deployment` resource and specify the stage name for your existing stage using the `stageName` property. +#### Using RestApi -Note that as long as the deployment's logical ID doesn't change, it will represent the snapshot in time when the resource was created. If you update the `stageName` property, you should be triggering a new deployment (i.e. with an updated logical ID). To ensure your deployment reflects changes to the `RestApi` model, see [Controlled triggering of deployments](#controlled-triggering-of-deployments). +If you want to use an existing stage to deploy your `RestApi`, first set `{ deploy: false }` so the construct doesn't automatically create new `Deployment` and `Stage` resources. Then you can manually define a `apigateway.Deployment` resource and specify the stage name for your existing stage using the `stageName` property. + +Note that as long as the deployment's logical ID doesn't change, it will represent the snapshot in time when the resource was created. To ensure your deployment reflects changes to the `RestApi` model, see [Controlled triggering of deployments](#controlled-triggering-of-deployments). ```ts -const restApi = new apigateway.RestApi(this, 'my-api', { +const restApi = new apigateway.RestApi(this, 'my-rest-api', { deploy: false, }); @@ -1017,9 +1019,33 @@ const deployment = new apigateway.Deployment(this, 'my-deployment', { retainDeployments: true, // keep old deployments }); ``` +#### Using SpecRestApi +If you want to use an existing stage to deploy your `SpecRestApi`, first set `{ deploy: false }` so the construct doesn't automatically create new `Deployment` and `Stage` resources. Then you can manually define a `apigateway.Deployment` resource and specify the stage name for your existing stage using the `stageName` property. + +To automatically create a new deployment that reflects the latest API changes, you can use the `addToLogicalId()` method and pass in your OpenAPI definition. + +```ts +const myApiDefinition = apigateway.ApiDefinition.fromAsset('path-to-file.json'); +const specRestApi = new apigateway.SpecRestApi(this, 'my-specrest-api', { + deploy: false, + apiDefinition: myApiDefinition +}); + +// Use `stageName` to deploy to an existing stage +const deployment = new apigateway.Deployment(this, 'my-deployment', { + api: specRestApi, + stageName: 'dev', + retainDeployments: true, // keep old deployments +}); + +// Trigger a new deployment on OpenAPI definition updates +deployment.addToLogicalId(myApiDefinition); + +``` + +> Note: If the `stageName` property is set but a stage with the corresponding name does not exist, a new stage resource will be created with the provided stage name. -If the `stageName` property is set but a stage with the corresponding name does not exist, a new stage -resource will be created with the provided stage name. +> Note: If you update the `stageName` property, you should be triggering a new deployment (i.e. with an updated logical ID and API changes). Otherwise, an error will occur during deployment. ### Controlled triggering of deployments