Skip to content

Commit b368a31

Browse files
fix(apigateway): Explicitly test for undefined instead of falsey for stage default options (#20868)
Fixes #20860 Default options for throttling burst and rate limits could be interpreted incorrectly as undefined if they were set to zero. ---- ### 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*
1 parent 2ec0fb8 commit b368a31

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/@aws-cdk/aws-apigateway/lib/stage.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ export class Stage extends Resource implements IStage {
310310
};
311311

312312
// if any of them are defined, add an entry for '/*/*'.
313-
const hasCommonOptions = Object.keys(commonMethodOptions).map(v => (commonMethodOptions as any)[v]).filter(x => x).length > 0;
313+
const hasCommonOptions = Object.keys(commonMethodOptions).map(v => (commonMethodOptions as any)[v]).filter(x => x !== undefined).length > 0;
314314
if (hasCommonOptions) {
315315
settings.push(renderEntry('/*/*', commonMethodOptions));
316316
}

packages/@aws-cdk/aws-apigateway/test/stage.test.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Template } from '@aws-cdk/assertions';
22
import * as logs from '@aws-cdk/aws-logs';
33
import * as cdk from '@aws-cdk/core';
44
import * as apigateway from '../lib';
5+
import { ApiDefinition } from '../lib';
56

67
describe('stage', () => {
78
test('minimal setup', () => {
@@ -396,4 +397,30 @@ describe('stage', () => {
396397
accessLogFormat: testFormat,
397398
})).toThrow(/Access log format is specified without a destination/);
398399
});
400+
401+
test('default throttling settings', () => {
402+
// GIVEN
403+
const stack = new cdk.Stack();
404+
new apigateway.SpecRestApi(stack, 'testapi', {
405+
apiDefinition: ApiDefinition.fromInline({
406+
openapi: '3.0.2',
407+
}),
408+
deployOptions: {
409+
throttlingBurstLimit: 0,
410+
throttlingRateLimit: 0,
411+
metricsEnabled: false,
412+
},
413+
});
414+
415+
// THEN
416+
Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Stage', {
417+
MethodSettings: [{
418+
DataTraceEnabled: false,
419+
HttpMethod: '*',
420+
ResourcePath: '/*',
421+
ThrottlingBurstLimit: 0,
422+
ThrottlingRateLimit: 0,
423+
}],
424+
});
425+
});
399426
});

0 commit comments

Comments
 (0)