From b4d973fa2dab0f8ac528ddbde4ded43aeef33856 Mon Sep 17 00:00:00 2001 From: josephedward <15126922+josephedward@users.noreply.github.com> Date: Mon, 25 Jul 2022 17:37:56 -0400 Subject: [PATCH] feat(api-gateway): allow configuration of deployment description (#21207) ---- Closes #20934 Motivation: Customer would like to be able to set the description per deployment. From inside their pipeline, they could get the commit hash / commit message, timestamp, custom text, and other git-related metadata that they would like to set as description. Thanks to @TheRealAmazonKendra for help cleaning this PR up and providing some pointers on locally building the CDK. ### All Submissions: * [ ] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) ### Adding new Unconventional Dependencies: * [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) ### New Features * [ ] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? * [ ] Did you use `yarn integ` to deploy the infrastructure and generate the snapshot (i.e. `yarn integ` without `--dry-run`)? *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../@aws-cdk/aws-apigateway/lib/restapi.ts | 15 +++++---- .../aws-apigateway/test/restapi.test.ts | 32 +++++++++++++++++++ 2 files changed, 40 insertions(+), 7 deletions(-) diff --git a/packages/@aws-cdk/aws-apigateway/lib/restapi.ts b/packages/@aws-cdk/aws-apigateway/lib/restapi.ts index 625d6a6b6cbbd..450df5003dc39 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/restapi.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/restapi.ts @@ -180,6 +180,13 @@ export interface RestApiBaseProps { * @default false */ readonly disableExecuteApiEndpoint?: boolean; + + /** + * A description of the RestApi construct. + * + * @default - 'Automatically created by the RestApi construct' + */ + readonly description?: string; } /** @@ -193,12 +200,6 @@ export interface RestApiOptions extends RestApiBaseProps, ResourceOptions { * Props to create a new instance of RestApi */ export interface RestApiProps extends RestApiOptions { - /** - * A description of the purpose of this API Gateway RestApi resource. - * - * @default - No description. - */ - readonly description?: string; /** * The list of binary media mime-types that are supported by the RestApi @@ -554,7 +555,7 @@ export abstract class RestApiBase extends Resource implements IRestApi { if (deploy) { this._latestDeployment = new Deployment(this, 'Deployment', { - description: 'Automatically created by the RestApi construct', + description: props.description? props.description :'Automatically created by the RestApi construct', api: this, retainDeployments: props.retainDeployments, }); diff --git a/packages/@aws-cdk/aws-apigateway/test/restapi.test.ts b/packages/@aws-cdk/aws-apigateway/test/restapi.test.ts index 0b019719a4873..ee7cce939bb91 100644 --- a/packages/@aws-cdk/aws-apigateway/test/restapi.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/restapi.test.ts @@ -1096,4 +1096,36 @@ describe('restapi', () => { DisableExecuteApiEndpoint: true, }); }); + + + describe('Description', () => { + test('description can be set', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + const api = new apigw.RestApi(stack, 'my-api', { description: 'My API' }); + api.root.addMethod('GET'); + + // THEN + Template.fromStack(stack).hasResourceProperties( + 'AWS::ApiGateway::RestApi', + { + Description: 'My API', + }); + }); + + test('description is not set', () => { + // GIVEN + const stack = new Stack(); + + // WHEN + const api = new apigw.RestApi(stack, 'my-api'); + api.root.addMethod('GET'); + + // THEN + Template.fromStack(stack).hasResourceProperties( + 'AWS::ApiGateway::RestApi', {}); + }); + }); });