Skip to content

Commit

Permalink
Add troubleshoot guide for enum -> union migration (#506)
Browse files Browse the repository at this point in the history
Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
  • Loading branch information
timotheeguerin and markcowl authored Mar 30, 2024
1 parent 391e135 commit b9a6c8f
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions docs/troubleshoot/enum-not-extensible.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# My enums are not extensible anymore

## Symptoms

I had an enum that used to generate `x-ms-enum.modelAsString: true` but now it is generating as `x-ms-enum.modelAsString: false` and I see a warning message `@azure-tools/typespec-azure-core/no-enum`

## Cause

Azure stopped treating enums as extensible.

## Workaround

To define an extensible enum you will need instead to use a `union` where one of the variants is `string`.
If you see the linter warning [`@azure-tools/typespec-azure-core/no-enum`](https://tspwebsitepr.z22.web.core.windows.net/typespec-azure/prs/389/docs/next/libraries/azure-core/rules/no-enum) it also offers an automatic codefix (click the (ℹ) bulb in VS Code)
For example

```tsp
enum PetKind {
Cat,
Dog,
}
```

should be converted to

```tsp
union PetKind {
Cat: "Cat",
Dog: "Dog",
string,
}
```

0 comments on commit b9a6c8f

Please sign in to comment.