|
2 | 2 |
|
3 | 3 | Microsoft Graph API Design Pattern
|
4 | 4 |
|
5 |
| -*The Namespace provides the ability to organize resource definitions together into a logical set.* |
| 5 | +*The namespace pattern provides the ability to organize resource definitions together into a logical set.* |
6 | 6 |
|
7 | 7 | ## Problem
|
8 | 8 |
|
9 |
| ---- |
10 |
| -When building a complex offering API designers may need to model many different |
11 |
| -resources and their relationships. For better user experience and |
12 |
| -discoverability related API elements need to be grouped together. |
13 |
| - |
| 9 | +When building a complex offering, API designers might need to model many different |
| 10 | +resources and their relationships. For a better user experience and |
| 11 | +discoverability, related API elements need to be grouped together. |
14 | 12 |
|
15 | 13 | ## Solution
|
16 | 14 |
|
17 |
| ---- |
18 |
| -API designers can use the Namespace attribute of the CSDL schema to declare a |
19 |
| -namespace and logically organize related API entities in the Graph metadata. |
| 15 | +API designers can use the namespace attribute of the CSDL schema to declare a |
| 16 | +namespace and logically organize related API entities in the Microsoft Graph metadata. |
20 | 17 |
|
21 |
| -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ XML |
| 18 | +```XML |
22 | 19 | <Schema Namespace="microsoft.graph.{namespace}">
|
23 | 20 | ...
|
24 | 21 | </Schema>
|
25 |
| -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 22 | +``` |
26 | 23 |
|
27 |
| -A public namespace must have "microsoft.graph." prefix and be presented in camel |
28 |
| -case, i.e microsoft.graph.myNamespace. |
| 24 | +A public namespace must contain the `microsoft.graph.` prefix and be presented in camel |
| 25 | +case; that is, `microsoft.graph.myNamespace`. |
29 | 26 |
|
30 |
| -When type casting is required in the API query, request or response, a fully |
| 27 | +When type casting is required in the API query, request, or response, a fully |
31 | 28 | qualified type name is represented as concatenation of a namespace and a type
|
32 |
| -name. For consistent user experience namespaces MUST be aligned with the corresponding API category path segment. |
33 |
| - |
34 |
| - |
35 |
| -## When to Use this Pattern |
| 29 | +name. For a consistent user experience, namespaces MUST be aligned with the corresponding API category path segment. |
36 | 30 |
|
37 |
| ---- |
38 |
| -API resource grouping creates a user-friendly experience keeping all resources |
39 |
| -for a specific feature close together |
40 |
| -and limits the length of IDE prompts such as auto-complete in some programming languages. |
| 31 | +## When to use this pattern |
41 | 32 |
|
42 |
| -We recommend that a new namespace should be aligned with top-level API category. |
| 33 | +API resource grouping creates a user-friendly experience, keeping all resources for a specific feature close together and limiting the length of IDE prompts such as auto-complete in some programming languages. |
43 | 34 |
|
44 |
| -## Issues and Considerations |
| 35 | +We recommend that a new namespace be aligned with a top-level API category. |
45 | 36 |
|
46 |
| ---- |
47 |
| -1. Microsoft Graph consistency requirements discourage using the same type |
48 |
| - names for different concepts even within different namespaces. Microsoft |
49 |
| - Graph type names must be descriptive and unique within the API |
50 |
| - surface without requiring full qualification. |
| 37 | +## Issues and considerations |
51 | 38 |
|
52 |
| -2. Namespace must be consistent with API category in the navigation path according to [Microsoft Graph REST API Guidelines](GuidelinesGraph.md#uniform-resource-locators-urls) |
| 39 | +- Microsoft Graph consistency requirements discourage using the same type names for different concepts even within different namespaces. Microsoft Graph type names must be descriptive and unique within the API surface without requiring full qualification. |
53 | 40 |
|
54 |
| -3. When type name is ambiguous and requires a namespace qualifier, changing |
55 |
| - namespace is a breaking change. |
| 41 | +- A namespace must be consistent with an API category in the navigation path according to [Microsoft Graph REST API Guidelines](../GuidelinesGraph.md#uniform-resource-locators-urls). |
56 | 42 |
|
57 |
| -4. To extend a type in a different schema, a service must declare that schema |
58 |
| - and the type in it. This is conceptually similar to .NET partial types. |
| 43 | +- When type name is ambiguous and requires a namespace qualifier, changing a namespace is a breaking change. |
59 | 44 |
|
60 |
| -5. To reference a type in a different schema, simply refer to that type by |
61 |
| - fully qualified name (namespace + type name). |
| 45 | +- To extend a type in a different schema, a service must declare that schema and the type in it. This is conceptually similar to .NET partial types. |
62 | 46 |
|
63 |
| -6. Cyclical references between namespaces are not allowed as many |
64 |
| - object-oriented languages don’t support a cycles between namespaces. |
| 47 | +- To reference a type in a different schema, simply refer to that type by its fully qualified name (namespace + type name). |
65 | 48 |
|
66 |
| -7. Microsoft Graph has some predefined constraints for declared namespaces: |
| 49 | +- Cyclical references between namespaces are not allowed because many object-oriented languages don’t support cycles between namespaces. |
67 | 50 |
|
68 |
| - - All public namespaces must have a prefix "microsoft.graph" |
| 51 | +- Microsoft Graph has some predefined constraints for declared namespaces: |
69 | 52 |
|
70 |
| - - Only one level of nesting deeper then "microsoft.graph" is supported |
71 |
| - |
72 |
| - - If a namespace does not begin with "microsoft.graph" prefix, all types |
73 |
| - in the schema will be coerced into the main "microsoft.graph" namespace. |
| 53 | + - All public namespaces must have the prefix `microsoft.graph`. |
| 54 | + |
| 55 | + - Only one level of nesting deeper than `microsoft.graph` is supported. |
| 56 | + |
| 57 | + - If a namespace does not begin with the `microsoft.graph` prefix, all types in the schema are coerced into the main `microsoft.graph` namespace. |
74 | 58 |
|
75 | 59 | ## Examples
|
76 | 60 |
|
77 |
| ---- |
78 |
| -### Namespace and type declarations: |
| 61 | +### Namespace and type declarations |
79 | 62 |
|
80 |
| -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ XML |
| 63 | +```XML |
81 | 64 | <Schema Namespace="microsoft.graph.search" xmlns=”<http://docs.oasis-open.org/odata/ns/edm>”\>
|
82 | 65 | …
|
83 | 66 | <EntityType Name="bookmark" …
|
84 | 67 | </EntityType>
|
85 | 68 | …
|
86 | 69 | </Schema>
|
87 |
| -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 70 | +``` |
| 71 | + |
| 72 | +Fully qualified type name: `microsoft.graph.search.bookmark` |
88 | 73 |
|
89 |
| -Fully qualified type name: "microsoft.graph.search.bookmark" |
| 74 | +### Managing multiple schemas |
90 | 75 |
|
91 |
| -### Managing multiple schemas: |
| 76 | +Workloads must define schemas in their CSDL by using the Edmx format. |
| 77 | +Following is an example of a workload that exposes multiple namespaces. |
92 | 78 |
|
93 |
| -Workloads must define schemas in their csdl using the Edmx format. |
94 |
| -Here is an example of a workload that exposes multiple namespaces. |
| 79 | +> **Tip:** As with schemas that exist in the `microsoft.graph` namespace, defining an |
| 80 | +entity type is optional; by default your schema derives all entity types |
| 81 | +from `microsoft.graph.entity`. |
95 | 82 |
|
96 |
| -**Tip:** As with schemas that exist in the microsoft.graph namespace, defining an |
97 |
| -entity type is optional, by default your schema derives all entity types |
98 |
| -from microsoft.graph.entity. |
| 83 | +> **Warning:** Do not deviate from the general structure in the following example. |
| 84 | +The schema validation tool expects the XML structure (including XML namespace |
| 85 | +declarations) to match this example. |
99 | 86 |
|
100 |
| -**Warning:** Do not deviate from the general structure in the example below. |
101 |
| -Schema validation tool expects the XML structure (including xml namespace |
102 |
| -declarations) to match the example below. |
103 | 87 | ```XML
|
104 | 88 | <?xml version="1.0" encoding="utf-8"?>
|
105 | 89 | <edmx:Edmx Version="4.0" xmlns:edmx="http://docs.oasis-open.org/odata/ns/edmx" xmlns:odata="http://schemas.microsoft.com/oDataCapabilities">
|
|
0 commit comments