From f546ee618e2b698face7785acc8cbb52882cf1b6 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Mon, 1 Apr 2024 10:40:30 -0400 Subject: [PATCH 1/5] look at final result when present --- .../src/package.ts | 12 ++++++++---- .../test/package.test.ts | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/packages/typespec-client-generator-core/src/package.ts b/packages/typespec-client-generator-core/src/package.ts index 7a2989b6cb..d45b982bb7 100644 --- a/packages/typespec-client-generator-core/src/package.ts +++ b/packages/typespec-client-generator-core/src/package.ts @@ -154,10 +154,14 @@ function getSdkLroServiceMethod< const basicServiceMethod = diagnostics.pipe( getSdkBasicServiceMethod(context, operation) ); - - basicServiceMethod.response.type = diagnostics.pipe( - getClientTypeWithDiagnostics(context, metadata.logicalResult) - ); + const finalResult = metadata.finalResult ?? metadata.logicalResult; + if (finalResult === "void") { + basicServiceMethod.response.type = undefined; + } else if (finalResult) { + basicServiceMethod.response.type = diagnostics.pipe( + getClientTypeWithDiagnostics(context, finalResult) + ); + } return diagnostics.wrap({ ...basicServiceMethod, kind: "lro", diff --git a/packages/typespec-client-generator-core/test/package.test.ts b/packages/typespec-client-generator-core/test/package.test.ts index 2e9483727c..7d71d13daa 100644 --- a/packages/typespec-client-generator-core/test/package.test.ts +++ b/packages/typespec-client-generator-core/test/package.test.ts @@ -2767,6 +2767,23 @@ describe("typespec-client-generator-core: package", () => { strictEqual(methodResponse.type, widgetModel); strictEqual(createOrUpdate.getResponseMapping(), "result"); }); + it("lro delete", async () => { + const runnerWithCore = await createSdkTestRunner({ + librariesToAdd: [AzureCoreTestLibrary], + autoUsings: ["Azure.Core", "Azure.Core.Traits"], + emitterName: "@azure-tools/typespec-java", + }); + await compileAzureWidgetService( + runnerWithCore, + ` + op delete is ResourceOperations.LongRunningResourceDelete; + ` + ); + const method = getServiceMethodOfClient(runnerWithCore.context.experimental_sdkPackage); + strictEqual(method.name, "delete"); + strictEqual(method.kind, "lro"); + strictEqual(method.response.type, undefined); + }); it("paging", async () => { const runnerWithCore = await createSdkTestRunner({ librariesToAdd: [AzureCoreTestLibrary], From cd0fa543ab00981661c1417016a796321f2cb350 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Mon, 1 Apr 2024 10:56:00 -0400 Subject: [PATCH 2/5] add changeset --- .chronus/changes/lro_response-2024-3-1-10-55-55.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/lro_response-2024-3-1-10-55-55.md diff --git a/.chronus/changes/lro_response-2024-3-1-10-55-55.md b/.chronus/changes/lro_response-2024-3-1-10-55-55.md new file mode 100644 index 0000000000..561d046ce8 --- /dev/null +++ b/.chronus/changes/lro_response-2024-3-1-10-55-55.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/typespec-client-generator-core" +--- + +take lroMetadata.finalResult into consideration \ No newline at end of file From 27a49f4675dc9c69fdced32d31c7b4acd42ed487 Mon Sep 17 00:00:00 2001 From: iscai-msft Date: Mon, 1 Apr 2024 11:12:47 -0400 Subject: [PATCH 3/5] look at final result path as well --- .../src/package.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/typespec-client-generator-core/src/package.ts b/packages/typespec-client-generator-core/src/package.ts index d45b982bb7..839e961c86 100644 --- a/packages/typespec-client-generator-core/src/package.ts +++ b/packages/typespec-client-generator-core/src/package.ts @@ -162,6 +162,17 @@ function getSdkLroServiceMethod< getClientTypeWithDiagnostics(context, finalResult) ); } + let resultPath = metadata.finalResultPath ?? metadata.logicalPath; + if (!resultPath) { + // keep this specifically as envelopeResult and not finalEnvelopeResult, bc this is a very specific scenario + if ( + metadata.envelopeResult !== metadata.logicalResult && + basicServiceMethod.operation.verb === "post" + ) { + resultPath = "result"; + } + } + basicServiceMethod.response; return diagnostics.wrap({ ...basicServiceMethod, kind: "lro", @@ -174,12 +185,7 @@ function getSdkLroServiceMethod< ) ), getResponseMapping(): string | undefined { - return ( - metadata.logicalPath ?? - (metadata.envelopeResult !== metadata.logicalResult && this.operation.verb === "post" - ? "result" - : undefined) - ); + return resultPath; }, }); } From 51e385d816e161767c3ca2f82c61e8b1d105aa76 Mon Sep 17 00:00:00 2001 From: tadelesh Date: Wed, 3 Apr 2024 17:50:01 +0800 Subject: [PATCH 4/5] change to only use final result --- .../src/package.ts | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/packages/typespec-client-generator-core/src/package.ts b/packages/typespec-client-generator-core/src/package.ts index 01f306ee62..09ec74f4ca 100644 --- a/packages/typespec-client-generator-core/src/package.ts +++ b/packages/typespec-client-generator-core/src/package.ts @@ -129,12 +129,12 @@ function getSdkPagingServiceMethod< nextLinkPath: pagedMetadata?.nextLinkSegments?.join("."), nextLinkOperation: pagedMetadata?.nextLinkOperation ? diagnostics.pipe( - getSdkServiceOperation( - context, - pagedMetadata.nextLinkOperation, - basic.parameters - ) + getSdkServiceOperation( + context, + pagedMetadata.nextLinkOperation, + basic.parameters ) + ) : undefined, getResponseMapping(): string | undefined { return pagedMetadata?.itemsSegments?.join("."); @@ -155,15 +155,17 @@ function getSdkLroServiceMethod< getSdkBasicServiceMethod(context, operation) ); - basicServiceMethod.response.type = diagnostics.pipe( - getClientTypeWithDiagnostics(context, metadata.logicalResult) - ); - basicServiceMethod.response.resultPath = - metadata.logicalPath ?? - (metadata.envelopeResult !== metadata.logicalResult && - basicServiceMethod.operation.verb === "post" - ? "result" - : undefined); + if (metadata.finalResult === undefined || metadata.finalResult === "void") { + basicServiceMethod.response.type = undefined; + } if (metadata.finalResult === undefined || metadata.finalResult === "void") { + basicServiceMethod.response.type = undefined; + } else { + basicServiceMethod.response.type = diagnostics.pipe( + getClientTypeWithDiagnostics(context, metadata.finalResult) + ); + } + + basicServiceMethod.response.resultPath = metadata.finalResultPath; return diagnostics.wrap({ ...basicServiceMethod, kind: "lro", From 49d7df3c56c90275676e1f538563eeeafdb2af12 Mon Sep 17 00:00:00 2001 From: tadelesh Date: Wed, 3 Apr 2024 17:58:27 +0800 Subject: [PATCH 5/5] format --- .../typespec-client-generator-core/src/package.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packages/typespec-client-generator-core/src/package.ts b/packages/typespec-client-generator-core/src/package.ts index 09ec74f4ca..baec0e0f9c 100644 --- a/packages/typespec-client-generator-core/src/package.ts +++ b/packages/typespec-client-generator-core/src/package.ts @@ -129,12 +129,12 @@ function getSdkPagingServiceMethod< nextLinkPath: pagedMetadata?.nextLinkSegments?.join("."), nextLinkOperation: pagedMetadata?.nextLinkOperation ? diagnostics.pipe( - getSdkServiceOperation( - context, - pagedMetadata.nextLinkOperation, - basic.parameters + getSdkServiceOperation( + context, + pagedMetadata.nextLinkOperation, + basic.parameters + ) ) - ) : undefined, getResponseMapping(): string | undefined { return pagedMetadata?.itemsSegments?.join("."); @@ -157,8 +157,6 @@ function getSdkLroServiceMethod< if (metadata.finalResult === undefined || metadata.finalResult === "void") { basicServiceMethod.response.type = undefined; - } if (metadata.finalResult === undefined || metadata.finalResult === "void") { - basicServiceMethod.response.type = undefined; } else { basicServiceMethod.response.type = diagnostics.pipe( getClientTypeWithDiagnostics(context, metadata.finalResult) @@ -166,6 +164,7 @@ function getSdkLroServiceMethod< } basicServiceMethod.response.resultPath = metadata.finalResultPath; + return diagnostics.wrap({ ...basicServiceMethod, kind: "lro",