From dc786c6fe9198ceda57e048a80cf65370917d4b1 Mon Sep 17 00:00:00 2001 From: Gavin Zhang Date: Wed, 6 Mar 2024 14:51:52 -0800 Subject: [PATCH 1/2] fix(spec2cdk): use modern type when building tag type --- tools/@aws-cdk/spec2cdk/lib/cdk/resource-decider.ts | 2 +- tools/@aws-cdk/spec2cdk/lib/cdk/type-converter.ts | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/@aws-cdk/spec2cdk/lib/cdk/resource-decider.ts b/tools/@aws-cdk/spec2cdk/lib/cdk/resource-decider.ts index 2db62bb3d0b4a..7b981cacb8fd7 100644 --- a/tools/@aws-cdk/spec2cdk/lib/cdk/resource-decider.ts +++ b/tools/@aws-cdk/spec2cdk/lib/cdk/resource-decider.ts @@ -179,7 +179,7 @@ export class ResourceDecider { private handleTagPropertyModern(cfnName: string, prop: Property, variant: TagVariant) { const originalName = propertyNameFromCloudFormation(cfnName); - const originalType = this.converter.typeFromProperty(prop); + const originalType = this.converter.typeFromPropertyForModernTags(prop); this.propsProperties.push({ propertySpec: { diff --git a/tools/@aws-cdk/spec2cdk/lib/cdk/type-converter.ts b/tools/@aws-cdk/spec2cdk/lib/cdk/type-converter.ts index df3a215e503e5..5accddfe15da2 100644 --- a/tools/@aws-cdk/spec2cdk/lib/cdk/type-converter.ts +++ b/tools/@aws-cdk/spec2cdk/lib/cdk/type-converter.ts @@ -96,6 +96,16 @@ export class TypeConverter { return this.typeFromSpecType(this.typeHistoryFromProperty(property)[0]); } + /** + * Return the appropriate typewriter type for a servicespec type for modern tags + * Unlike typeFromProperty, we want to default to use the newest type instead. + */ + public typeFromPropertyForModernTags(property: Property): Type { + // For backwards compatibility reasons we always have to use the original type + const types = this.typeHistoryFromProperty(property); + return this.typeFromSpecType(types[types.length - 1]); + } + /** * Return the full type history for a servicespec property */ From 9611612ae6bcfd3fafe40fd057ceb59b630e970d Mon Sep 17 00:00:00 2001 From: Gavin Zhang Date: Thu, 7 Mar 2024 09:02:55 -0800 Subject: [PATCH 2/2] Add unit tests --- .../aws-cdk-lib/aws-xray/test/xray.test.ts | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 packages/aws-cdk-lib/aws-xray/test/xray.test.ts diff --git a/packages/aws-cdk-lib/aws-xray/test/xray.test.ts b/packages/aws-cdk-lib/aws-xray/test/xray.test.ts new file mode 100644 index 0000000000000..6f4df4fc6f0dd --- /dev/null +++ b/packages/aws-cdk-lib/aws-xray/test/xray.test.ts @@ -0,0 +1,41 @@ +import { Match, Template } from '../../assertions'; +import * as iam from '../../aws-iam'; +import * as kms from '../../aws-kms'; +import { CfnParameter, Duration, Stack, App, Token, Tags } from '../../core'; +import * as xray from '../lib'; + +/* eslint-disable quote-props */ + +test('able to add tags to XRay CfnGroup', () => { + const stack = new Stack(); + new xray.CfnGroup(stack, 'Group', { + groupName: 'GroupName', + tags: [{ + key: 'Key', + value: 'Value', + }], + }); + + Template.fromStack(stack).hasResourceProperties('AWS::XRay::Group', { + Tags: [{ + Key: 'Key', + Value: 'Value', + }], + }); +}); + +test('able to add tags through Tags.of()... to XRay CfnGroup', () => { + const stack = new Stack(); + new xray.CfnGroup(stack, 'Group', { + groupName: 'GroupName', + }); + + Tags.of(stack).add('Key', 'Value'); + + Template.fromStack(stack).hasResourceProperties('AWS::XRay::Group', { + Tags: [{ + Key: 'Key', + Value: 'Value', + }], + }); +});