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

Add troubleshoot guide for enum -> union migration #506

Merged
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 variant is `string`.
timotheeguerin marked this conversation as resolved.
Show resolved Hide resolved
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 offer an automatic codefix (click the (ℹ) bulb in VS Code)
timotheeguerin marked this conversation as resolved.
Show resolved Hide resolved
For example

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

should be converted to

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