Skip to content

Commit

Permalink
chore(apigateway): restApiName is not a physicalName (#10805)
Browse files Browse the repository at this point in the history
----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
Niranjan Jayakar authored Oct 9, 2020
1 parent 23f77fd commit 71aa4b6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/@aws-cdk/aws-apigateway/lib/restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,17 @@ export abstract class RestApiBase extends Resource implements IRestApi {
*/
public deploymentStage!: Stage;

/**
* A human friendly name for this Rest API. Note that this is different from `restApiId`.
*/
public readonly restApiName: string;

private _latestDeployment?: Deployment;
private _domainName?: DomainName;

constructor(scope: Construct, id: string, props: RestApiBaseProps = { }) {
super(scope, id, {
physicalName: props.restApiName || id,
});
super(scope, id);
this.restApiName = props.restApiName ?? id;

Object.defineProperty(this, RESTAPI_SYMBOL, { value: true });
}
Expand Down Expand Up @@ -381,7 +385,7 @@ export abstract class RestApiBase extends Resource implements IRestApi {
return new cloudwatch.Metric({
namespace: 'AWS/ApiGateway',
metricName,
dimensions: { ApiName: this.physicalName },
dimensions: { ApiName: this.restApiName },
...props,
});
}
Expand Down Expand Up @@ -565,7 +569,7 @@ export class SpecRestApi extends RestApiBase {
super(scope, id, props);
const apiDefConfig = props.apiDefinition.bind(this);
const resource = new CfnRestApi(this, 'Resource', {
name: this.physicalName,
name: this.restApiName,
policy: props.policy,
failOnWarnings: props.failOnWarnings,
body: apiDefConfig.inlineDefinition ? apiDefConfig.inlineDefinition : undefined,
Expand Down Expand Up @@ -667,7 +671,7 @@ export class RestApi extends RestApiBase {
super(scope, id, props);

const resource = new CfnRestApi(this, 'Resource', {
name: this.physicalName,
name: this.restApiName,
description: props.description,
policy: props.policy,
failOnWarnings: props.failOnWarnings,
Expand Down
3 changes: 3 additions & 0 deletions packages/@aws-cdk/aws-apigateway/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,9 @@
"attribute-tag:@aws-cdk/aws-apigateway.LambdaAuthorizer.authorizerArn",
"attribute-tag:@aws-cdk/aws-apigateway.RequestAuthorizer.authorizerArn",
"attribute-tag:@aws-cdk/aws-apigateway.TokenAuthorizer.authorizerArn",
"attribute-tag:@aws-cdk/aws-apigateway.RestApi.restApiName",
"attribute-tag:@aws-cdk/aws-apigateway.SpecRestApi.restApiName",
"attribute-tag:@aws-cdk/aws-apigateway.LambdaRestApi.restApiName",
"from-method:@aws-cdk/aws-apigateway.Stage"
]
},
Expand Down
16 changes: 16 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/test.restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,22 @@ export = {
test.done();
},

'restApiName is set correctly'(test: Test) {
// GIVEN
const stack = new Stack();

// WHEN
const myapi = new apigw.RestApi(stack, 'myapi');
const yourapi = new apigw.RestApi(stack, 'yourapi', {
restApiName: 'namedapi',
});

// THEN
test.deepEqual(myapi.restApiName, 'myapi');
test.deepEqual(yourapi.restApiName, 'namedapi');
test.done();
},

'defaultChild is set correctly'(test: Test) {
const stack = new Stack();
const api = new apigw.RestApi(stack, 'my-api');
Expand Down

0 comments on commit 71aa4b6

Please sign in to comment.