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): method response from rest api default options are not passed to Method #26275

Merged
merged 3 commits into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
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