File tree Expand file tree Collapse file tree
packages/aws-cdk-lib/aws-apigateway Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) ;
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments