diff --git a/.chronus/changes/fix-lro-autodetect-from-union-2024-2-8-22-32-28.md b/.chronus/changes/fix-lro-autodetect-from-union-2024-2-8-22-32-28.md new file mode 100644 index 0000000000..58b1e909e2 --- /dev/null +++ b/.chronus/changes/fix-lro-autodetect-from-union-2024-2-8-22-32-28.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@azure-tools/typespec-azure-core" +--- + +Fix `@lroStatus` not detecting default states correctly when using union diff --git a/packages/typespec-azure-core/src/decorators.ts b/packages/typespec-azure-core/src/decorators.ts index 6a99799176..fba649762e 100644 --- a/packages/typespec-azure-core/src/decorators.ts +++ b/packages/typespec-azure-core/src/decorators.ts @@ -351,7 +351,12 @@ export function extractLroStates( return diagnostics.wrap(undefined); } else { - storeLroState(program, result, option.value, variant); + storeLroState( + program, + result, + typeof variant.name === "string" ? variant.name : option.value, + variant + ); } } } else { diff --git a/packages/typespec-azure-core/test/decorators.test.ts b/packages/typespec-azure-core/test/decorators.test.ts index 5b031c3bf1..b169403675 100644 --- a/packages/typespec-azure-core/test/decorators.test.ts +++ b/packages/typespec-azure-core/test/decorators.test.ts @@ -497,6 +497,26 @@ describe("typespec-azure-core: decorators", () => { states: ["Donezo", "Borked", "Chucked", "HaveAnother"], }); }); + + it("resolve default state from union variant name", async () => { + const { DefaultLroStates } = (await runner.compile(` + @test + @lroStatus + union DefaultLroStates { + Succeeded: "uSucceeded", + Failed: "uFailed", + Canceled: "uCancelled", + Extra: "uExtra", + } + `)) as { DefaultLroStates: Model }; + + deepStrictEqual(getLongRunningStates(runner.program, DefaultLroStates), { + succeededState: ["Succeeded"], + failedState: ["Failed"], + canceledState: ["Canceled"], + states: ["Succeeded", "Failed", "Canceled", "Extra"], + }); + }); }); describe("@operationLink", () => {