Skip to content

Commit

Permalink
fix(apigateway): honour requestParameters passed via defaultMethodOpt…
Browse files Browse the repository at this point in the history
…ions (#4249)

* fix (apigateway): Apply default request parameters to method

* Add operation name check to make sure we're validating the expected method
  • Loading branch information
svenrienstra authored and mergify[bot] committed Sep 26, 2019
1 parent 96ec442 commit b347c35
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/@aws-cdk/aws-apigateway/lib/method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class Method extends Resource {
apiKeyRequired: options.apiKeyRequired || defaultMethodOptions.apiKeyRequired,
authorizationType: options.authorizationType || defaultMethodOptions.authorizationType || AuthorizationType.NONE,
authorizerId: authorizer && authorizer.authorizerId,
requestParameters: options.requestParameters,
requestParameters: options.requestParameters || defaultMethodOptions.requestParameters,
integration: this.renderIntegration(props.integration),
methodResponses: this.renderMethodResponses(options.methodResponses),
requestModels: this.renderRequestModels(options.requestModels),
Expand Down
33 changes: 32 additions & 1 deletion packages/@aws-cdk/aws-apigateway/test/test.method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,5 +578,36 @@ export = {
}));

test.done();
}
},

'use default requestParameters'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const api = new apigateway.RestApi(stack, 'test-api', {
cloudWatchRole: false,
deploy: false,
defaultMethodOptions: {
requestParameters: {"method.request.path.proxy": true}
}
});

// WHEN
new apigateway.Method(stack, 'defaultRequestParameters', {
httpMethod: 'POST',
resource: api.root,
options: {
operationName: 'defaultRequestParameters'
}
});

// THEN
expect(stack).to(haveResource('AWS::ApiGateway::Method', {
OperationName: 'defaultRequestParameters',
RequestParameters: {
"method.request.path.proxy": true
}
}));

test.done();
},
};

0 comments on commit b347c35

Please sign in to comment.