microsoftgraph / microsoftgraph/msgraph-sdk-java-core

Batch response: Improved error handling when "UserCollectionResponse" is returned but discrimiator is set to "User"

Đang mở
#1,587 2 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

enhancement
Ngôn ngữ chính
Java
Star
67
Fork
34
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

Graph Core Version: 3.1.9
Kiota Version: 1.1.7
Affected Method: com.microsoft.graph.core.requests.ResponseBodyHandler#handleResponse

Edit: Added a comment explaining the reason of this behavior and changed the issue title.

Microsoft Graph core returns an object with all properties set to null, if the response body contains a nested structure.

Expected behavior

com.microsoft.graph.core.requests.ResponseBodyHandler#handleResponse should parse nested response objects. And maybe throw an error if a response can not be parsed.

Actual behavior

com.microsoft.graph.core.requests.ResponseBodyHandler#handleResponse returns a object with all properties set to null.

Steps to reproduce the behavior

Execute the following request using the Graph API: POST https://graph.microsoft.com/v1.0/$batch

Body is GET users?$filter=identities/any(c:c/issuerAssignedId eq '<the issuer Assigned id>' and c/issuer eq 'contoso.com')&$select=id,displayName,email,UserPrincipalName,identities,accountEnabled

{
    "requests": [
        {
            "id": "d26195f1-aa54-461f-9119-aa98687ea27e",
            "url": "/users?%24filter=identities%2Fany% ... ",
            "method": "GET",
            "headers": {
                "accept": "application/json"
            }
        }
    ]
}

Response: shortended just to show the structure. Note the nested structure in the body which causes the erroneous behavior.

{
    "responses": [ 
         {
            "id": "766378b9-df71-473d-909a-da07fa9f10c5",
            "status": 200,
            "headers": {...},
            "body": {
                "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users(id,displayName,email,userPrincipalName,identities,accountEnabled)",
                "value": [
                    {
                        "id": "<some Id>",
                        "displayName": "John Doe",
                        "userPrincipalName": "cpim_something",
                        "accountEnabled": false,
                        "identities": [...]
                    }
                ]
            }
        }
    ]
}

The image shows the structure of parseNode in com.microsoft.graph.core.requests.ResponseBodyHandler#handleResponse for a Request that CAN NOT be parsed:
image

The image shows the structure of parseNode in com.microsoft.graph.core.requests.ResponseBodyHandler#handleResponse for a request that CAN be parsed:
image

Remarks

I verified this by unnesting the structure and re-parsing the response:

ByteArrayInputStream unnestedResponse =  new ByteArrayInputStream(((java.util.ArrayList)((JsonArray)((com.google.gson.internal.LinkedTreeMap.Node)((com.google.gson.internal.LinkedTreeMap)((JsonObject)((JsonParseNode)parseNode).currentNode).members).entrySet().toArray()[1]).getValue()).elements).get(0).toString().getBytes());

String contentType = body.contentType().type() + "/" + body.contentType().subtype();

this.parseNodeFactory
    .getParseNode(contentType, unnestedResponse)
    .getObjectValue(this.factory);

An intermediate fix (not yet tested) could be to provide your own implementation of ResponseBodyHandler when invoking com.microsoft.graph.core.content.BatchResponseContentCollection#getResponseById(java.lang.String, com.microsoft.kiota.ResponseHandler)

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với com.microsoft.graph.core.requests.ResponseBodyHandler#handleResponse và theo dõi cách body lồng nhau của phản hồi POST $batch được truyền đến nút parse. Xem lại BatchResponseContentCollection#getResponseById và bản tái hiện JSON lồng nhau được cung cấp. Hoàn tất khi các đối tượng UserCollectionResponse lồng nhau được parse chính xác, với lỗi phù hợp đối với các phản hồi không thể parse.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java
Lĩnh vực
api, backend
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.