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 diff --git a/packages/typespec-client-generator-core/src/package.ts b/packages/typespec-client-generator-core/src/package.ts index c2023a10b3..0e85305b1a 100644 --- a/packages/typespec-client-generator-core/src/package.ts +++ b/packages/typespec-client-generator-core/src/package.ts @@ -163,15 +163,16 @@ 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; + } else { + basicServiceMethod.response.type = diagnostics.pipe( + getClientTypeWithDiagnostics(context, metadata.finalResult) + ); + } + + basicServiceMethod.response.resultPath = metadata.finalResultPath; + 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 40f1a92ef3..be927f8c7d 100644 --- a/packages/typespec-client-generator-core/test/package.test.ts +++ b/packages/typespec-client-generator-core/test/package.test.ts @@ -2596,6 +2596,23 @@ describe("typespec-client-generator-core: package", () => { strictEqual(methodResponse.type, widgetModel); strictEqual(createOrUpdate.response.resultPath, "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],