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

[ClientBug] FileAttachment is not serialized with @odata.type #479

Closed
gaspik opened this issue Jun 22, 2022 · 3 comments · Fixed by #493
Closed

[ClientBug] FileAttachment is not serialized with @odata.type #479

gaspik opened this issue Jun 22, 2022 · 3 comments · Fixed by #493
Assignees
Labels
Bug Something isn't working fixed OpenApi

Comments

@gaspik
Copy link

gaspik commented Jun 22, 2022

Describe the bug
When uploading event attachment, the request is refused with error
{"error":{"code":"UnprocessableType","message":"Cannot process input of abstract type 'microsoft.graph.attachment'"}}

To Reproduce
Try to upload FileAttachment object to existing event. Sample code;

FileAttachment fileAttachment = ToMSGraphCommonConversion.ConvertAttachment(attachment);
					await GraphServiceClient.Me.Events[validId]
						.Attachments
						.PostAsync(fileAttachment, cancellationToken: cancellationToken);

This serializes the object as:
{"isInline":false,"name":"empty.txt","size":5,"contentBytes":"ZW1wdHk="}

i.e. without FileAttachment type specification.

In v4, the object is serialized as
{"contentBytes":"ZW1wdHk=","isInline":false,"name":"empty.txt","size":5,"@odata.type":"microsoft.graph.fileAttachment"}

Expected behavior
Specify correct odata.type during serialization

Client version
5.6.0-preview

Desktop (please complete the following information):

  • OS: Win 10 x64
  • Browser: N/A, WinForms application using standard HttpClient
  • Version: N/A
@ghost ghost added the Needs: Triage label Jun 22, 2022
@andrueastman andrueastman added OpenApi Bug Something isn't working and removed Needs: Triage labels Jun 29, 2022
@andrueastman
Copy link
Member

Thanks for raising this @gaspik and trying out the new preview.

This is related to microsoft/OpenAPI.NET.OData#243 which is not emitting the @odata.type property in the object's reference schema. We'll close this once the openApi conversion library fixes this and make a release with the corresponding schema update.

For now you should be able to work around this by placing adding the property in the additionalData bag.

            var fileAttachment = ToMSGraphCommonConversion.ConvertAttachment(attachment);
            fileAttachment.AdditionalData["@odata.type"] = "microsoft.graph.fileAttachment";

@andrueastman andrueastman self-assigned this Jun 29, 2022
@andrueastman andrueastman linked a pull request Jul 20, 2022 that will close this issue
1 task
@andrueastman
Copy link
Member

Closing this one for now.

The missing entries for odata.type have been updated via #493 and available through the latest 5.10.0-preview package.

OdataType = "#microsoft.graph.fileAttachment";

@gaspik
Copy link
Author

gaspik commented Jul 20, 2022

@andrueastman It looks like the fix broke something else, see

#495

@ghost ghost locked as resolved and limited conversation to collaborators Aug 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Something isn't working fixed OpenApi
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants