You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In OData, enum are nominal types representing a subset of the nominal type they use, and are especially useful in cases where certain properties have predefined, limited options.
333
+
334
+
```xml
335
+
<EnumTypeName="Color">
336
+
<MemberName="Red"Value="0" />
337
+
<MemberName="Green"Value="1" />
338
+
<MemberName="Blue"Value="2" />
339
+
</EnumType>
340
+
```
341
+
342
+
#### Pros
343
+
344
+
- Our SDK generators will translate the enum to the best representation of the target programming language, resulting in a better developer experience and free client side validation
345
+
346
+
#### Cons
347
+
348
+
- Adding a new value requires to go through a (generally fast) API Review
349
+
- If the enum is not [evolvable](./patterns/evolvable-enums.md), adding a new value is a breaking change and will generally not be allowed
350
+
351
+
#### Enum or Booleans
352
+
353
+
Enumerations are a good alternative to booleans when one of the two values (`true`, `false`) conveyes other possible values not yet conceived. Let's assume we have an `Error` type and a property to communicate how to display it:
354
+
355
+
```xml
356
+
<ComplexTypeName="Error">
357
+
<PropertyName="title"Type="Edm.String" />
358
+
<PropertyName="message"Type="Edm.String" />
359
+
<PropertyName="displayAsTip"Type="Edm.Boolean" />
360
+
</ComplexType>
361
+
```
362
+
363
+
The `false` value here merely communicates that the error shall not be displayed as a tip. What if, in the future, the error could be displayed as a `tip` or `alert`, and then in a more distant future, a `dialog` option is viable?
364
+
365
+
With the current model, the only way is to add more boolean properties to convey the new information:
Copy file name to clipboardExpand all lines: graph/patterns/evolvable-enums.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,8 @@ Microsoft Graph API Design Pattern
4
4
5
5
*The evolvable enums pattern allows API producers to extend enumerated types with new members without breaking API consumers.*
6
6
7
+
Note: You might be interested in reading the [Enum guidance](../GuidelinesGraph.md#enums) first
8
+
7
9
## Problem
8
10
9
11
Frequently API producers want to add new members to an enum type after it is initially published. Some serialization libraries might fail when they encounter members in an enum type that were added after the serialization model was generated. In this documentation, we refer to any added enum members as unknown.
0 commit comments