diff --git a/CHANGELOG.md b/CHANGELOG.md index aad99baa7eb98..2913e127f85ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## [UNRELEASED] + +### Bug Fixes + +* **aws-apigateway:** fix validation of resources failing for proxy resource paths (`{proxy+}`) + ## [0.10.0](https://github.com/awslabs/aws-cdk/compare/v0.9.2...v0.10.0) (2018-09-27) diff --git a/packages/@aws-cdk/aws-apigateway/lib/resource.ts b/packages/@aws-cdk/aws-apigateway/lib/resource.ts index 1bab6758d3d02..10b32292cda4b 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/resource.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/resource.ts @@ -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)) { diff --git a/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts b/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts index a90d1bbb6c4f7..c27a4dc00efff 100644 --- a/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts +++ b/packages/@aws-cdk/aws-apigateway/test/test.restapi.ts @@ -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();