Skip to content

Commit a8f5326

Browse files
authored
fix(apigateway): validation for path parts does not allow creation of resources beginning with dollar sign (#27619)
This PR adjusts the validation rules for path parts in resources created using the APIGateway library to allow the use of dollar mark in pathParts, as requested in #27083. This enables the creation of resources with paths such as $test(from the reproduction steps in the related issue). An existing resource unit test ('url for a resource') has been updated to ensure that a dollar mark in a pathPart does not throw an error and properly reflects in the output of RestApi.urlForPath. The integration test integ.restapi has also been updated, wherein the appliances resource now has a path of $appliances:all instead of appliances:all. Closes #27083. #### All Submissions: - [x] Have you followed the guidelines in our [Contributing guide?](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) #### Adding new Unconventional Dependencies: - [ ] This PR adds new unconventional dependencies following the process described [here](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md/#adding-new-unconventional-dependencies) #### New Features - [x] Have you added the new feature to an [integration test](https://github.com/aws/aws-cdk/blob/main/INTEGRATION_TESTS.md)? - [x] Did you use yarn integ to deploy the infrastructure and generate the snapshot (i.e. yarn integ without --dry-run)? By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license
1 parent 22a3234 commit a8f5326

File tree

7 files changed

+75
-29
lines changed

7 files changed

+75
-29
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.js.snapshot/manifest.json

+35-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.js.snapshot/test-apigateway-restapi.assets.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.js.snapshot/test-apigateway-restapi.template.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
"UpdateReplacePolicy": "Retain",
5858
"DeletionPolicy": "Retain"
5959
},
60-
"myapiDeployment92F2CB4993c0f175ba8d5964f5e1cc7bc64fe6e6": {
60+
"myapiDeployment92F2CB49069d16df09c59427069eb74581a0403d": {
6161
"Type": "AWS::ApiGateway::Deployment",
6262
"Properties": {
6363
"Description": "beta stage",
@@ -66,8 +66,8 @@
6666
}
6767
},
6868
"DependsOn": [
69-
"myapiv1appliancesallGETC4DF552D",
70-
"myapiv1appliancesallCF8C6A16",
69+
"myapiv1appliancesallGETB8EB1B77",
70+
"myapiv1appliancesallD279897B",
7171
"myapiv1booksGETC6B996D0",
7272
"myapiv1booksPOST53E2832E",
7373
"myapiv1books1D4BE6C1",
@@ -86,7 +86,7 @@
8686
"CacheClusterEnabled": true,
8787
"CacheClusterSize": "0.5",
8888
"DeploymentId": {
89-
"Ref": "myapiDeployment92F2CB4993c0f175ba8d5964f5e1cc7bc64fe6e6"
89+
"Ref": "myapiDeployment92F2CB49069d16df09c59427069eb74581a0403d"
9090
},
9191
"Description": "beta stage",
9292
"MethodSettings": [
@@ -290,19 +290,19 @@
290290
}
291291
}
292292
},
293-
"myapiv1appliancesallCF8C6A16": {
293+
"myapiv1appliancesallD279897B": {
294294
"Type": "AWS::ApiGateway::Resource",
295295
"Properties": {
296296
"ParentId": {
297297
"Ref": "myapiv113487378"
298298
},
299-
"PathPart": "appliances:all",
299+
"PathPart": "$appliances:all",
300300
"RestApiId": {
301301
"Ref": "myapi4C7BF186"
302302
}
303303
}
304304
},
305-
"myapiv1appliancesallGETC4DF552D": {
305+
"myapiv1appliancesallGETB8EB1B77": {
306306
"Type": "AWS::ApiGateway::Method",
307307
"Properties": {
308308
"AuthorizationType": "NONE",
@@ -311,7 +311,7 @@
311311
"Type": "MOCK"
312312
},
313313
"ResourceId": {
314-
"Ref": "myapiv1appliancesallCF8C6A16"
314+
"Ref": "myapiv1appliancesallD279897B"
315315
},
316316
"RestApiId": {
317317
"Ref": "myapi4C7BF186"
@@ -682,7 +682,7 @@
682682
}
683683
},
684684
"DependsOn": [
685-
"myapiv1appliancesallGETC4DF552D",
685+
"myapiv1appliancesallGETB8EB1B77",
686686
"myapiv1booksGETC6B996D0",
687687
"myapiv1booksPOST53E2832E",
688688
"myapiv1toysGET7348114D",

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.js.snapshot/tree.json

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-apigateway/test/integ.restapi.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class Test extends cdk.Stack {
4343
toys.addMethod('POST');
4444
toys.addMethod('PUT');
4545

46-
const appliances = v1.addResource('appliances:all');
46+
const appliances = v1.addResource('$appliances:all');
4747
appliances.addMethod('GET');
4848

4949
const books = v1.addResource('books');

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -561,8 +561,8 @@ function validateResourcePathPart(part: string) {
561561
}
562562
}
563563

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

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

+17
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ describe('resource', () => {
197197
const aResource = api.root.addResource('a');
198198
const cResource = aResource.addResource('b').addResource('c');
199199
const colonResource = cResource.addResource('d:e');
200+
const dollarResource = cResource.addResource('$d');
200201

201202
// THEN
202203
expect(stack.resolve(api.urlForPath(aResource.path))).toEqual({
@@ -247,6 +248,22 @@ describe('resource', () => {
247248
],
248249
],
249250
});
251+
expect(stack.resolve(api.urlForPath(dollarResource.path))).toEqual({
252+
'Fn::Join': [
253+
'',
254+
[
255+
'https://',
256+
{ Ref: 'apiC8550315' },
257+
'.execute-api.',
258+
{ Ref: 'AWS::Region' },
259+
'.',
260+
{ Ref: 'AWS::URLSuffix' },
261+
'/',
262+
{ Ref: 'apiDeploymentStageprod896C8101' },
263+
'/a/b/c/$d',
264+
],
265+
],
266+
});
250267

251268
});
252269

0 commit comments

Comments
 (0)