Skip to content

Commit

Permalink
[tcgc] add crossLanguageDefinitionId onto method types (Azure#748)
Browse files Browse the repository at this point in the history
Co-authored-by: iscai-msft <[email protected]>
  • Loading branch information
iscai-msft and iscai-msft committed Apr 26, 2024
1 parent 0bf5e3e commit 80e052f
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .chronus/changes/fix_cross_language-2024-3-26-13-30-49.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-client-generator-core"
---

add crossLanguageDefinitionId onto method types
1 change: 1 addition & 0 deletions packages/typespec-client-generator-core/src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ interface SdkMethodBase {
apiVersions: string[];
description?: string;
details?: string;
crossLanguageDefintionId: string;
}

interface SdkServiceMethodBase<TServiceOperation extends SdkServiceOperation>
Expand Down
6 changes: 5 additions & 1 deletion packages/typespec-client-generator-core/src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import {
import { createDiagnostic } from "./lib.js";
import {
getClientNamespaceString,
getCrossLanguageDefinitionId,
getCrossLanguagePackageId,
getDefaultApiVersion,
getEffectivePayloadType,
Expand Down Expand Up @@ -286,6 +287,7 @@ function getSdkBasicServiceMethod<
getResponseMapping: function getResponseMapping(): string | undefined {
return undefined; // currently we only return a value for paging or lro
},
crossLanguageDefintionId: getCrossLanguageDefinitionId({ ...operation, name }),
});
}

Expand Down Expand Up @@ -412,15 +414,17 @@ function getSdkMethods<TOptions extends object, TServiceOperation extends SdkSer
for (const operationGroup of listOperationGroups(context, client)) {
// We create a client accessor for each operation group
const operationGroupClient = diagnostics.pipe(createSdkClientType(context, operationGroup));
const name = `get${operationGroup.type.name}`;
retval.push({
kind: "clientaccessor",
parameters: [],
name: `get${operationGroup.type.name}`,
name,
description: getDocHelper(context, operationGroup.type).description,
details: getDocHelper(context, operationGroup.type).details,
access: "internal",
response: operationGroupClient,
apiVersions: getAvailableApiVersions(context, operationGroup.type),
crossLanguageDefintionId: getCrossLanguageDefinitionId({ ...operationGroup.type, name }),
});
}
return diagnostics.wrap(retval);
Expand Down
37 changes: 37 additions & 0 deletions packages/typespec-client-generator-core/test/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,16 @@ describe("typespec-client-generator-core: package", () => {
strictEqual(clientAccessor.name, "getMyOperationGroup");
strictEqual(clientAccessor.parameters.length, 0);
strictEqual(clientAccessor.response, operationGroup);
strictEqual(clientAccessor.crossLanguageDefintionId, "TestService.getMyOperationGroup");

strictEqual(operationGroup.initialization.properties.length, 1);
strictEqual(operationGroup.initialization.access, "internal");
strictEqual(operationGroup.methods.length, 1);
strictEqual(operationGroup.methods[0].name, "func");
strictEqual(
operationGroup.methods[0].crossLanguageDefintionId,
"TestService.MyOperationGroup.func"
);
});

