Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enum Serialization doing wrongly according to docs #2385

Open
gabrieligbastos opened this issue Mar 14, 2024 · 3 comments
Open

Enum Serialization doing wrongly according to docs #2385

gabrieligbastos opened this issue Mar 14, 2024 · 3 comments

Comments

@gabrieligbastos
Copy link

Describe the bug
Im trying to report policy violation API in Teams, using the /v1.0/chats/{chat-id}/messages/{message-id} Endpoint.
The serialization is defined to be camel case starting with lower case, but documentation says it should be camelCase starting with UpperCase, so Im getting 400 Bad Request - Invalid request body was sent! message

To Reproduce
Steps to reproduce the behavior:

  1. Create a simple snippet to report policy violation

var chatId = turnContext.Activity.Conversation.Id;
var messageId = turnContext.Activity.Id;

                var requestBody = new ChatMessage
                {
                    PolicyViolation = new ChatMessagePolicyViolation
                    {
                        PolicyTip = new ChatMessagePolicyViolationPolicyTip
                        {
                            GeneralText = "This item has been blocked by the administrator",
                            ComplianceUrl = "https://contoso.com/dlp-policy-page",
                            MatchedConditionDescriptions = new List<string> { "Credit Card Number" },
                        },
                        VerdictDetails = ChatMessagePolicyViolationVerdictDetailsTypes.AllowOverrideWithJustification | ChatMessagePolicyViolationVerdictDetailsTypes.AllowFalsePositiveOverride,
                        DlpAction = ChatMessagePolicyViolationDlpActionTypes.BlockAccess,
                    },
                };
                var result = await _graphClient.Chats[chatId].Messages[messageId].PatchAsync(requestBody);
  1. It will throw an exception with OData error, pointing to "Invalid request body was sent"

Expected behavior
Success message without exception being thrown

Screenshots

Dotnet SDK
Dotnet 6.0
Microsoft.Graph 5.44.0

Additional context
The payload built through

 var requestBody = new ChatMessage
                    {
                        PolicyViolation = new ChatMessagePolicyViolation
                        {
                            PolicyTip = new ChatMessagePolicyViolationPolicyTip
                            {
                                GeneralText = "This item has been blocked by the administrator",
                                ComplianceUrl = "https://contoso.com/dlp-policy-page",
                                MatchedConditionDescriptions = new List<string> { "Credit Card Number" },
                            },
                            VerdictDetails = ChatMessagePolicyViolationVerdictDetailsTypes.AllowOverrideWithJustification | ChatMessagePolicyViolationVerdictDetailsTypes.AllowFalsePositiveOverride,
                            DlpAction = ChatMessagePolicyViolationDlpActionTypes.BlockAccess,
                        },
                    };

is being serialized to:

{
    "policyViolation": {
        "dlpAction": "blockAccess",
        "policyTip": {
            "complianceUrl": "https://contoso.com/dlp-policy-page",
            "generalText": "This item has been blocked by the administrator",
            "matchedConditionDescriptions": [
                "Credit Card Number"
            ]
        },
        "verdictDetails": "allowFalsePositiveOverride,allowOverrideWithJustification"
    }
}

But according to doc at: https://learn.microsoft.com/pt-br/graph/api/chatmessage-update?view=graph-rest-1.0&tabs=http
It should starts with Upper case (BlockAccess and AllowFalsePositiveOverride and AllowOverrideWithJustification)

So, because of that, im getting the error back from API

{
    "error": {
        "code": "BadRequest",
        "message": "Invalid request body was sent.",
        "innerError": {
            "date": "2024-03-14T01:16:42",
            "request-id": "2bba391e-affe-4b9c-9276-8dd46e4ad787",
            "client-request-id": "2bba391e-affe-4b9c-9276-8dd46e4ad787"
        }
    }
}
@andrueastman
Copy link
Member

Thanks for raising this @gabrieligbastos

According to the metadata used to generate the SDK, the properties are camelCased which is inconsistent with the docs.
image

Just to confirm, if you make the request with the properties starting with an uppercase, are you able to get a successful response when using the Graph Explorer or Postman?

@gabrieligbastos
Copy link
Author

Hey @andrueastman

So, what happened, i was getting failed request from SDK. Tried on Postman, and it was working, then, I checked my Fiddler to see what the SDK was requesting and i noted this difference. The actually problem is with the first letter.

It says the EnumType is
allowFalsePositiveOverride

But actually, it is not with lower case 'a' in the first letter, but upper case.
So i tried the same request at Fiddler, but changing allowFalsePositiveOverride to AllowFalsePositiveOverride

And it worked..
For workaround, i sent a httpClient with a custom httpClientHandler that is intercepting the requesting and changing it to me, and it is working.

But as soon as it is fixed here, i can get this hard-coded code manually making first letter uppercase cleared :)

This payload on Postman works:

{
  "policyViolation": {
    "policyTip": {
      "generalText" : "This item has been blocked by the administrator.",
      "complianceUrl" : "https://contoso.com/dlp-policy-page",
      "matchedConditionDescriptions" : ["Credit Card Number"]
    },
    "verdictDetails" : "AllowOverrideWithoutJustification,AllowFalsePositiveOverride",
    "dlpAction" : "BlockAccess"
  }
}

@gabrieligbastos
Copy link
Author

Here is a link to another doc i found also saying the first letter is upper case.

https://learn.microsoft.com/en-us/graph/api/resources/chatmessagepolicyviolation?view=graph-rest-1.0#properties

Oh and thanks by the way for quick reply on this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants