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', {}); + }); + }); });