Skip to content

Commit

Permalink
fix(apigateway): method response from rest api default options are no…
Browse files Browse the repository at this point in the history
…t 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*
  • Loading branch information
lpizzinidev committed Jul 7, 2023
1 parent af3a188 commit 9bcc6d5
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/aws-cdk-lib/aws-apigateway/lib/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class Method extends Resource {
authorizer._attachToApi(this.api);
}

this.methodResponses = options.methodResponses ?? [];
this.methodResponses = options.methodResponses ?? defaultMethodOptions.methodResponses ?? [];

const integration = props.integration ?? this.resource.defaultIntegration ?? new MockIntegration();
const bindResult = integration.bind(this);
Expand Down
32 changes: 32 additions & 0 deletions packages/aws-cdk-lib/aws-apigateway/test/method.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,38 @@ describe('method', () => {

});

test('methodResponse should be passed from defaultMethodOptions', () => {
// GIVEN
const stack = new cdk.Stack();
const api = new apigw.RestApi(stack, 'test-api', {
cloudWatchRole: false,
deploy: false,
defaultMethodOptions: {
requestParameters: { 'method.request.path.proxy': true },
methodResponses: [
{
statusCode: '200',
},
],
},
});

// WHEN
new apigw.Method(stack, 'method-man', {
httpMethod: 'GET',
resource: api.root,
});

// THEN
Template.fromStack(stack).hasResourceProperties('AWS::ApiGateway::Method', {
HttpMethod: 'GET',
MethodResponses: [{
StatusCode: '200',
}],
});

});

describe('Metrics', () => {
test('metric', () => {
// GIVEN
Expand Down

0 comments on commit 9bcc6d5

Please sign in to comment.