Describe the bug
When creating a RestApi and setting RestApiProps.defaultMethodOptions.methodResponses, the method responses aren't passed to methods created on the RestApi that don't have a MethodOptions passed in.
Expected Behavior
Method responses should be passed to methods.
Current Behavior
Method responses aren't passed to methods. Other properties like RestApiProps.defaultMethodOptions.authorizationType seem to be passed though.
Reproduction Steps
TypeScript code:
import { Construct, aws_apigateway } from "aws-cdk-lib";
export class MockApiGatewayRestApi extends Construct {
constructor(scope: Construct, id: string) {
super(scope, id);
const restApi = new aws_apigateway.RestApi(this, "REST_API", {
defaultIntegration: new aws_apigateway.MockIntegration({
passthroughBehavior: aws_apigateway.PassthroughBehavior.NEVER,
requestTemplates: {
"application/json": '{"statusCode": 200}'
},
integrationResponses: [
{
statusCode: "200"
}
]
}),
defaultMethodOptions: {
authorizationType: aws_apigateway.AuthorizationType.IAM,
methodResponses: [
{
statusCode: "200"
}
]
}
});
restApi.root.addResource("test").addMethod("GET");
}
}
Resulting AWS::ApiGateway::Method:
{
"{Logical ID}": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"HttpMethod": "GET",
"ResourceId": {
"Ref": "{AWS::ApiGateway::Resource logical ID for test resource}"
},
"RestApiId": {
"Ref": "{AWS::ApiGateway::RestApi logical ID for endpoint}"
},
"AuthorizationType": "AWS_IAM",
"Integration": {
"IntegrationResponses": [
{
"StatusCode": "200"
}
],
"PassthroughBehavior": "NEVER",
"RequestTemplates": {
"application/json": "{\"statusCode\": 200}"
},
"Type": "MOCK"
}
}
}
}
CDK CLI Version
2.85.0
Framework Version
2.85.0
Node.js Version
20.2.0
OS
macOS Monterey 12.6.6 and Amazon Linux 2
Language
Typescript
Language Version
5.1.3
Other information
If we pass in the integration and method options when creating the method, the resulting template is as expected.
TypeScript code:
import { Construct, aws_apigateway } from "aws-cdk-lib";
export class MockApiGatewayRestApi extends Construct {
constructor(scope: Construct, id: string) {
super(scope, id);
const restApi = new aws_apigateway.RestApi(this, "REST_API");
const mockIntegration = new aws_apigateway.MockIntegration({
passthroughBehavior: aws_apigateway.PassthroughBehavior.NEVER,
requestTemplates: {
"application/json": '{"statusCode": 200}'
},
integrationResponses: [
{
statusCode: "200"
}
]
});
const methodOptions: aws_apigateway.MethodOptions = {
authorizationType: aws_apigateway.AuthorizationType.IAM,
methodResponses: [
{
statusCode: "200"
}
]
};
restApi.root.addResource("test").addMethod("GET", mockIntegration, methodOptions);
}
}
Resulting AWS::ApiGateway::Method:
{
"{Logical ID}": {
"Type": "AWS::ApiGateway::Method",
"Properties": {
"HttpMethod": "GET",
"ResourceId": {
"Ref": "{AWS::ApiGateway::Resource logical ID for test resource}"
},
"RestApiId": {
"Ref": "{AWS::ApiGateway::RestApi logical ID for endpoint}"
},
"AuthorizationType": "AWS_IAM",
"Integration": {
"IntegrationResponses": [
{
"StatusCode": "200"
}
],
"PassthroughBehavior": "NEVER",
"RequestTemplates": {
"application/json": "{\"statusCode\": 200}"
},
"Type": "MOCK"
},
"MethodResponses": [
{
"StatusCode": "200"
}
]
}
}
}
Describe the bug
When creating a
RestApiand settingRestApiProps.defaultMethodOptions.methodResponses, the method responses aren't passed to methods created on theRestApithat don't have aMethodOptionspassed in.Expected Behavior
Method responses should be passed to methods.
Current Behavior
Method responses aren't passed to methods. Other properties like
RestApiProps.defaultMethodOptions.authorizationTypeseem to be passed though.Reproduction Steps
TypeScript code:
Resulting
AWS::ApiGateway::Method:{ "{Logical ID}": { "Type": "AWS::ApiGateway::Method", "Properties": { "HttpMethod": "GET", "ResourceId": { "Ref": "{AWS::ApiGateway::Resource logical ID for test resource}" }, "RestApiId": { "Ref": "{AWS::ApiGateway::RestApi logical ID for endpoint}" }, "AuthorizationType": "AWS_IAM", "Integration": { "IntegrationResponses": [ { "StatusCode": "200" } ], "PassthroughBehavior": "NEVER", "RequestTemplates": { "application/json": "{\"statusCode\": 200}" }, "Type": "MOCK" } } } }CDK CLI Version
2.85.0
Framework Version
2.85.0
Node.js Version
20.2.0
OS
macOS Monterey 12.6.6 and Amazon Linux 2
Language
Typescript
Language Version
5.1.3
Other information
If we pass in the integration and method options when creating the method, the resulting template is as expected.
TypeScript code:
Resulting
AWS::ApiGateway::Method:{ "{Logical ID}": { "Type": "AWS::ApiGateway::Method", "Properties": { "HttpMethod": "GET", "ResourceId": { "Ref": "{AWS::ApiGateway::Resource logical ID for test resource}" }, "RestApiId": { "Ref": "{AWS::ApiGateway::RestApi logical ID for endpoint}" }, "AuthorizationType": "AWS_IAM", "Integration": { "IntegrationResponses": [ { "StatusCode": "200" } ], "PassthroughBehavior": "NEVER", "RequestTemplates": { "application/json": "{\"statusCode\": 200}" }, "Type": "MOCK" }, "MethodResponses": [ { "StatusCode": "200" } ] } } }