Skip to content

Commit

Permalink
Fix @lroStatus not detecting default states correctly when using un…
Browse files Browse the repository at this point in the history
…ion (#392)
  • Loading branch information
timotheeguerin authored Mar 29, 2024
1 parent e3e4fbc commit cfbcedf
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion packages/typespec-azure-core/src/decorators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 20 additions & 0 deletions packages/typespec-azure-core/test/decorators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down

0 comments on commit cfbcedf

Please sign in to comment.