Skip to content

Commit 67f30db

Browse files
authored
Merge pull request #522 from microsoft/corranrogue9/dictionary2
Update dictionary guidance to have the correct workload CSDL to implement a dictionary type
2 parents 3fdf426 + ddeed9f commit 67f30db

File tree

1 file changed

+56
-35
lines changed

1 file changed

+56
-35
lines changed

graph/patterns/dictionary.md

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -37,30 +37,42 @@ For more information, see the [OData reference](https://github.com/oasis-tcs/oda
3737

3838
## Examples
3939

40-
### Declaring a string dictionary
40+
### String dictionary
41+
42+
#### CSDL declaration
4143
The following example demonstrates defining a dictionary that can contain string values.
4244

4345
```xml
44-
<ComplexType Name="stringDictionary" BaseType="graph.Dictionary">
45-
<Annotation Term="Org.OData.Validation.V1.OpenPropertyTypeConstraint">
46-
<Collection>
47-
<String>Edm.String</String>
48-
</Collection>
49-
</Annotation>
50-
</ComplexType>
46+
<Schema Namespace="microsoft.graph"> <!--NOTE: the namespace that declares the Dictionary complex type *must* be microsoft.graph-->
47+
<ComplexType Name="Dictionary" OpenType="true">
48+
<Annotation Term="Core.Description" String="A dictionary of name-value pairs. Names must be valid property names, values may be restricted to a list of types via an annotation with term `Validation.OpenPropertyTypeConstraint`." />
49+
</ComplexType>
50+
</Schema>
51+
<Schema Namespace="WorkloadNamespace">
52+
<ComplexType Name="stringDictionary" OpenType="true" BaseType="microsoft.graph.Dictionary">
53+
<Annotation Term="Org.OData.Validation.V1.OpenPropertyTypeConstraint">
54+
<Collection>
55+
<String>Edm.String</String>
56+
</Collection>
57+
</Annotation>
58+
</ComplexType>
59+
</Schema>
5160
```
5261

53-
### Defining a dictionary property
62+
Please note that schema validation will fail due to the casing of `Dictionary`.
63+
This warning should be suppressed.
64+
65+
#### Defining a dictionary property
5466
The following example shows defining a dictionary property, "userTags", on the item entity type.
5567

5668
```xml
5769
<EntityType Name="item">
5870
...
59-
<Property Name="userTags" Type="self.stringDictionary"/>
71+
<Property Name="userTags" Type="WorkloadNamespace.stringDictionary"/>
6072
</EntityType>
6173
```
6274

63-
### Reading a dictionary
75+
#### Reading a dictionary
6476
Dictionaries are represented in JSON payloads as a JSON object, where the property names are comprised of the keys and their values are the corresponding key values.
6577

6678
The following example shows reading an item with a dictionary property named "userTags":
@@ -80,7 +92,7 @@ Response:
8092
}
8193
```
8294

83-
### Setting a dictionary value
95+
#### Setting a dictionary value
8496
The following example shows setting a dictionary value. If "hairColor" already exists, it is updated, otherwise it is added.
8597

8698
```http
@@ -92,7 +104,7 @@ PATCH /item/userTags
92104
}
93105
```
94106

95-
### Deleting a dictionary value
107+
#### Deleting a dictionary value
96108
A dictionary value can be removed by setting the value to null.
97109
```http
98110
PATCH /item/userTags
@@ -103,34 +115,43 @@ PATCH /item/userTags
103115
}
104116
```
105117

106-
### Declaring a complex typed dictionary
118+
### Complex typed dictionary
119+
120+
#### CSDL declaration
107121
Dictionaries can also contain complex types whose values may be constrained to a particular set of complex types.
108122

109123
The following example defines a complex type **roleSettings**, an **assignedRoleGroupDictionary** that contains **roleSettings**, and an **assignedRoles** property that uses the dictionary..
110124

111125
```xml
112-
<EntityType Name="principal">
113-
...
114-
<Property Name="assignedRoles" Type="self.assignedRoleGroupDictionary">
115-
</EntityType>
116-
117-
<ComplexType Name="roleSettings">
118-
<Property Name ="domain" Type="Edm.String" Nullable="false" />
119-
</ComplexType>
120-
121-
<ComplexType Name="assignedRoleGroupDictionary" BaseType="graph.Dictionary">
122-
<!-- Note: Strongly-typed dictionary
123-
of roleSettings
124-
keyed by name of roleGroup. -->
125-
<Annotation Term="Org.OData.Validation.V1.OpenPropertyTypeConstraint">
126-
<Collection>
127-
<String>microsoft.graph.roleSettings</String>
128-
</Collection>
129-
</Annotation>
130-
</ComplexType>
126+
<Schema Namespace="microsoft.graph"> <!--NOTE: the namespace that declares the Dictionary complex type *must* be microsoft.graph-->
127+
<ComplexType Name="Dictionary" OpenType="true">
128+
<Annotation Term="Core.Description" String="A dictionary of name-value pairs. Names must be valid property names, values may be restricted to a list of types via an annotation with term `Validation.OpenPropertyTypeConstraint`." />
129+
</ComplexType>
130+
</Schema>
131+
<Schema Namespace="WorkloadNamespace">
132+
<EntityType Name="principal">
133+
...
134+
<Property Name="assignedRoles" Type="WorkloadNamespace.assignedRoleGroupDictionary">
135+
</EntityType>
136+
137+
<ComplexType Name="roleSettings">
138+
<Property Name ="domain" Type="Edm.String" Nullable="false" />
139+
</ComplexType>
140+
141+
<ComplexType Name="assignedRoleGroupDictionary" BaseType="microsoft.graph.Dictionary">
142+
<!-- Note: Strongly-typed dictionary of roleSettings keyed by name of roleGroup. -->
143+
of roleSettings
144+
keyed by name of roleGroup. -->
145+
<Annotation Term="Org.OData.Validation.V1.OpenPropertyTypeConstraint">
146+
<Collection>
147+
<String>microsoft.graph.roleSettings</String>
148+
</Collection>
149+
</Annotation>
150+
</ComplexType>
151+
</Schema>
131152
```
132153

133-
### Reading a entity with a complex-typed dictionary
154+
#### Reading a entity with a complex-typed dictionary
134155

135156
The following example illustrates reading an entity containing the complex-typed dictionary "assignedRoles".
136157

@@ -158,7 +179,7 @@ Response:
158179
}
159180
```
160181

161-
### Reading the dictionary property
182+
#### Reading the dictionary property
162183
The following example shows getting just the "assignedRoles" dictionary property.
163184

164185
```HTTP

0 commit comments

Comments
 (0)