|
2 | 2 |
|
3 | 3 | Microsoft Graph API Design Pattern
|
4 | 4 |
|
5 |
| -### *A known pattern in Microsoft Graph is to model multiple variants of a common concept as a single entity type with all the potential properties plus an additional property to distinguish the variants.* |
| 5 | +*A known pattern in Microsoft Graph is to model multiple variants of a common concept as a single entity type with all potential properties plus an additional property to distinguish the variants.* |
6 | 6 |
|
7 | 7 |
|
8 | 8 | ## Problem
|
9 | 9 |
|
10 |
| -API designer needs to model a small and limited number of variants of a common concept with a concise list of non-overlapping properties and consistent behavior across variant. The designer also wants to simplify query construction. |
| 10 | +API designers need to model a small and limited number of variants of a common concept with a concise list of non-overlapping properties and consistent behavior across variant. The designer also wants to simplify query construction. |
11 | 11 |
|
12 | 12 | ## Solution
|
13 | 13 |
|
14 |
| -The API designer creates one entity type with all the potential properties plus an additional property to distinguish the variants, often called `variantType`. |
| 14 | +The API designer creates one entity type with all the potential properties plus an additional property to distinguish the variants, often called `variantType`. For each value of `variantType` some properties are meaningful and others are ignored. |
15 | 15 |
|
16 |
| -## Issues and Considerations |
| 16 | +## When to use this pattern |
17 | 17 |
|
18 |
| -???? |
| 18 | +The flat-bag pattern is useful when there is a small number of variants with similar behavior and variants are queried for mostly read-only operations. |
| 19 | +The pattern also makes it syntactically easier to query resources by using OData $filter expression because it doesn't require casting. |
19 | 20 |
|
| 21 | +## Issues and considerations |
20 | 22 |
|
21 |
| -## When to Use this Pattern |
| 23 | +In general the flat-bag pattern is the least recommended modeling choice because it is weakly typed and it is difficult to semantically verify targeted resource modifications. But there are circumstances when query simplicity and limited number of properties may overweight considerations of more strongly typed approach. |
| 24 | +The pattern is not recommended for large number of variants and properties because the payload becomes sparsely populated. |
22 | 25 |
|
23 |
| -The flat-bag pattern is useful when there is a small number of variants |
24 |
| - |
25 |
| -???? |
26 |
| - |
27 |
| -There are related patterns to consider such as |
28 |
| -[Type Hierarchy](https://github.com/microsoft/api-guidelines/tree/graph/graph) and [Flat |
29 |
| -bag of |
30 |
| -properties](https://github.com/microsoft/api-guidelines/tree/graph/graph). |
| 26 | +You can consider related patterns such as Type hierarchy and Flat bag of properties. |
31 | 27 |
|
32 | 28 | ## Example
|
33 |
| -????? |
| 29 | + |
| 30 | +A good example for flat-bag implementation is the recurrencePattern and recurrenceRange types on [patternedRecurrence](https://docs.microsoft.com/graph/api/resources/patternedrecurrence). |
| 31 | + |
| 32 | +The recurrencePattern has six variants expressed as six different values of the `type` property (for example: daily, weekly, ...). The key here is that for each of these values, some properties are meaningful and others are ignored (for example: `daysOfWeek` is relevant when `type` is `weekly` but not when it is `daily`). |
| 33 | + |
| 34 | +``` |
| 35 | +<EnumType Name="recurrencePatternType"> |
| 36 | + <Member Name="daily" Value="0" /> |
| 37 | + <Member Name="weekly" Value="1" /> |
| 38 | + <Member Name="absoluteMonthly" Value="2" /> |
| 39 | + <Member Name="relativeMonthly" Value="3" /> |
| 40 | + <Member Name="absoluteYearly" Value="4" /> |
| 41 | + <Member Name="relativeYearly" Value="5" /> |
| 42 | +</EnumType> |
| 43 | +
|
| 44 | +<ComplexType Name="recurrencePattern" ags:WorkloadIds="Microsoft.Exchange,Microsoft.IdentityGovernance.AccessReviews,Microsoft.IGAELM,Microsoft.PIM.AzureRBAC,Microsoft.Tasks,Microsoft.Teams.Shifts,Microsoft.Todo" ags:PassthroughWorkloadIds="Microsoft.Exchange"> |
| 45 | + <Property Name="dayOfMonth" Type="Edm.Int32" Nullable="false" /> |
| 46 | + <Property Name="daysOfWeek" Type="Collection(graph.dayOfWeek)" /> |
| 47 | + <Property Name="firstDayOfWeek" Type="graph.dayOfWeek" /> |
| 48 | + <Property Name="index" Type="graph.weekIndex" /> |
| 49 | + <Property Name="interval" Type="Edm.Int32" Nullable="false" /> |
| 50 | + <Property Name="month" Type="Edm.Int32" Nullable="false" /> |
| 51 | + <Property Name="type" Type="graph.recurrencePatternType" /> |
| 52 | +</ComplexType> |
| 53 | +``` |
0 commit comments