Skip to main content
Version: Latest (Core: 0.57.x, Azure: 0.43.x)

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 it also offers an automatic codefix (click the (ℹ) bulb in VS Code) For example

enum PetKind {
Cat,
Dog,
}

should be converted to

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