-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add troubleshoot guide for enum -> union migration (#506)
Co-authored-by: Mark Cowlishaw <markcowl@microsoft.com>
- Loading branch information
1 parent
391e135
commit b9a6c8f
Showing
1 changed file
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
} | ||
``` |