From db1b6056d2770d32d5743f1fb4c51682bb28a6be Mon Sep 17 00:00:00 2001 From: Haoling Dong Date: Thu, 25 Jul 2024 11:26:23 +0800 Subject: [PATCH 1/8] logics to add crossLanguageDefinitionId on sdkClientType --- packages/typespec-client-generator-core/src/interfaces.ts | 1 + packages/typespec-client-generator-core/src/package.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/typespec-client-generator-core/src/interfaces.ts b/packages/typespec-client-generator-core/src/interfaces.ts index 03953e8b6d..565dae3459 100644 --- a/packages/typespec-client-generator-core/src/interfaces.ts +++ b/packages/typespec-client-generator-core/src/interfaces.ts @@ -96,6 +96,7 @@ export interface SdkClientType methods: SdkMethod[]; apiVersions: string[]; nameSpace: string; // fully qualified + crossLanguageDefinitionId: string; /** * @deprecated This property is deprecated. Look at `.arm` on `SdkContext` instead. */ diff --git a/packages/typespec-client-generator-core/src/package.ts b/packages/typespec-client-generator-core/src/package.ts index 7f100a7bf2..74a2fadeaf 100644 --- a/packages/typespec-client-generator-core/src/package.ts +++ b/packages/typespec-client-generator-core/src/package.ts @@ -522,6 +522,7 @@ function createSdkClientType( // eslint-disable-next-line deprecation/deprecation arm: client.kind === "SdkClient" ? client.arm : false, decorators: diagnostics.pipe(getTypeDecorators(context, client.type)), + crossLanguageDefinitionId: isClient ? `${getClientNamespaceStringHelper(context, client.service)}.${clientName}` : getCrossLanguageDefinitionId(context, client.type), }; return diagnostics.wrap(sdkClientType); } From 55b1440e2c4b76ed4f96309972234b4178647c3c Mon Sep 17 00:00:00 2001 From: Haoling Dong Date: Thu, 25 Jul 2024 11:26:48 +0800 Subject: [PATCH 2/8] add tests --- .../typespec-client-generator-core/test/package.test.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/typespec-client-generator-core/test/package.test.ts b/packages/typespec-client-generator-core/test/package.test.ts index 72377d6cba..5bb79d60eb 100644 --- a/packages/typespec-client-generator-core/test/package.test.ts +++ b/packages/typespec-client-generator-core/test/package.test.ts @@ -447,6 +447,7 @@ describe("typespec-client-generator-core: package", () => { strictEqual(sdkPackage.clients.length, 1); const client = sdkPackage.clients[0]; strictEqual(client.name, "ServiceClient"); + strictEqual(client.crossLanguageDefinitionId, "My.Service.ServiceClient"); strictEqual(client.initialization.properties.length, 3); strictEqual(client.apiVersions.length, 1); strictEqual(client.apiVersions[0], "2022-12-01-preview"); @@ -516,6 +517,7 @@ describe("typespec-client-generator-core: package", () => { strictEqual(sdkPackage.clients.length, 1); const client = sdkPackage.clients[0]; strictEqual(client.name, "ServiceClient"); + strictEqual(client.crossLanguageDefinitionId, "My.Service.ServiceClient"); strictEqual(client.initialization.properties.length, 3); strictEqual(client.apiVersions.length, 2); deepStrictEqual(client.apiVersions, ["2022-12-01-preview", "2022-12-01"]); @@ -579,6 +581,7 @@ describe("typespec-client-generator-core: package", () => { strictEqual(mainClient.methods.length, 1); strictEqual(mainClient.initialization.properties.length, 1); strictEqual(mainClient.initialization.properties[0].name, "endpoint"); + strictEqual(mainClient.crossLanguageDefinitionId, "TestService.TestServiceClient"); const clientAccessor = mainClient.methods[0]; strictEqual(clientAccessor.kind, "clientaccessor"); @@ -596,6 +599,7 @@ describe("typespec-client-generator-core: package", () => { operationGroup.methods[0].crossLanguageDefintionId, "TestService.MyOperationGroup.func" ); + strictEqual(operationGroup.crossLanguageDefinitionId, "TestService.MyOperationGroup") }); it("operationGroup2", async () => { @@ -629,6 +633,7 @@ describe("typespec-client-generator-core: package", () => { ok(mainClient.initialization); strictEqual(mainClient.initialization.properties.length, 1); strictEqual(mainClient.initialization.properties[0].name, "endpoint"); + strictEqual(mainClient.crossLanguageDefinitionId, "TestService.TestServiceClient") const fooAccessor = mainClient.methods[0]; strictEqual(fooAccessor.kind, "clientaccessor"); @@ -649,6 +654,8 @@ describe("typespec-client-generator-core: package", () => { strictEqual(fooClient.initialization.properties.length, 1); strictEqual(fooClient.initialization.access, "internal"); strictEqual(fooClient.methods.length, 1); + strictEqual(fooClient.crossLanguageDefinitionId, "TestService.Foo") + const fooBarAccessor = fooClient.methods[0]; strictEqual(fooBarAccessor.kind, "clientaccessor"); @@ -660,6 +667,7 @@ describe("typespec-client-generator-core: package", () => { strictEqual(fooBarClient.initialization.properties.length, 1); strictEqual(fooBarClient.initialization.access, "internal"); + strictEqual(fooBarClient.crossLanguageDefinitionId, "TestService.Foo.Bar"); strictEqual(fooBarClient.methods.length, 1); strictEqual(fooBarClient.methods[0].kind, "basic"); strictEqual(fooBarClient.methods[0].name, "one"); @@ -667,6 +675,7 @@ describe("typespec-client-generator-core: package", () => { strictEqual(barClient.initialization.properties.length, 1); strictEqual(barClient.initialization.access, "internal"); + strictEqual(barClient.crossLanguageDefinitionId, "TestService.Bar"); strictEqual(barClient.methods.length, 1); strictEqual(barClient.methods[0].kind, "basic"); strictEqual(barClient.methods[0].name, "two"); From 1f306ee283aeda10f1c7a72dce379cba41231b7e Mon Sep 17 00:00:00 2001 From: Haoling Dong <87355844+haolingdong-msft@users.noreply.github.com> Date: Thu, 25 Jul 2024 11:33:50 +0800 Subject: [PATCH 3/8] Create client-cross-language-id-2024-6-25-3-32-24.md --- .../changes/client-cross-language-id-2024-6-25-3-32-24.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .chronus/changes/client-cross-language-id-2024-6-25-3-32-24.md diff --git a/.chronus/changes/client-cross-language-id-2024-6-25-3-32-24.md b/.chronus/changes/client-cross-language-id-2024-6-25-3-32-24.md new file mode 100644 index 0000000000..ab8f5f6bd2 --- /dev/null +++ b/.chronus/changes/client-cross-language-id-2024-6-25-3-32-24.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@azure-tools/typespec-client-generator-core" +--- + +TCGC, add `crossLanguageDefinitionId` to `SdkClientType` From 81cddb1a87245fc8dc54732c1f6391e8c7357cae Mon Sep 17 00:00:00 2001 From: Haoling Dong Date: Thu, 25 Jul 2024 11:39:21 +0800 Subject: [PATCH 4/8] format --- packages/typespec-client-generator-core/src/package.ts | 5 ++++- .../typespec-client-generator-core/test/package.test.ts | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/typespec-client-generator-core/src/package.ts b/packages/typespec-client-generator-core/src/package.ts index 74a2fadeaf..4f88a08b56 100644 --- a/packages/typespec-client-generator-core/src/package.ts +++ b/packages/typespec-client-generator-core/src/package.ts @@ -522,7 +522,10 @@ function createSdkClientType( // eslint-disable-next-line deprecation/deprecation arm: client.kind === "SdkClient" ? client.arm : false, decorators: diagnostics.pipe(getTypeDecorators(context, client.type)), - crossLanguageDefinitionId: isClient ? `${getClientNamespaceStringHelper(context, client.service)}.${clientName}` : getCrossLanguageDefinitionId(context, client.type), + // if it is client, the crossLanguageDefinitionId is the namespace.TestClient, if it is operation group, the crosslanguageDefinitionId is the namespace.Test + crossLanguageDefinitionId: isClient + ? `${getClientNamespaceStringHelper(context, client.service)}.${clientName}` + : getCrossLanguageDefinitionId(context, client.type), }; return diagnostics.wrap(sdkClientType); } diff --git a/packages/typespec-client-generator-core/test/package.test.ts b/packages/typespec-client-generator-core/test/package.test.ts index 5bb79d60eb..695d9dad41 100644 --- a/packages/typespec-client-generator-core/test/package.test.ts +++ b/packages/typespec-client-generator-core/test/package.test.ts @@ -599,7 +599,7 @@ describe("typespec-client-generator-core: package", () => { operationGroup.methods[0].crossLanguageDefintionId, "TestService.MyOperationGroup.func" ); - strictEqual(operationGroup.crossLanguageDefinitionId, "TestService.MyOperationGroup") + strictEqual(operationGroup.crossLanguageDefinitionId, "TestService.MyOperationGroup"); }); it("operationGroup2", async () => { @@ -633,7 +633,7 @@ describe("typespec-client-generator-core: package", () => { ok(mainClient.initialization); strictEqual(mainClient.initialization.properties.length, 1); strictEqual(mainClient.initialization.properties[0].name, "endpoint"); - strictEqual(mainClient.crossLanguageDefinitionId, "TestService.TestServiceClient") + strictEqual(mainClient.crossLanguageDefinitionId, "TestService.TestServiceClient"); const fooAccessor = mainClient.methods[0]; strictEqual(fooAccessor.kind, "clientaccessor"); @@ -654,8 +654,7 @@ describe("typespec-client-generator-core: package", () => { strictEqual(fooClient.initialization.properties.length, 1); strictEqual(fooClient.initialization.access, "internal"); strictEqual(fooClient.methods.length, 1); - strictEqual(fooClient.crossLanguageDefinitionId, "TestService.Foo") - + strictEqual(fooClient.crossLanguageDefinitionId, "TestService.Foo"); const fooBarAccessor = fooClient.methods[0]; strictEqual(fooBarAccessor.kind, "clientaccessor"); From b0337311feb108c1dbdc7dccc941630de09452e2 Mon Sep 17 00:00:00 2001 From: Haoling Dong Date: Mon, 29 Jul 2024 16:19:53 +0800 Subject: [PATCH 5/8] update according to comments --- packages/typespec-client-generator-core/src/decorators.ts | 2 +- packages/typespec-client-generator-core/src/package.ts | 4 +--- .../typespec-client-generator-core/test/package.test.ts | 8 ++++---- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index 71388e1393..d44fdbce33 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -335,7 +335,7 @@ export function listClients(context: TCGCContext): SdkClient[] { service: service.type, type: service.type, arm: isArm(service.type), - crossLanguageDefinitionId: `${getNamespaceFullName(service.type)}.${clientName}`, + crossLanguageDefinitionId: `${getNamespaceFullName(service.type)}.${originalName}`, } as SdkClient; }); diff --git a/packages/typespec-client-generator-core/src/package.ts b/packages/typespec-client-generator-core/src/package.ts index 4f88a08b56..3f1687efd5 100644 --- a/packages/typespec-client-generator-core/src/package.ts +++ b/packages/typespec-client-generator-core/src/package.ts @@ -523,9 +523,7 @@ function createSdkClientType( arm: client.kind === "SdkClient" ? client.arm : false, decorators: diagnostics.pipe(getTypeDecorators(context, client.type)), // if it is client, the crossLanguageDefinitionId is the namespace.TestClient, if it is operation group, the crosslanguageDefinitionId is the namespace.Test - crossLanguageDefinitionId: isClient - ? `${getClientNamespaceStringHelper(context, client.service)}.${clientName}` - : getCrossLanguageDefinitionId(context, client.type), + crossLanguageDefinitionId: getCrossLanguageDefinitionId(context, client.type), }; return diagnostics.wrap(sdkClientType); } diff --git a/packages/typespec-client-generator-core/test/package.test.ts b/packages/typespec-client-generator-core/test/package.test.ts index 695d9dad41..7fee3a1810 100644 --- a/packages/typespec-client-generator-core/test/package.test.ts +++ b/packages/typespec-client-generator-core/test/package.test.ts @@ -447,7 +447,7 @@ describe("typespec-client-generator-core: package", () => { strictEqual(sdkPackage.clients.length, 1); const client = sdkPackage.clients[0]; strictEqual(client.name, "ServiceClient"); - strictEqual(client.crossLanguageDefinitionId, "My.Service.ServiceClient"); + strictEqual(client.crossLanguageDefinitionId, "My.Service"); strictEqual(client.initialization.properties.length, 3); strictEqual(client.apiVersions.length, 1); strictEqual(client.apiVersions[0], "2022-12-01-preview"); @@ -517,7 +517,7 @@ describe("typespec-client-generator-core: package", () => { strictEqual(sdkPackage.clients.length, 1); const client = sdkPackage.clients[0]; strictEqual(client.name, "ServiceClient"); - strictEqual(client.crossLanguageDefinitionId, "My.Service.ServiceClient"); + strictEqual(client.crossLanguageDefinitionId, "My.Service"); strictEqual(client.initialization.properties.length, 3); strictEqual(client.apiVersions.length, 2); deepStrictEqual(client.apiVersions, ["2022-12-01-preview", "2022-12-01"]); @@ -581,7 +581,7 @@ describe("typespec-client-generator-core: package", () => { strictEqual(mainClient.methods.length, 1); strictEqual(mainClient.initialization.properties.length, 1); strictEqual(mainClient.initialization.properties[0].name, "endpoint"); - strictEqual(mainClient.crossLanguageDefinitionId, "TestService.TestServiceClient"); + strictEqual(mainClient.crossLanguageDefinitionId, "TestService"); const clientAccessor = mainClient.methods[0]; strictEqual(clientAccessor.kind, "clientaccessor"); @@ -633,7 +633,7 @@ describe("typespec-client-generator-core: package", () => { ok(mainClient.initialization); strictEqual(mainClient.initialization.properties.length, 1); strictEqual(mainClient.initialization.properties[0].name, "endpoint"); - strictEqual(mainClient.crossLanguageDefinitionId, "TestService.TestServiceClient"); + strictEqual(mainClient.crossLanguageDefinitionId, "TestService"); const fooAccessor = mainClient.methods[0]; strictEqual(fooAccessor.kind, "clientaccessor"); From 1033e3595dbea3beefda23a97ba6147a6e0c1fed Mon Sep 17 00:00:00 2001 From: Haoling Dong Date: Tue, 30 Jul 2024 11:12:12 +0800 Subject: [PATCH 6/8] update according to comments --- packages/typespec-client-generator-core/src/decorators.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/typespec-client-generator-core/src/decorators.ts b/packages/typespec-client-generator-core/src/decorators.ts index d44fdbce33..ca48fc0b5a 100644 --- a/packages/typespec-client-generator-core/src/decorators.ts +++ b/packages/typespec-client-generator-core/src/decorators.ts @@ -335,7 +335,7 @@ export function listClients(context: TCGCContext): SdkClient[] { service: service.type, type: service.type, arm: isArm(service.type), - crossLanguageDefinitionId: `${getNamespaceFullName(service.type)}.${originalName}`, + crossLanguageDefinitionId: getNamespaceFullName(service.type), } as SdkClient; }); From 8709b83e6d6a3300a2b917391010d69fbfa11c5c Mon Sep 17 00:00:00 2001 From: Haoling Dong Date: Wed, 31 Jul 2024 10:26:08 +0800 Subject: [PATCH 7/8] refine comment --- packages/typespec-client-generator-core/src/package.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/typespec-client-generator-core/src/package.ts b/packages/typespec-client-generator-core/src/package.ts index 3f1687efd5..2dcff379ad 100644 --- a/packages/typespec-client-generator-core/src/package.ts +++ b/packages/typespec-client-generator-core/src/package.ts @@ -522,7 +522,7 @@ function createSdkClientType( // eslint-disable-next-line deprecation/deprecation arm: client.kind === "SdkClient" ? client.arm : false, decorators: diagnostics.pipe(getTypeDecorators(context, client.type)), - // if it is client, the crossLanguageDefinitionId is the namespace.TestClient, if it is operation group, the crosslanguageDefinitionId is the namespace.Test + // if it is client, the crossLanguageDefinitionId is the ${namespace}, if it is operation group, the crosslanguageDefinitionId is the %{namespace}.%{operationGroupName} crossLanguageDefinitionId: getCrossLanguageDefinitionId(context, client.type), }; return diagnostics.wrap(sdkClientType); From f91476e2472a4c5444e69fd35c3255124ab27679 Mon Sep 17 00:00:00 2001 From: Haoling Dong Date: Wed, 31 Jul 2024 12:27:10 +0800 Subject: [PATCH 8/8] fix tests --- .../typespec-client-generator-core/test/decorators.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/typespec-client-generator-core/test/decorators.test.ts b/packages/typespec-client-generator-core/test/decorators.test.ts index 2ef945a06e..83785428ff 100644 --- a/packages/typespec-client-generator-core/test/decorators.test.ts +++ b/packages/typespec-client-generator-core/test/decorators.test.ts @@ -177,7 +177,7 @@ describe("typespec-client-generator-core: decorators", () => { service: MyService, type: MyService, arm: false, - crossLanguageDefinitionId: "MyService.MyServiceClient", + crossLanguageDefinitionId: "MyService", }, ]); }); @@ -431,7 +431,7 @@ describe("typespec-client-generator-core: decorators", () => { service: MyService, type: MyService, arm: false, - crossLanguageDefinitionId: "MyService.MyServiceClient", + crossLanguageDefinitionId: "MyService", }, ]); });