Skip to content

Commit 9aadcb6

Browse files
danrix0rrr
dan
authored andcommitted
fix(aws-apigateway): allow + in path parts (#769)
The RegEx was too restrictive when being used with proxy variables. The \+ in {proxy+} is valid and should not throw an exception. Fixes #768.
1 parent f5fcc89 commit 9aadcb6

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/@aws-cdk/aws-apigateway/lib/resource.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,15 @@ function validateResourcePathPart(part: string) {
138138
// strip {} which indicate this is a parameter
139139
if (part.startsWith('{') && part.endsWith('}')) {
140140
part = part.substr(1, part.length - 2);
141+
142+
// proxy resources are allowed to end with a '+'
143+
if (part.endsWith('+')) {
144+
part = part.substr(0, part.length - 1);
145+
}
141146
}
142147

143148
if (!/^[a-zA-Z0-9\.\_\-]+$/.test(part)) {
144-
throw new Error(`Resource's path part only allow a-zA-Z0-9._- and curly braces at the beginning and the end: ${part}`);
149+
throw new Error(`Resource's path part only allow [a-zA-Z0-9._-], an optional trailing '+'
150+
and curly braces at the beginning and the end: ${part}`);
145151
}
146152
}

packages/@aws-cdk/aws-apigateway/test/test.restapi.ts

+21
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,27 @@ export = {
223223
test.done();
224224
},
225225

226+
'"addResource" allows configuration of proxy paths'(test: Test) {
227+
// GIVEN
228+
const stack = new cdk.Stack();
229+
const api = new apigateway.RestApi(stack, 'restapi', {
230+
deploy: false,
231+
cloudWatchRole: false,
232+
restApiName: 'my-rest-api'
233+
});
234+
235+
// WHEN
236+
const proxy = api.root.addResource('{proxy+}');
237+
proxy.addMethod('ANY');
238+
239+
// THEN
240+
expect(stack).to(haveResource('AWS::ApiGateway::Resource', {
241+
PathPart: "{proxy+}",
242+
ParentId: { "Fn::GetAtt": ["restapiC5611D27", "RootResourceId"] }
243+
}));
244+
test.done();
245+
},
246+
226247
'"addMethod" can be used to add methods to resources'(test: Test) {
227248
// GIVEN
228249
const stack = new cdk.Stack();

0 commit comments

Comments
 (0)