Skip to content

Commit 47cae25

Browse files
authored
chore: tweak enum-like parser to exclude certain classes (#33536)
### Issue # (if applicable) N/A ### Reason for this change The enum-like parser was pulling in some classes that did not follow the pattern of enum-like classes. This alleviates that by, rather than looking for fields that are strictly not strings, fields that strictly follow the pattern: ```ts public static readonly NEW_EXPRESSION = new SomeClass(...); public static readonly CALL_EXPRESSION = SomeClass.method(...); public static readonly ACCESS_EXPRESSION = MyClass.ANOTHER_ENUM; ``` ### Description of changes Altered the parsing logic to be more specific, and reran the script to parse enum-likes. ### Describe any new or updated permissions being added N/A ### Description of how you validated changes `yarn test` ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 315be88 commit 47cae25

File tree

2 files changed

+8
-60
lines changed

2 files changed

+8
-60
lines changed

packages/aws-cdk-lib/core/lib/analytics-data-source/enums/module-enumlikes.json

+3-58
Original file line numberDiff line numberDiff line change
@@ -189,21 +189,6 @@
189189
"TSV"
190190
]
191191
},
192-
"packages/@aws-cdk/aws-glue-alpha/lib/schema.ts": {
193-
"Schema": [
194-
"BOOLEAN",
195-
"BINARY",
196-
"BIG_INT",
197-
"DOUBLE",
198-
"FLOAT",
199-
"INTEGER",
200-
"SMALL_INT",
201-
"TINY_INT",
202-
"DATE",
203-
"TIMESTAMP",
204-
"STRING"
205-
]
206-
},
207192
"packages/@aws-cdk/aws-iot-alpha/lib/scheduled-audit.ts": {
208193
"DayOfMonth": [
209194
"LAST_DAY"
@@ -287,9 +272,6 @@
287272
],
288273
"LogType": [
289274
"AUDIT"
290-
],
291-
"DatabaseCluster": [
292-
"DEFAULT_NUM_INSTANCES"
293275
]
294276
},
295277
"packages/@aws-cdk/aws-neptune-alpha/lib/instance.ts": {
@@ -467,13 +449,6 @@
467449
"T2_XLARGE"
468450
]
469451
},
470-
"packages/aws-cdk-lib/aws-apigateway/lib/cors.ts": {
471-
"Cors": [
472-
"ALL_METHODS",
473-
"ALL_ORIGINS",
474-
"DEFAULT_HEADERS"
475-
]
476-
},
477452
"packages/aws-cdk-lib/aws-apigateway/lib/gateway-response.ts": {
478453
"ResponseType": [
479454
"ACCESS_DENIED",
@@ -1372,12 +1347,6 @@
13721347
"EC2_TRANSIT_GATEWAY_MULTICAST_DOMAIN"
13731348
]
13741349
},
1375-
"packages/aws-cdk-lib/aws-docdb/lib/cluster.ts": {
1376-
"DatabaseCluster": [
1377-
"DEFAULT_NUM_INSTANCES",
1378-
"DEFAULT_PORT"
1379-
]
1380-
},
13811350
"packages/aws-cdk-lib/aws-ec2/lib/machine-image/amazon-linux-2022.ts": {
13821351
"AmazonLinux2022Kernel": [
13831352
"CDK_LATEST",
@@ -1399,11 +1368,6 @@
13991368
"KERNEL_5_10"
14001369
]
14011370
},
1402-
"packages/aws-cdk-lib/aws-ec2/lib/nat.ts": {
1403-
"NatInstanceProviderV2": [
1404-
"DEFAULT_USER_DATA_COMMANDS"
1405-
]
1406-
},
14071371
"packages/aws-cdk-lib/aws-ec2/lib/port.ts": {
14081372
"Port": [
14091373
"SSH",
@@ -1836,12 +1800,6 @@
18361800
"ALL_DEFAULT_FIELDS"
18371801
]
18381802
},
1839-
"packages/aws-cdk-lib/aws-ec2/lib/vpc.ts": {
1840-
"Vpc": [
1841-
"DEFAULT_SUBNETS",
1842-
"DEFAULT_SUBNETS_NO_NAT"
1843-
]
1844-
},
18451803
"packages/aws-cdk-lib/aws-ecr-assets/lib/image-asset.ts": {
18461804
"NetworkMode": [
18471805
"DEFAULT",
@@ -1864,11 +1822,6 @@
18641822
"LATEST"
18651823
]
18661824
},
1867-
"packages/aws-cdk-lib/aws-ecs/lib/container-definition.ts": {
1868-
"ContainerDefinition": [
1869-
"CONTAINER_PORT_USE_RANGE"
1870-
]
1871-
},
18721825
"packages/aws-cdk-lib/aws-ecs/lib/runtime-platform.ts": {
18731826
"CpuArchitecture": [
18741827
"ARM64",
@@ -1885,11 +1838,6 @@
18851838
"WINDOWS_SERVER_20H2_CORE"
18861839
]
18871840
},
1888-
"packages/aws-cdk-lib/aws-efs/lib/efs-file-system.ts": {
1889-
"FileSystem": [
1890-
"DEFAULT_PORT"
1891-
]
1892-
},
18931841
"packages/aws-cdk-lib/aws-eks/lib/access-entry.ts": {
18941842
"AccessPolicyArn": [
18951843
"AMAZON_EKS_ADMIN_POLICY",
@@ -2391,7 +2339,8 @@
23912339
"VER_3_06_1",
23922340
"VER_3_07_0",
23932341
"VER_3_07_1",
2394-
"VER_3_08_0"
2342+
"VER_3_08_0",
2343+
"VER_3_08_1"
23952344
],
23962345
"AuroraPostgresEngineVersion": [
23972346
"VER_9_6_8",
@@ -2852,6 +2801,7 @@
28522801
"VER_16_4",
28532802
"VER_16_5",
28542803
"VER_16_6",
2804+
"VER_16_7",
28552805
"VER_17",
28562806
"VER_17_1",
28572807
"VER_17_2"
@@ -3625,11 +3575,6 @@
36253575
"INSTANCE"
36263576
]
36273577
},
3628-
"packages/aws-cdk-lib/custom-resources/lib/aws-custom-resource/aws-custom-resource.ts": {
3629-
"AwsCustomResourcePolicy": [
3630-
"ANY_RESOURCE"
3631-
]
3632-
},
36333578
"packages/aws-cdk-lib/pipelines/lib/helpers-internal/pipeline-graph.ts": {
36343579
"PipelineGraph": [
36353580
"NO_STEP"

tools/@aws-cdk/construct-metadata-updater/lib/metadata-updater.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -719,8 +719,11 @@ export class EnumLikeUpdater extends MetadataUpdater {
719719
if (className) {
720720
node.forEachChild((classField) => {
721721
if (classField instanceof PropertyDeclaration) {
722-
// enum-likes have `public static readonly` attributes that map to non-string values
723-
if (classField.getText().startsWith("public static readonly") && classField.getInitializer()?.getKind() !== SyntaxKind.StringLiteral) {
722+
// enum-likes have `public static readonly` attributes that map to either new or call expressions
723+
const initializerKind = classField.getInitializer()?.getKind();
724+
if (initializerKind && classField.getText().startsWith("public static readonly") &&
725+
(initializerKind === SyntaxKind.NewExpression || initializerKind === SyntaxKind.CallExpression || initializerKind === SyntaxKind.PropertyAccessExpression)
726+
) {
724727
// This is an enum-like; add to blueprint
725728
const enumlikeName = classField.getName();
726729
if (!fileBlueprint[className]) {

0 commit comments

Comments
 (0)