|
| 1 | +# Namespace |
| 2 | + |
| 3 | +Microsoft Graph API Design Pattern |
| 4 | + |
| 5 | +### *The Namespace provides the ability to group resource definitions together into a logical set.* |
| 6 | + |
| 7 | +## Problem |
| 8 | + |
| 9 | +When building a complex offering API designers may need to model many different |
| 10 | +resources and their relationships. For better user experience and |
| 11 | +discoverability related API definitions need to be grouped together. Large API |
| 12 | +surface may need to be partitioned to generate light-weight client SDKs and libraries. |
| 13 | + |
| 14 | +## Solution |
| 15 | + |
| 16 | +API designers can use the Namespace attribute of the CSDL schema to |
| 17 | +declare a namespace and logically bundle related API entities in the Graph |
| 18 | +metadata. |
| 19 | +```XML |
| 20 | +<Schema Namespace="microsoft.graph.{namespace}"> |
| 21 | +... |
| 22 | +</Schema> |
| 23 | +``` |
| 24 | + |
| 25 | +All resources declared within the namespace will be grouped together in the public |
| 26 | +Graph metadata and may be used for partitioning. |
| 27 | + |
| 28 | +A public namespace must have "microsoft.graph.” prefix and be presented in camel |
| 29 | +case, i.e microsoft.graph.myNamespace. |
| 30 | + |
| 31 | +When type casting is required in the API query, request or response a fully-qualified type name is represented as concatenation of a namespace and a type name. Consequently namespace should be aligned with API category |
| 32 | +path segment. |
| 33 | + |
| 34 | +## When to Use this Pattern |
| 35 | + |
| 36 | +API resource grouping creates a user-friendly experience keeping all resources |
| 37 | +for a specific use case close together. It also allows generating smaller SDKs |
| 38 | +and libraries and limits length of IDE prompts such as Intellisense. |
| 39 | + |
| 40 | + |
| 41 | +## Issues and Considerations |
| 42 | + |
| 43 | +1. Microsoft Graph consistency requirements discourage using the same type |
| 44 | + names for different concepts even within different namespaces. Microsoft |
| 45 | + Graph type names must be descriptive and almost always unique within the API |
| 46 | + surface. |
| 47 | + |
| 48 | +2. Namespace must be consistent with API navigation path. |
| 49 | + |
| 50 | +3. When type name is ambiguous and requires a namespace qualifier changing namespace is a breaking change. |
| 51 | + |
| 52 | + |
| 53 | +4. To extend a type in a different schema, a service must declare that schema |
| 54 | + and the type in it. This is conceptually similar to .NET partial types. |
| 55 | + |
| 56 | +5. To reference a type in a different schema, simply refer to that type by |
| 57 | + fully qualified name (namespace + type name). |
| 58 | +6. Microsoft Graph has heuristic rules for declared namespaces: |
| 59 | + |
| 60 | + - All public namespaces must have a prefix ‘microsoft.graph’ |
| 61 | + |
| 62 | + - If a namespace does not begin with ‘microsoft.graph’ prefix, all types in |
| 63 | + the schema will be coerced into the main ‘microsoft.graph’ namespace. |
| 64 | + |
| 65 | +## Example |
| 66 | + |
| 67 | +Namespace and type declarations: |
| 68 | +```XML |
| 69 | + |
| 70 | +<Schema Namespace="microsoft.graph.search" xmlns=”<http://docs.oasis-open.org/odata/ns/edm>”\> |
| 71 | +… |
| 72 | + <EntityType Name="bookmark" … |
| 73 | + </EntityType> |
| 74 | +… |
| 75 | +</Schema> |
| 76 | + |
| 77 | +``` |
| 78 | + |
| 79 | +Fully qualified type name: microsoft.graph.search.bookmark |
0 commit comments