Skip to content

Commit 4f9ed77

Browse files
committed
First go at converting dictionary guidance to Pattern template
1 parent e8a0050 commit 4f9ed77

File tree

2 files changed

+44
-13
lines changed

2 files changed

+44
-13
lines changed
File renamed without changes.

graph/dictionary/index.md renamed to graph/patterns/dictionary/index.md

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,40 @@
1-
# Dictionary types
1+
# Dictionary
2+
3+
Microsoft Graph API Design Pattern
4+
5+
*The Dictionary type provides the ability to create a set of primitives or objects, of the same type, where the API consumer can define a name for each value in the set.*
6+
7+
## Problem
8+
--------
9+
10+
The API design requires a resource to include an unknown quantity of similar data elements that need to be named using values provided by the API consumer.
11+
12+
## Solution
13+
--------
14+
15+
API designers use a JSON object to represent a dictionary in a `application/json`response payload. When describing the model in CSDL, a new complex type can be created that derives from `Org.OData.Core.V1.Dictionary` and then use the `Org.OData.Validation.V1.OpenPropertyTypeConstraint`to constrain the type that can be used for the values in the dictionary.
16+
17+
Dictionary entries can be added via `POST`, updated via `PATCH`, and they can be removed by setting the entry value to `null`. Multiple dictionaries can be updated at once by using `PATCH` on the dictionary property.
18+
19+
## Issues and Considerations
20+
-------------------------
221

322
Dictionaries, sometimes called maps, are a collection of name-value pairs. They allow dynamic data sets to be accessed in a systematic manner and are a good compromise between a strictly defined ahead of time structure with all its named properties and between a loosely defined dynamic object (i.e. OData OpenTypes).
423

24+
As dictionary entries are removed via setting the value to null, this means that dictionaries can only support values that are non-nullable.
25+
26+
OpenQuestions:
27+
- Can/should PUT be supported on the dictionary property and/or the entry value
28+
- What does OData say about being able to POST to a structured property? Will OData Web API allow that?
29+
- Must an implementer support PATCH at both the dictionary level and the entry level?
30+
531
More information:
632

733
- [OData reference](https://github.com/oasis-tcs/odata-vocabularies/blob/master/vocabularies/Org.OData.Core.V1.md#dictionary)
834

9-
## When to use dictionary types
35+
 
36+
## When to Use this Pattern
37+
------------------------
1038

1139
Before using a dictionary type in your API definition make sure your scenario fits the following criteria:
1240

@@ -20,7 +48,10 @@ Before using a dictionary type in your API definition make sure your scenario fi
2048
- [Open types](https://docs.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/odata-v4/use-open-types-in-odata-v4) when your data is not a collection in nature.
2149
- [Complex types](https://docs.microsoft.com/en-us/odata/webapi/complextypewithnavigationproperty) when the set of data values are known.
2250

23-
## JSON payload example
51+
## Examples
52+
-------
53+
54+
### JSON payload example
2455

2556
The following example illustrates the resulting JSON for a property of dictionary type. The parent object has been ommitted for brievety.
2657

@@ -38,11 +69,11 @@ The following example illustrates the resulting JSON for a property of dictionar
3869
}
3970
```
4071

41-
## HTTP calls examples
72+
### HTTP calls examples
4273

4374
In this set of examples we're modeling a **roles** property of dictionary type on the user entity which is exposed by the users entity set.
4475

45-
### Getting an entry from the dictionary
76+
#### Getting an entry from the dictionary
4677

4778
```HTTP
4879
GET https://graph.microsoft.com/v1.0/users/10/roles/author
@@ -56,7 +87,7 @@ Reponse:
5687
}
5788
```
5889

59-
### Getting the dictionary
90+
#### Getting the dictionary
6091

6192
```HTTP
6293
GET https://graph.microsoft.com/v1.0/users/10/roles
@@ -78,7 +109,7 @@ Reponse:
78109
}
79110
```
80111

81-
### Getting the entity with the dictionary
112+
#### Getting the entity with the dictionary
82113

83114
```HTTP
84115
GET https://graph.microsoft.com/v1.0/users/10
@@ -104,7 +135,7 @@ Reponse:
104135
}
105136
```
106137

107-
### Creating an entry in the dictionary
138+
#### Creating an entry in the dictionary
108139

109140
```HTTP
110141
POST https://graph.microsoft.com/v1.0/users/10/roles/author
@@ -114,7 +145,7 @@ POST https://graph.microsoft.com/v1.0/users/10/roles/author
114145
}
115146
```
116147

117-
### Updating the dictionary
148+
#### Updating the dictionary
118149

119150
```HTTP
120151
PATCH https://graph.microsoft.com/v1.0/users/10/roles
@@ -137,7 +168,7 @@ PATCH https://graph.microsoft.com/v1.0/users/10/roles
137168
> Note: the domain values for the existing author and maintainer entries will get udpated.
138169
> Note: the reviewer entry will be inserted in the dictionary.
139170
140-
### Updating an entry in the dictionary
171+
#### Updating an entry in the dictionary
141172

142173
```HTTP
143174
PATCH https://graph.microsoft.com/v1.0/users/10/roles/author
@@ -147,13 +178,13 @@ PATCH https://graph.microsoft.com/v1.0/users/10/roles/author
147178
}
148179
```
149180

150-
### Deleting an entry from the dictionary
181+
#### Deleting an entry from the dictionary
151182

152183
```HTTP
153184
DELETE https://graph.microsoft.com/v1.0/users/10/roles/author
154185
```
155186

156-
## CDSL example
187+
### CDSL example
157188

158189
The following example defines a complex type **roleSettings** as well as a dictionary of which the key will be a string and the value a **roleSettings**.
159190

@@ -182,6 +213,6 @@ The following example defines a complex type **roleSettings** as well as a dicti
182213
</ComplexType>
183214
```
184215

185-
## Additional information
216+
### Additional information
186217

187218
[SDK implementation guidance](./client-guidance.md).

0 commit comments

Comments
 (0)