it("operationGroup2", async () => {
Expand Down Expand Up @@ -612,6 +617,7 @@ describe("typespec-client-generator-core: package", () => {

const fooAccessor = mainClient.methods[0];
strictEqual(fooAccessor.kind, "clientaccessor");
strictEqual(fooAccessor.crossLanguageDefintionId, "TestService.getFoo");
strictEqual(fooAccessor.access, "internal");
strictEqual(fooAccessor.name, "getFoo");
strictEqual(fooAccessor.parameters.length, 0);
Expand All @@ -621,6 +627,7 @@ describe("typespec-client-generator-core: package", () => {
strictEqual(barAccessor.kind, "clientaccessor");
strictEqual(barAccessor.access, "internal");
strictEqual(barAccessor.name, "getBar");
strictEqual(barAccessor.crossLanguageDefintionId, "TestService.getBar");
strictEqual(barAccessor.parameters.length, 0);
strictEqual(barAccessor.response, barClient);

Expand All @@ -630,6 +637,7 @@ describe("typespec-client-generator-core: package", () => {

const fooBarAccessor = fooClient.methods[0];
strictEqual(fooBarAccessor.kind, "clientaccessor");
strictEqual(fooBarAccessor.crossLanguageDefintionId, "TestService.Foo.getBar");
strictEqual(fooBarAccessor.access, "internal");
strictEqual(fooBarAccessor.name, "getBar");
strictEqual(fooBarAccessor.parameters.length, 0);
Expand All @@ -640,12 +648,14 @@ describe("typespec-client-generator-core: package", () => {
strictEqual(fooBarClient.methods.length, 1);
strictEqual(fooBarClient.methods[0].kind, "basic");
strictEqual(fooBarClient.methods[0].name, "one");
strictEqual(fooBarClient.methods[0].crossLanguageDefintionId, "TestService.Foo.Bar.one");

strictEqual(barClient.initialization.properties.length, 1);
strictEqual(barClient.initialization.access, "internal");
strictEqual(barClient.methods.length, 1);
strictEqual(barClient.methods[0].kind, "basic");
strictEqual(barClient.methods[0].name, "two");
strictEqual(barClient.methods[0].crossLanguageDefintionId, "TestService.Bar.two");
});

function getServiceNoDefaultApiVersion(op: string) {
Expand Down Expand Up @@ -804,6 +814,10 @@ describe("typespec-client-generator-core: package", () => {
strictEqual(withoutApiVersion.kind, "basic");
strictEqual(withoutApiVersion.parameters.length, 0);
strictEqual(withoutApiVersion.operation.parameters.length, 0);
strictEqual(
withoutApiVersion.crossLanguageDefintionId,
"Server.Versions.Versioned.withoutApiVersion"
);
});

it("service with default api version, method with api version param", async () => {
Expand Down Expand Up @@ -843,6 +857,10 @@ describe("typespec-client-generator-core: package", () => {
const withApiVersion = client.methods[0];
strictEqual(withApiVersion.name, "withQueryApiVersion");
strictEqual(withApiVersion.kind, "basic");
strictEqual(
withApiVersion.crossLanguageDefintionId,
"Server.Versions.Versioned.withQueryApiVersion"
);
strictEqual(withApiVersion.parameters.length, 1);
strictEqual(withApiVersion.operation.parameters.length, 1);
strictEqual(withApiVersion.parameters[0].isApiVersionParam, true);
Expand Down Expand Up @@ -894,6 +912,10 @@ describe("typespec-client-generator-core: package", () => {
const withApiVersion = client.methods[0];
strictEqual(withApiVersion.name, "withPathApiVersion");
strictEqual(withApiVersion.kind, "basic");
strictEqual(
withApiVersion.crossLanguageDefintionId,
"Server.Versions.Versioned.withPathApiVersion"
);
strictEqual(withApiVersion.parameters.length, 1);
strictEqual(withApiVersion.parameters[0].isApiVersionParam, true);
strictEqual(withApiVersion.parameters[0].name, "apiVersion");
Expand Down Expand Up @@ -924,6 +946,7 @@ describe("typespec-client-generator-core: package", () => {
const method = getServiceMethodOfClient(sdkPackage);
strictEqual(method.name, "myOp");
strictEqual(method.kind, "basic");
strictEqual(method.crossLanguageDefintionId, "My.Service.myOp");
strictEqual(method.parameters.length, 1);

const methodParam = method.parameters[0];
Expand Down Expand Up @@ -999,6 +1022,7 @@ describe("typespec-client-generator-core: package", () => {
const method = getServiceMethodOfClient(sdkPackage);
strictEqual(method.name, "pathInModel");
strictEqual(method.kind, "basic");
strictEqual(method.crossLanguageDefintionId, "TestService.pathInModel");
strictEqual(method.parameters.length, 1);
const pathMethod = method.parameters[0];
strictEqual(pathMethod.kind, "method");
Expand Down Expand Up @@ -1037,6 +1061,7 @@ describe("typespec-client-generator-core: package", () => {
const method = getServiceMethodOfClient(sdkPackage);
strictEqual(method.name, "myOp");
strictEqual(method.kind, "basic");
strictEqual(method.crossLanguageDefintionId, "My.Service.myOp");
strictEqual(method.parameters.length, 1);

const methodParam = method.parameters[0];
Expand Down Expand Up @@ -2424,6 +2449,10 @@ describe("typespec-client-generator-core: package", () => {
ok(getStatus);
strictEqual(getStatus.name, "getWidgetOperationStatus");
strictEqual(getStatus.kind, "basic");
strictEqual(
getStatus.crossLanguageDefintionId,
"Contoso.WidgetManager.Widgets.getWidgetOperationStatus"
);
strictEqual(getStatus.parameters.length, 4);

const methodWidgetName = getStatus.parameters.find((p) => p.name === "widgetName");
Expand Down Expand Up @@ -2504,6 +2533,10 @@ describe("typespec-client-generator-core: package", () => {
const createOrUpdate = client.methods.find((x) => x.name === "createOrUpdateWidget");
ok(createOrUpdate);
strictEqual(createOrUpdate.kind, "lro");
strictEqual(
createOrUpdate.crossLanguageDefintionId,
"Contoso.WidgetManager.Widgets.createOrUpdateWidget"
);
deepStrictEqual(
createOrUpdate.parameters.map((x) => x.name),
[
Expand Down Expand Up @@ -2638,6 +2671,10 @@ describe("typespec-client-generator-core: package", () => {
const listManufacturers = widgetClient.methods[0];

strictEqual(listManufacturers.name, "listManufacturers");
strictEqual(
listManufacturers.crossLanguageDefintionId,
"Contoso.WidgetManager.Widgets.listManufacturers"
);
strictEqual(listManufacturers.kind, "paging");
strictEqual(listManufacturers.parameters.length, 3);
deepStrictEqual(
Expand Down

0 comments on commit 80e052f

Please sign in to comment.