OData / odata.net

ODataLib: Open Data Protocol - .NET Libraries and Frameworks
https://docs.microsoft.com/odata
Other
686 stars 349 forks source link

nested context uri is missing #1976

Open xuzhg opened 3 years ago

xuzhg commented 3 years ago

We are upgrading our OData libs from 6.15.0 to 7.7.2 for better webapi2 integration and features supported in latest version. I have handled all the cases like you suggested before. But I noticed that context URI is missing when I use $expand functionality. For example: "RecipientPermission@odata.context" is missing in below payload using Microsoft.OData.Core 7.7.2. Here Recipient, and RecipientPermissions are entity types. URI: https://10.128.4.68/adminapi/beta/vg.extest.microsoft.com/Recipient('fc44eae0-4a01-4c6c-9c0d-35933ed53894')?$expand=RecipientPermission&$select=ExternalDirectoryObjectId

{
    "@odata.context": "https://exhr-79956.exhr-79956dom.extest.microsoft.com:444/adminapi/beta/vg.extest.microsoft.com/$metadata#Recipient(ExternalDirectoryObjectId,RecipientPermission)/$entity",
    "@odata.id": "https://exhr-79956.exhr-79956dom.extest.microsoft.com:444/adminapi/beta/vg.extest.microsoft.com/Recipient('fc44eae0-4a01-4c6c-9c0d-35933ed53894')",
    "@odata.editLink": "https://exhr-79956.exhr-79956dom.extest.microsoft.com:444/adminapi/beta/vg.extest.microsoft.com/Recipient('fc44eae0-4a01-4c6c-9c0d-35933ed53894')",
    "ObjectKey": "fc44eae0-4a01-4c6c-9c0d-35933ed53894",
    "RecipientPermission@odata.context": "https://exhr-79956.exhr-79956dom.extest.microsoft.com:444/adminapi/beta/vg.extest.microsoft.com/$metadata#Recipient('fc44eae0-4a01-4c6c-9c0d-35933ed53894')/RecipientPermission",
    "RecipientPermission": [
        {
            "Identity": "Administrator",
            "Trustee": "NT AUTHORITY\\SELF",
            "AccessControlType": "Allow",
            "AccessRights": [
                "SendAs"
            ],
            "IsInherited": false,
            "InheritanceType": "None"
        }
    ]
}

Investigation:

I investigated it and it seems related to this commit:

https://github.com/OData/odata.net/commit/b214dbfde938edf765a7fe8132ce4d5732995ac4#diff-a357b7f405d3fce1a2b3960daab3b0bf2cdba1a7af09a09e05b8df6511b87ade as below

xuzhg commented 3 years ago

Investigation:

1) we should public this https://github.com/OData/odata.net/blob/master/src/Microsoft.OData.Core/ODataNestedResourceInfo.cs#L97 . So customer can set the context uri

2) we should change the logic at: https://github.com/OData/odata.net/blob/master/src/Microsoft.OData.Core/JsonLight/ODataJsonLightWriter.cs#L990-L994

3) We maybe add "public Func<Uri, IEdmModel> ContextUriEdmModelFunc;" into reader/writer setting to provide the edm model for a certain context Uri.