microsoftgraph / microsoftgraph/msgraph-sdk-dotnet

Enum Serialization doing wrongly according to docs

Open
#2,385 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug: metadata Needs: Attention :wave:
Dominant language
C#
Stars
789
Forks
264
Avg merge
15h 17m
Merged PRs (30d)
3

Description

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"
        }
    }
}

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing serialization for ChatMessagePolicyViolation, including the VerdictDetails and DlpAction enum values, and compare the generated payload with the linked Graph documentation. Done means a focused reproduction or test demonstrates the documented casing and the request is accepted; the issue names no source file or test to begin from.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.