Microsoft Graph API @odata.type 是否包含“#”字符?

Does the Microsoft Graph API @odata.type include the "#" character?

Microsoft Graph API 基于 OData,每个对象都有一个 @odata.type

查看 user resource type@odata.type#microsoft.graph.user"

{
  "@odata.type": "#microsoft.graph.user",
  "id": "String (identifier)",
  "deviceEnrollmentLimit": 5
}

但是 group resource type 中的示例 @odata.typemicrosoft.graph.user 并且不以 #

开头
{
  ...
  "members": [ { "@odata.type": "microsoft.graph.directoryObject" } ],
  "membersWithLicenseErrors": [{"@odata.type": "microsoft.graph.user"}],
  ...
}

OData 版本 4.0 通用架构定义语言 (CSDL) 的 Types 部分似乎没有指明与此主题相关的任何标准。

问题: # 字符部分是 Microsoft 定义的 @odata.type 还是 OData 规范的一部分,或者只是某些 OData 提供商使用的约定?

我希望这个问题有一个简单的答案。描述 OData JSON 格式的 OData 规范有以下内容:

For payloads described by an OData-Version header with a value of 4.0, this name MUST be prefixed with the hash symbol (#); for non-OData 4.0 payloads, built-in primitive type values SHOULD be represented without the hash symbol, but consumers of 4.01 or greater payloads MUST support values with or without the hash symbol.

http://docs.oasis-open.org/odata/odata-json-format/v4.01/cs01/odata-json-format-v4.01-cs01.html#_Toc499720587

Microsoft Graph 测试版支持 4.01,但 V1.0 API 大部分使用 4.0。最好的选择是始终包含非原始类型的哈希符号。

注意:将 Darrel 的答案标记为正确,因为他发现了这个,但以不同的方式回答

Graph Explorer 开始,您可以使用 https://graph.microsoft.com/v1.0/$metadata

直接探索 $metadata

架构中定义的命名空间是microsoft.graph

<Schema Namespace="microsoft.graph" Alias="graph" xmlns="http://docs.oasis-open.org/odata/ns/edm">

对于相关实体,类型名称是 user

<EntityType Name="user" BaseType="graph.directoryObject" OpenType="true">

所以,我会得出结论,完全命名空间类型实际上是 microsoft.graph.user,别名是 graph.user,但是 @odata.type 的值是 #microsoft.graph.user,因为它需要 # 字符(哈希符号)根据 OData JSON Format spec.