Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(apigateway): cannot configure stage for SpecRestApi #10749

Merged
merged 2 commits into from
Oct 19, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/@aws-cdk/aws-apigateway/lib/base-path-mapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Resource, Token } from '@aws-cdk/core';
import { Construct } from 'constructs';
import { CfnBasePathMapping } from './apigateway.generated';
import { IDomainName } from './domain-name';
import { IRestApi, RestApi } from './restapi';
import { IRestApi, RestApiBase } from './restapi';
import { Stage } from './stage';

export interface BasePathMappingOptions {
Expand Down Expand Up @@ -55,7 +55,7 @@ export class BasePathMapping extends Resource {

// if restApi is an owned API and it has a deployment stage, map all requests
// to that stage. otherwise, the stage will have to be specified in the URL.
const stage = props.stage ?? (props.restApi instanceof RestApi
const stage = props.stage ?? (props.restApi instanceof RestApiBase
? props.restApi.deploymentStage
: undefined);

Expand Down
59 changes: 59 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/test.domains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -443,4 +443,63 @@ export = {
test.done();
},

'base path mapping configures stage for RestApi creation'(test: Test) {
// GIVEN
const stack = new Stack();
new apigw.RestApi(stack, 'restApiWithStage', {
domainName: {
domainName: 'example.com',
certificate: acm.Certificate.fromCertificateArn(stack, 'cert', 'arn:aws:acm:us-east-1:1111111:certificate/11-3336f1-44483d-adc7-9cd375c5169d'),
endpointType: apigw.EndpointType.REGIONAL,
},
}).root.addMethod('GET');

// THEN
expect(stack).to(haveResource('AWS::ApiGateway::BasePathMapping', {
'DomainName': {
'Ref': 'restApiWithStageCustomDomainC4749625',
},
'RestApiId': {
'Ref': 'restApiWithStageD4F931D0',
},
'Stage': {
'Ref': 'restApiWithStageDeploymentStageprodC82A6648',
},
}));

test.done();
},

'base path mapping configures stage for SpecRestApi creation'(test: Test) {
// GIVEN
const stack = new Stack();

const definition = {
key1: 'val1',
};

new apigw.SpecRestApi(stack, 'specRestApiWithStage', {
apiDefinition: apigw.ApiDefinition.fromInline(definition),
domainName: {
domainName: 'example.com',
certificate: acm.Certificate.fromCertificateArn(stack, 'cert', 'arn:aws:acm:us-east-1:1111111:certificate/11-3336f1-44483d-adc7-9cd375c5169d'),
endpointType: apigw.EndpointType.REGIONAL,
},
}).root.addMethod('GET');

// THEN
expect(stack).to(haveResource('AWS::ApiGateway::BasePathMapping', {
'DomainName': {
'Ref': 'specRestApiWithStageCustomDomain8A36A5C9',
},
'RestApiId': {
'Ref': 'specRestApiWithStageC1492575',
},
'Stage': {
'Ref': 'specRestApiWithStageDeploymentStageprod2D3037ED',
},
}));

test.done();
},
};