From 6aa83941472c8b587c1d61f5b8baafe0f8951206 Mon Sep 17 00:00:00 2001 From: ben pace Date: Mon, 30 Mar 2026 13:12:55 -0400 Subject: [PATCH] =?UTF-8?q?Revert=20"feat(core):=20add=20source=20tracing?= =?UTF-8?q?=20for=20L1=20construct=20property=20mutations=20(#=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit f0b6da82b49da6611f871b67497db8d5004738a2. --- packages/aws-cdk-lib/aws-sns/test/sns.test.ts | 67 --------- packages/aws-cdk-lib/core/lib/stack-trace.ts | 23 ---- tools/@aws-cdk/spec2cdk/lib/cdk/cdk.ts | 1 - .../spec2cdk/lib/cdk/resource-class.ts | 30 +--- .../spec2cdk/lib/cdk/resource-decider.ts | 8 -- .../cfn-prop-mixins.test.ts.snap | 2 +- .../__snapshots__/fake-services.test.ts.snap | 20 +-- .../__snapshots__/relationships.test.ts.snap | 62 ++------- .../test/__snapshots__/resources.test.ts.snap | 128 ++---------------- .../spec2cdk/test/relationships.test.ts | 2 +- .../@aws-cdk/spec2cdk/test/resources.test.ts | 37 ----- 11 files changed, 34 insertions(+), 346 deletions(-) diff --git a/packages/aws-cdk-lib/aws-sns/test/sns.test.ts b/packages/aws-cdk-lib/aws-sns/test/sns.test.ts index 7fda1181b72b9..3af8faced4b78 100644 --- a/packages/aws-cdk-lib/aws-sns/test/sns.test.ts +++ b/packages/aws-cdk-lib/aws-sns/test/sns.test.ts @@ -1,14 +1,10 @@ -import * as fs from 'node:fs'; -import * as path from 'node:path'; import { Template } from '../../assertions'; -import { AssertionError } from '../../assertions/lib/private/error'; import * as notifications from '../../aws-codestarnotifications'; import * as iam from '../../aws-iam'; import { ServicePrincipal } from '../../aws-iam'; import * as kms from '../../aws-kms'; import { CfnKey } from '../../aws-kms'; import * as cdk from '../../core'; -import { Stage } from '../../core'; import * as sns from '../lib'; import { TopicGrants } from '../lib'; @@ -1086,67 +1082,4 @@ describe('Topic', () => { ).toThrow('`fifoThroughputScope` can only be set for FIFO SNS topics.'); }); }); - - /* - This is a representative test suite for source tracing. - What we are asserting here about CfnTopic applies to all L1 constructs. - */ - describe('Source tracing', () => { - test('Metadata contains propertyAssignment and stack trace with CDK_DEBUG=1', () => { - try { - process.env.CDK_DEBUG = '1'; - const stack = new cdk.Stack(); - - const topic = new sns.CfnTopic(stack, 'MyTopic', { - topicName: 'topicName', - }); - - topic.displayName = 'something'; - const lineWherePropertyWasSet = getLineNumber() - 1; // the one before this one - - const asm = synth(stack); - const metadata = JSON.parse(fs.readFileSync(path.join(asm.directory, 'Default.metadata.json'), 'utf8')); - const propertyAssignmentEntry = metadata['/Default/MyTopic'].find((e: any) => e.type === 'aws:cdk:propertyAssignment'); - - expect(propertyAssignmentEntry).toBeDefined(); - expect(propertyAssignmentEntry.data.propertyName).toEqual('DisplayName'); - expect(propertyAssignmentEntry.data.stackTrace.some( - (t: string) => t.includes(`${__filename}:${lineWherePropertyWasSet}`)), - ).toBe(true); - } finally { - delete process.env.CDK_DEBUG; - } - }); - - test('Metadata does not contain propertyAssignment by default', () => { - const stack = new cdk.Stack(); - - const topic = new sns.CfnTopic(stack, 'MyTopic', { - topicName: 'topicName', - }); - - topic.displayName = 'something'; - - const asm = synth(stack); - const metadata = JSON.parse(fs.readFileSync(path.join(asm.directory, 'Default.metadata.json'), 'utf8')); - const propertyAssignmentEntry = metadata['/Default/MyTopic'].find((e: any) => e.type === 'aws:cdk:propertyAssignment'); - - expect(propertyAssignmentEntry).toBeUndefined(); - }); - }); }); - -function synth(stack: cdk.Stack) { - const stage = Stage.of(stack); - if (!Stage.isStage(stage)) { - throw new AssertionError('unexpected: all stacks must be part of a Stage or an App'); - } - - return stage.synth(); -} - -function getLineNumber(): number { - const err = new Error(); - const line = err.stack?.split('\n')[2]?.match(/:(\d+):\d+\)?$/)?.[1]; - return Number(line); -} diff --git a/packages/aws-cdk-lib/core/lib/stack-trace.ts b/packages/aws-cdk-lib/core/lib/stack-trace.ts index 34465562ba04f..965a2bf84722d 100644 --- a/packages/aws-cdk-lib/core/lib/stack-trace.ts +++ b/packages/aws-cdk-lib/core/lib/stack-trace.ts @@ -1,4 +1,3 @@ -import type { Node } from 'constructs'; import { debugModeEnabled } from './debug'; /** @@ -191,25 +190,3 @@ interface CallSite { fileName: string; sourceLocation: string; } - -/** - * Records a metadata entry on a construct node to trace a property assignment. - * - * When debug mode is enabled (via the `CDK_DEBUG` environment variable), - * this attaches `aws:cdk:propertyAssignment` metadata to the given node, - * including a stack trace pointing back to the caller. This is useful for - * diagnosing where a particular property value was set during synthesis. - * - * This is a no-op when debug mode is not enabled. - * - * @param node the construct node to attach the metadata to. - * @param propertyName the name of the property being assigned. - */ -export function traceProperty(node: Node, propertyName: string) { - if (debugModeEnabled()) { - node.addMetadata('aws:cdk:propertyAssignment', { - propertyName, - stackTrace: captureStackTrace(traceProperty), - }); - } -} diff --git a/tools/@aws-cdk/spec2cdk/lib/cdk/cdk.ts b/tools/@aws-cdk/spec2cdk/lib/cdk/cdk.ts index 044b6d637df17..6342428976a08 100644 --- a/tools/@aws-cdk/spec2cdk/lib/cdk/cdk.ts +++ b/tools/@aws-cdk/spec2cdk/lib/cdk/cdk.ts @@ -36,7 +36,6 @@ export class CdkCore extends ExternalModule { public readonly unionMapper = makeCallableExpr(this, 'unionMapper'); public readonly requireProperty = makeCallableExpr(this, 'requireProperty'); public readonly isResolvableObject = makeCallableExpr(this, 'isResolvableObject'); - public readonly traceProperty = makeCallableExpr(this, 'traceProperty'); public readonly mapArrayInPlace = makeCallableExpr(this, 'mapArrayInPlace'); public readonly ValidationResult = $T(Type.fromName(this, 'ValidationResult')); diff --git a/tools/@aws-cdk/spec2cdk/lib/cdk/resource-class.ts b/tools/@aws-cdk/spec2cdk/lib/cdk/resource-class.ts index decf3419419c9..ac0edb2fec6f2 100644 --- a/tools/@aws-cdk/spec2cdk/lib/cdk/resource-class.ts +++ b/tools/@aws-cdk/spec2cdk/lib/cdk/resource-class.ts @@ -217,31 +217,7 @@ export class ResourceClass extends ClassType implements Referenceable { } for (const prop of this.decider.classProperties) { - const spec = prop.propertySpec; - if (spec.immutable) { - this.addProperty(spec); - } else { - // For mutable properties, generate getter and setter - const backingFieldName = `_${spec.name}`; - this.addProperty({ - name: backingFieldName, - type: spec.type, - optional: spec.optional, - visibility: MemberVisibility.Private, - docs: spec.docs, - }); - this.addProperty({ - name: spec.name, - type: spec.type, - optional: spec.optional, - docs: spec.docs, - getterBody: Block.with(stmt.ret($this[backingFieldName])), - setterBody: (value: Expression) => Block.with( - CDK_CORE.traceProperty($this.node, expr.lit(prop.cfnName)), - stmt.assign($this[backingFieldName], value), - ), - }); - } + this.addProperty(prop.propertySpec); } // Copy properties onto class and props type @@ -769,8 +745,8 @@ export class ResourceClass extends ClassType implements Referenceable { init.addBody( // Props - ...this.decider.classProperties.map(({ propertySpec: { name, immutable }, initializer }) => - stmt.assign($this[immutable ? name : `_${name}`], initializer(props)), + ...this.decider.classProperties.map(({ propertySpec: { name }, initializer }) => + stmt.assign($this[name], initializer(props)), ), ); diff --git a/tools/@aws-cdk/spec2cdk/lib/cdk/resource-decider.ts b/tools/@aws-cdk/spec2cdk/lib/cdk/resource-decider.ts index 1b53c644aea26..eb9c5c08a5873 100644 --- a/tools/@aws-cdk/spec2cdk/lib/cdk/resource-decider.ts +++ b/tools/@aws-cdk/spec2cdk/lib/cdk/resource-decider.ts @@ -104,7 +104,6 @@ export class ResourceDecider { immutable: false, docs: this.defaultClassPropDocs(cfnName, prop), }, - cfnName, initializer: resolverResult.resolver, cfnValueToRender: { [resolverResult.name]: $this[resolverResult.name] }, }); @@ -167,7 +166,6 @@ export class ResourceDecider { summary: 'Tag Manager which manages the tags for this resource', }, }, - cfnName, initializer: (props: Expression) => new CDK_CORE.TagManager( this.tagManagerVariant(variant), @@ -186,7 +184,6 @@ export class ResourceDecider { optional: true, // Tags are never required docs: this.defaultClassPropDocs(cfnName, prop), }, - cfnName, initializer: (props: Expression) => $E(props)[originalName], cfnValueToRender: {}, // Gets rendered as part of the TagManager above }, @@ -224,7 +221,6 @@ export class ResourceDecider { summary: 'Tag Manager which manages the tags for this resource', }, }, - cfnName, initializer: (_: Expression) => new CDK_CORE.TagManager( this.tagManagerVariant(variant), @@ -243,7 +239,6 @@ export class ResourceDecider { optional: true, // Tags are never required docs: this.defaultClassPropDocs(cfnName, prop), }, - cfnName, initializer: (props: Expression) => $E(props)[originalName], cfnValueToRender: {}, // Gets rendered as part of the TagManager above }, @@ -369,9 +364,6 @@ export interface PropsProperty { export interface ClassProperty { readonly propertySpec: PropertySpec; - /** The original CloudFormation property name */ - readonly cfnName: string; - /** Given the name of the props value, produce the member value */ readonly initializer: (props: Expression) => Expression; diff --git a/tools/@aws-cdk/spec2cdk/test/__snapshots__/cfn-prop-mixins.test.ts.snap b/tools/@aws-cdk/spec2cdk/test/__snapshots__/cfn-prop-mixins.test.ts.snap index 72bfd7d306dbc..2e34c93f404a7 100644 --- a/tools/@aws-cdk/spec2cdk/test/__snapshots__/cfn-prop-mixins.test.ts.snap +++ b/tools/@aws-cdk/spec2cdk/test/__snapshots__/cfn-prop-mixins.test.ts.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing +// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`L1 property mixin for a standard-issue resource 1`] = ` "/* eslint-disable prettier/prettier, @stylistic/max-len */ diff --git a/tools/@aws-cdk/spec2cdk/test/__snapshots__/fake-services.test.ts.snap b/tools/@aws-cdk/spec2cdk/test/__snapshots__/fake-services.test.ts.snap index 26fb654c3bb6d..013a199352085 100644 --- a/tools/@aws-cdk/spec2cdk/test/__snapshots__/fake-services.test.ts.snap +++ b/tools/@aws-cdk/spec2cdk/test/__snapshots__/fake-services.test.ts.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing +// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`can codegen deprecated service 1`] = ` "/* eslint-disable prettier/prettier, @stylistic/max-len */ @@ -54,7 +54,7 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR /** * The identifier of the resource. */ - private _id?: string; + public id?: string; /** * Create a new \`AWS::Some::Resource\`. @@ -69,7 +69,7 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR properties: props }); - this._id = props.id; + this.id = props.id; } public get resourceRef(): ResourceReference { @@ -78,20 +78,6 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR }; } - /** - * The identifier of the resource. - */ - public get id(): string | undefined { - return this._id; - } - /** - * The identifier of the resource. - */ - public set id(value: string | undefined) { - cdk.traceProperty(this.node, "Id"); - this._id = value; - } - protected get cfnProperties(): Record { return { id: this.id diff --git a/tools/@aws-cdk/spec2cdk/test/__snapshots__/relationships.test.ts.snap b/tools/@aws-cdk/spec2cdk/test/__snapshots__/relationships.test.ts.snap index 10e2436c7b560..c5c1eab1a2fda 100644 --- a/tools/@aws-cdk/spec2cdk/test/__snapshots__/relationships.test.ts.snap +++ b/tools/@aws-cdk/spec2cdk/test/__snapshots__/relationships.test.ts.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing +// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`resource with array of nested properties with relationship 1`] = ` "/* eslint-disable prettier/prettier, @stylistic/max-len */ @@ -192,7 +192,7 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR return (cdk.CfnResource.isCfnResource(x) && (x.cfnResourceType === CfnResource.CFN_RESOURCE_TYPE_NAME)); } - private _permissions?: Array | cdk.IResolvable; + public permissions?: Array | cdk.IResolvable; /** * Create a new \`AWS::IAM::Resource\`. @@ -207,21 +207,13 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR properties: props }); - this._permissions = props.permissions; + this.permissions = props.permissions; } public get resourceRef(): ResourceReference { return {}; } - public get permissions(): Array | cdk.IResolvable | undefined { - return this._permissions; - } - public set permissions(value: Array | cdk.IResolvable | undefined) { - cdk.traceProperty(this.node, "Permissions"); - this._permissions = value; - } - protected get cfnProperties(): Record { return { permissions: this.permissions @@ -693,7 +685,7 @@ export class CfnPolicy extends cdk.CfnResource implements cdk.IInspectable, IPol return (cdk.CfnResource.isCfnResource(x) && (x.cfnResourceType === CfnPolicy.CFN_RESOURCE_TYPE_NAME)); } - private _principalArn?: string; + public principalArn?: string; /** * Create a new \`AWS::IAM::Policy\`. @@ -708,21 +700,13 @@ export class CfnPolicy extends cdk.CfnResource implements cdk.IInspectable, IPol properties: props }); - this._principalArn = cdk.getRefProperty((props.principalArn as iamRefs.IRoleRef)?.roleRef, 'roleArn') ?? cdk.getRefProperty((props.principalArn as iamRefs.IUserRef)?.userRef, 'userArn') ?? cdk.ensureStringOrUndefined(props.principalArn, "principalArn", "iam.IRoleRef | iam.IUserRef | string"); + this.principalArn = cdk.getRefProperty((props.principalArn as iamRefs.IRoleRef)?.roleRef, 'roleArn') ?? cdk.getRefProperty((props.principalArn as iamRefs.IUserRef)?.userRef, 'userArn') ?? cdk.ensureStringOrUndefined(props.principalArn, "principalArn", "iam.IRoleRef | iam.IUserRef | string"); } public get policyRef(): PolicyReference { return {}; } - public get principalArn(): string | undefined { - return this._principalArn; - } - public set principalArn(value: string | undefined) { - cdk.traceProperty(this.node, "PrincipalArn"); - this._principalArn = value; - } - protected get cfnProperties(): Record { return { principalArn: this.principalArn @@ -996,7 +980,7 @@ export class CfnTask extends cdk.CfnResource implements cdk.IInspectable, ITaskR return (cdk.CfnResource.isCfnResource(x) && (x.cfnResourceType === CfnTask.CFN_RESOURCE_TYPE_NAME)); } - private _executionConfig?: CfnTask.ExecutionConfigProperty | cdk.IResolvable; + public executionConfig?: CfnTask.ExecutionConfigProperty | cdk.IResolvable; /** * Create a new \`AWS::IAM::Task\`. @@ -1011,21 +995,13 @@ export class CfnTask extends cdk.CfnResource implements cdk.IInspectable, ITaskR properties: props }); - this._executionConfig = props.executionConfig; + this.executionConfig = props.executionConfig; } public get taskRef(): TaskReference { return {}; } - public get executionConfig(): CfnTask.ExecutionConfigProperty | cdk.IResolvable | undefined { - return this._executionConfig; - } - public set executionConfig(value: CfnTask.ExecutionConfigProperty | cdk.IResolvable | undefined) { - cdk.traceProperty(this.node, "ExecutionConfig"); - this._executionConfig = value; - } - protected get cfnProperties(): Record { return { executionConfig: this.executionConfig @@ -1354,7 +1330,7 @@ export class CfnJob extends cdk.CfnResource implements cdk.IInspectable, IJobRef return (cdk.CfnResource.isCfnResource(x) && (x.cfnResourceType === CfnJob.CFN_RESOURCE_TYPE_NAME)); } - private _config?: cdk.IResolvable | CfnJob.OldConfigProperty; + public config?: cdk.IResolvable | CfnJob.OldConfigProperty; /** * Create a new \`AWS::IAM::Job\`. @@ -1369,21 +1345,13 @@ export class CfnJob extends cdk.CfnResource implements cdk.IInspectable, IJobRef properties: props }); - this._config = props.config; + this.config = props.config; } public get jobRef(): JobReference { return {}; } - public get config(): cdk.IResolvable | CfnJob.OldConfigProperty | undefined { - return this._config; - } - public set config(value: cdk.IResolvable | CfnJob.OldConfigProperty | undefined) { - cdk.traceProperty(this.node, "Config"); - this._config = value; - } - protected get cfnProperties(): Record { return { config: this.config @@ -1775,7 +1743,7 @@ export class CfnFunction extends cdk.CfnResource implements cdk.IInspectable, IF return (cdk.CfnResource.isCfnResource(x) && (x.cfnResourceType === CfnFunction.CFN_RESOURCE_TYPE_NAME)); } - private _roleArn?: string; + public roleArn?: string; /** * Create a new \`AWS::IAM::Function\`. @@ -1790,21 +1758,13 @@ export class CfnFunction extends cdk.CfnResource implements cdk.IInspectable, IF properties: props }); - this._roleArn = cdk.getRefProperty((props.roleArn as iamRefs.IRoleRef)?.roleRef, 'roleArn') ?? cdk.ensureStringOrUndefined(props.roleArn, "roleArn", "iam.IRoleRef | string"); + this.roleArn = cdk.getRefProperty((props.roleArn as iamRefs.IRoleRef)?.roleRef, 'roleArn') ?? cdk.ensureStringOrUndefined(props.roleArn, "roleArn", "iam.IRoleRef | string"); } public get functionRef(): FunctionReference { return {}; } - public get roleArn(): string | undefined { - return this._roleArn; - } - public set roleArn(value: string | undefined) { - cdk.traceProperty(this.node, "RoleArn"); - this._roleArn = value; - } - protected get cfnProperties(): Record { return { roleArn: this.roleArn diff --git a/tools/@aws-cdk/spec2cdk/test/__snapshots__/resources.test.ts.snap b/tools/@aws-cdk/spec2cdk/test/__snapshots__/resources.test.ts.snap index 065b51307ec33..4542534ffd3da 100644 --- a/tools/@aws-cdk/spec2cdk/test/__snapshots__/resources.test.ts.snap +++ b/tools/@aws-cdk/spec2cdk/test/__snapshots__/resources.test.ts.snap @@ -1,4 +1,4 @@ -// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing +// Jest Snapshot v1, https://goo.gl/fbAQLP exports[`can generate interface types into a separate module 1`] = ` "/* eslint-disable prettier/prettier, @stylistic/max-len */ @@ -84,7 +84,7 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR /** * The identifier of the resource. */ - private _id?: string; + public id?: string; /** * Create a new \`AWS::Some::Resource\`. @@ -99,7 +99,7 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR properties: props }); - this._id = props.id; + this.id = props.id; } public get resourceRef(): ResourceReference { @@ -108,20 +108,6 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR }; } - /** - * The identifier of the resource. - */ - public get id(): string | undefined { - return this._id; - } - /** - * The identifier of the resource. - */ - public set id(value: string | undefined) { - cdk.traceProperty(this.node, "Id"); - this._id = value; - } - protected get cfnProperties(): Record { return { id: this.id @@ -256,7 +242,7 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR /** * The identifier of the resource. */ - private _id?: string; + public id?: string; /** * Create a new \`AWS::Some::Resource\`. @@ -271,7 +257,7 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR properties: props }); - this._id = props.id; + this.id = props.id; } public get resourceRef(): ResourceReference { @@ -280,20 +266,6 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR }; } - /** - * The identifier of the resource. - */ - public get id(): string | undefined { - return this._id; - } - /** - * The identifier of the resource. - */ - public set id(value: string | undefined) { - cdk.traceProperty(this.node, "Id"); - this._id = value; - } - protected get cfnProperties(): Record { return { id: this.id @@ -906,7 +878,7 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR /** * The arn for the resource. */ - private _arn?: string; + public arn?: string; /** * Create a new \`AWS::Some::Resource\`. @@ -921,7 +893,7 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR properties: props }); - this._arn = props.arn; + this.arn = props.arn; } public get resourceRef(): ResourceReference { @@ -930,20 +902,6 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR }; } - /** - * The arn for the resource. - */ - public get arn(): string | undefined { - return this._arn; - } - /** - * The arn for the resource. - */ - public set arn(value: string | undefined) { - cdk.traceProperty(this.node, "Arn"); - this._arn = value; - } - /** * The identifier of the resource * @@ -1434,7 +1392,7 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR /** * The identifier of the resource. */ - private _id?: string; + public id?: string; /** * Create a new \`AWS::Some::Resource\`. @@ -1449,7 +1407,7 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR properties: props }); - this._id = props.id; + this.id = props.id; } public get resourceRef(): ResourceReference { @@ -1458,20 +1416,6 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR }; } - /** - * The identifier of the resource. - */ - public get id(): string | undefined { - return this._id; - } - /** - * The identifier of the resource. - */ - public set id(value: string | undefined) { - cdk.traceProperty(this.node, "Id"); - this._id = value; - } - protected get cfnProperties(): Record { return { id: this.id @@ -1606,12 +1550,12 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR /** * Another identifier of the resource. */ - private _anotherId?: string; + public anotherId?: string; /** * The identifier of the resource. */ - private _id?: string; + public id?: string; /** * Create a new \`AWS::Some::Resource\`. @@ -1626,8 +1570,8 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR properties: props }); - this._anotherId = props.anotherId; - this._id = props.id; + this.anotherId = props.anotherId; + this.id = props.id; } public get resourceRef(): ResourceReference { @@ -1637,34 +1581,6 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR }; } - /** - * Another identifier of the resource. - */ - public get anotherId(): string | undefined { - return this._anotherId; - } - /** - * Another identifier of the resource. - */ - public set anotherId(value: string | undefined) { - cdk.traceProperty(this.node, "AnotherId"); - this._anotherId = value; - } - - /** - * The identifier of the resource. - */ - public get id(): string | undefined { - return this._id; - } - /** - * The identifier of the resource. - */ - public set id(value: string | undefined) { - cdk.traceProperty(this.node, "Id"); - this._id = value; - } - protected get cfnProperties(): Record { return { anotherId: this.anotherId, @@ -1810,7 +1726,7 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR /** * The identifier of the resource. */ - private _id?: string; + public id?: string; /** * Create a new \`AWS::Some::Resource\`. @@ -1825,7 +1741,7 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR properties: props }); - this._id = props.id; + this.id = props.id; } public get resourceRef(): ResourceReference { @@ -1834,20 +1750,6 @@ export class CfnResource extends cdk.CfnResource implements cdk.IInspectable, IR }; } - /** - * The identifier of the resource. - */ - public get id(): string | undefined { - return this._id; - } - /** - * The identifier of the resource. - */ - public set id(value: string | undefined) { - cdk.traceProperty(this.node, "Id"); - this._id = value; - } - protected get cfnProperties(): Record { return { id: this.id diff --git a/tools/@aws-cdk/spec2cdk/test/relationships.test.ts b/tools/@aws-cdk/spec2cdk/test/relationships.test.ts index e3a5ce90e7525..675fe5e17f573 100644 --- a/tools/@aws-cdk/spec2cdk/test/relationships.test.ts +++ b/tools/@aws-cdk/spec2cdk/test/relationships.test.ts @@ -322,6 +322,6 @@ test('relationship have arns appear first in the constructor chain', () => { const rendered = renderer.render(module); - const chain = 'this._roleArn = cdk.getRefProperty((props.roleArn as iamRefs.IRoleRef)?.roleRef, \'roleArn\') ?? cdk.getRefProperty((props.roleArn as iamRefs.IRoleRef)?.roleRef, \'roleName\') ?? cdk.getRefProperty((props.roleArn as iamRefs.IRoleRef)?.roleRef, \'otherPrimaryId\') ?? cdk.ensureStringOrUndefined(props.roleArn, "roleArn", "iam.IRoleRef | string")'; + const chain = 'this.roleArn = cdk.getRefProperty((props.roleArn as iamRefs.IRoleRef)?.roleRef, \'roleArn\') ?? cdk.getRefProperty((props.roleArn as iamRefs.IRoleRef)?.roleRef, \'roleName\') ?? cdk.getRefProperty((props.roleArn as iamRefs.IRoleRef)?.roleRef, \'otherPrimaryId\') ?? cdk.ensureStringOrUndefined(props.roleArn, "roleArn", "iam.IRoleRef | string")'; expect(rendered).toContain(chain); }); diff --git a/tools/@aws-cdk/spec2cdk/test/resources.test.ts b/tools/@aws-cdk/spec2cdk/test/resources.test.ts index 2e179f0fd41ed..269322c2b1867 100644 --- a/tools/@aws-cdk/spec2cdk/test/resources.test.ts +++ b/tools/@aws-cdk/spec2cdk/test/resources.test.ts @@ -443,43 +443,6 @@ test('CFN reference identifier of same length as CC-API identifier aliases field ); }); -describe('Source tracing', () => { - test('generates setter for each property, with a call to traceProperty', () => { - givenResource({ - ...BASE_RESOURCE, - attributes: { - Arn: { - type: { type: 'string' }, - documentation: 'The ARN of this resource', - }, - }, - primaryIdentifier: ['Id'], - cfnRefIdentifier: ['Arn'], - properties: { - Id: { - type: { type: 'string' }, - }, - Foo: { - type: { type: 'string' }, - }, - }, - }); - - // THEN - const rendered = renderResource(); - - expect(rendered.resources).toContainCode(`public set id(value: string | undefined) { - cdk.traceProperty(this.node, "Id"); - this._id = value; - }`); - - expect(rendered.resources).toContainCode(`public set foo(value: string | undefined) { - cdk.traceProperty(this.node, "Foo"); - this._foo = value; - }`); - }); -}); - function givenResource(res: Plain) { db.link('hasResource', service, db.allocate('resource', res)); }