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(aws-apigateway): Fix proxy resources being rejected by validation #813

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## [UNRELEASED]

### Bug Fixes

* **aws-apigateway:** fix validation of resources failing for proxy resource paths (`{proxy+}`)

<a name="0.10.0"></a>
## [0.10.0](https://github.com/awslabs/aws-cdk/compare/v0.9.2...v0.10.0) (2018-09-27)

Expand Down
5 changes: 5 additions & 0 deletions packages/@aws-cdk/aws-apigateway/lib/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ function validateResourcePathPart(part: string) {
// strip {} which indicate this is a parameter
if (part.startsWith('{') && part.endsWith('}')) {
part = part.substr(1, part.length - 2);

// proxy resources are allowed to end with a '+'
if (part.endsWith('+')) {
part = part.substr(0, part.length - 1);
}
}

if (!/^[a-zA-Z0-9\.\_\-]+$/.test(part)) {
Expand Down
21 changes: 21 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/test.restapi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,27 @@ export = {
test.done();
},

'"addResource" allows configuration of proxy paths'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const api = new apigateway.RestApi(stack, 'restapi', {
deploy: false,
cloudWatchRole: false,
restApiName: 'my-rest-api'
});

// WHEN
const proxy = api.root.addResource('{proxy+}');
proxy.addMethod('ANY');

// THEN
expect(stack).to(haveResource('AWS::ApiGateway::Resource', {
PathPart: "{proxy+}",
ParentId: { "Fn::GetAtt": ["restapiC5611D27", "RootResourceId"] }
}));
test.done();
},

'"addMethod" can be used to add methods to resources'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down