Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[tcgc] take lro finalResult into consideration #559

Merged
merged 12 commits into from
Apr 22, 2024
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
Loading