Skip to content

Commit

Permalink
[tcgc] take lro finalResult into consideration (#559)
Browse files Browse the repository at this point in the history
fixes #124

---------

Co-authored-by: iscai-msft <isabellavcai@gmail.com>
Co-authored-by: Joel Hendrix <jhendrix@microsoft.com>
Co-authored-by: tadelesh <tadelesh.shi@live.cn>
  • Loading branch information
4 people authored Apr 22, 2024
1 parent 64b5ae2 commit 897ba80
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 9 deletions.
7 changes: 7 additions & 0 deletions .chronus/changes/lro_response-2024-3-1-10-55-55.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: fix
packages:
- "@azure-tools/typespec-client-generator-core"
---

take lroMetadata.finalResult into consideration
19 changes: 10 additions & 9 deletions packages/typespec-client-generator-core/src/package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,16 @@ function getSdkLroServiceMethod<
getSdkBasicServiceMethod<TOptions, TServiceOperation>(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",
Expand Down
17 changes: 17 additions & 0 deletions packages/typespec-client-generator-core/test/package.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Widget>;
`
);
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],
Expand Down

0 comments on commit 897ba80

Please sign in to comment.