Skip to content

Commit 9bcc6d5

Browse files
authored
fix(apigateway): method response from rest api default options are not passed to Method (#26275)
`methodResponses` specified in `RestApi`'s `defaultMethodOptions` were not passed to `Method` as default. This fix solves the problem. Closes #26252. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent af3a188 commit 9bcc6d5

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

packages/aws-cdk-lib/aws-apigateway/lib/method.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ export class Method extends Resource {
203203
authorizer._attachToApi(this.api);
204204
}
205205

206-
this.methodResponses = options.methodResponses ?? [];
206+
this.methodResponses = options.methodResponses ?? defaultMethodOptions.methodResponses ?? [];
207207

208208
const integration = props.integration ?? this.resource.defaultIntegration ?? new MockIntegration();
209209
const bindResult = integration.bind(this);

packages/aws-cdk-lib/aws-apigateway/test/method.test.ts

+32
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,38 @@ describe('method', () => {
909909

910910
});
911911

912+
test('methodResponse should be passed from defaultMethodOptions', () => {
913+
// GIVEN
914+
const stack = new cdk.Stack();
915+
const api = new apigw.RestApi(stack, 'test-api', {
916+
cloudWatchRole: false,
917+
deploy: false,
918+
defaultMethodOptions: {
919+
requestParameters: { 'method.request.path.proxy': true },
920+
methodResponses: [
921+
{
922+
statusCode: '200',
923+
},
924+
],
925+
},
926+
});
927+
928+
// WHEN
929+
new apigw.Method(stack, 'method-man', {
930+
httpMethod: 'GET',
931+
resource: api.root,
932+
});
933+
934+
// THEN
935+
Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', {
936+
HttpMethod: 'GET',
937+
MethodResponses: [{
938+
StatusCode: '200',
939+
}],
940+
});
941+
942+
});
943+
912944
describe('Metrics', () => {
913945
test('metric', () => {
914946
// GIVEN

0 commit comments

Comments
 (0)