Skip to content

Commit

Permalink
fix(aws-apigateway): allow + in path parts (#769)
Browse files Browse the repository at this point in the history
The RegEx was too restrictive when being used with proxy variables. The
\+ in {proxy+} is valid and should not throw an exception.

Fixes #768.
  • Loading branch information
dan authored and rix0rrr committed Oct 2, 2018
1 parent f5fcc89 commit 9aadcb6
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/@aws-cdk/aws-apigateway/lib/resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,15 @@ 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)) {
throw new Error(`Resource's path part only allow a-zA-Z0-9._- and curly braces at the beginning and the end: ${part}`);
throw new Error(`Resource's path part only allow [a-zA-Z0-9._-], an optional trailing '+'
and curly braces at the beginning and the end: ${part}`);
}
}
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

0 comments on commit 9aadcb6

Please sign in to comment.