Skip to content

Commit 3c3458b

Browse files
committed
flat-bag updates
1 parent 9ae63f0 commit 3c3458b

File tree

2 files changed

+36
-16
lines changed

2 files changed

+36
-16
lines changed

graph/patterns/facets.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ The driveItem resource represents a file, folder, image, or other item stored in
6565
An API request to get all items from a personal OneDrive returns a heterogenous collection with different facets populated. In the following example, there is a folder, a file, and an image in the collection. The image entity has two facets populated: file and image.
6666

6767
```
68-
https://graph.microsoft.com/v1.0/me/drive/root/children
68+
GET https://graph.microsoft.com/v1.0/me/drive/root/children
6969
7070
Response shortened for readability:
7171

graph/patterns/flat-bag.md

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,52 @@
22

33
Microsoft Graph API Design Pattern
44

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.*
66

77

88
## Problem
99

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.
1111

1212
## Solution
1313

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.
1515

16-
## Issues and Considerations
16+
## When to use this pattern
1717

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.
1920

21+
## Issues and considerations
2022

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.
2225

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.
3127

3228
## 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

Comments
 (0)