microsoftgraph / microsoftgraph/msgraph-sdk-dotnet
Enum Serialization doing wrongly according to docs
Nobody has claimed this yet.
- 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:
- 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);
- 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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