简体   繁体   English

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

[英]Does the Microsoft Graph API @odata.type include the “#” character?

The Microsoft Graph API is based on OData and each object has an @odata.type Microsoft Graph API 基于 OData,每个 object 都有一个@odata.type

Looking at the user resource type , the @odata.type is #microsoft.graph.user"查看用户资源类型@odata.type#microsoft.graph.user"

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

But the example from group resource type the @odata.type is microsoft.graph.user and does not start with a #但是来自组资源类型的示例@odata.typemicrosoft.graph.user并且不以#开头

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

The Types section of the OData Version 4.0 Common Schema Definition Language (CSDL) doesn't seem to indicate any standard related to this topic. OData 版本 4.0 通用架构定义语言 (CSDL) 的类型部分似乎没有指明与此主题相关的任何标准。

Question: Is the # character part of the Microsoft defined @odata.type or part of OData spec or just a convention some OData providers use?问题: #字符是 Microsoft 定义的@odata.type的一部分还是 OData 规范的一部分,还是只是某些 OData 提供商使用的约定?

I wish there was an easy answer to this question.我希望这个问题有一个简单的答案。 The OData specification that describes the OData JSON format has the following to say:描述 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 (#);对于 OData 版本 header 描述的有效载荷,值为 4.0,此名称必须以 hash 符号 (#) 为前缀; 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.对于非 OData 4.0 有效负载,内置原始类型值应该不带 hash 符号表示,但 4.01 或更高有效负载的消费者必须支持带或不带 hash 符号的值。

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

The beta version of Microsoft Graph supports 4.01, but most of the V1.0 API uses 4.0. Microsoft Graph 的 beta 版本支持 4.01,但大部分 V1.0 API 使用 4.0。 The best option would be to always include the hash symbol for non-primitive types.最好的选择是始终包含非原始类型的 hash 符号。

Note : Marking Darrel's answer as correct since he found this, but answering in a different way注意:将 Darrel 的答案标记为正确,因为他发现了这个,但以不同的方式回答

From Graph Explorer you can explore the $metadata directly using https://graph.microsoft.com/v1.0/$metadataGraph Explorer中,您可以使用https://graph.microsoft.com/v1.0/$metadata直接探索$metadata

The namespace defined in the schema is microsoft.graph架构中定义的命名空间是microsoft.graph

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

and for the entity in question, the type name is user对于有问题的实体,类型名称是user

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

So, I would conclude the fully namespaced type is actually microsoft.graph.user with an alias of graph.user but the value of @odata.type is #microsoft.graph.user because it requires the # character (hash symbol) per the OData JSON Format spec .因此,我会得出结论,完全命名空间的类型实际上是microsoft.graph.user ,别名是graph.user ,但@odata.type的值是#microsoft.graph.user因为它需要每个#字符(哈希符号) OData JSON 格式规范

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM