File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed
packages/@aws-cdk/aws-apigateway Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff 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 - z A - Z 0 - 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}
Original file line number Diff line number Diff 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 ( ) ;
You can’t perform that action at this time.
0 commit comments