简体   繁体   中英

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

Looking at the user resource type , the @odata.type is #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 #

{
  ...
  "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.

Question: Is the # character part of the Microsoft defined @odata.type or part of OData spec or just a convention some OData providers use?

I wish there was an easy answer to this question. The OData specification that describes the OData JSON format has the following to say:

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

The beta version of Microsoft Graph supports 4.01, but most of the V1.0 API uses 4.0. The best option would be to always include the hash symbol for non-primitive types.

Note : Marking Darrel's answer as correct since he found this, but answering in a different way

From Graph Explorer you can explore the $metadata directly using https://graph.microsoft.com/v1.0/$metadata

The namespace defined in the schema is 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

<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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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