Skip to content

fix ruby model serializer - #4146

Closed
Olafur Arason (olafura) wants to merge 1 commit into
microsoft:mainfrom
olafura:olafura/fix-ruby-model-serializer
Closed

Olafur Arason (olafura) wants to merge 1 commit into
microsoft:mainfrom
olafura:olafura/fix-ruby-model-serializer

Conversation

@olafura

Copy link
Copy Markdown

I was trying to test it with generating code https://github.com/microsoftgraph/msgraph-sdk-ruby
But I could not figure out the params needed

@olafura
Olafur Arason (olafura) requested a review from a team as a code owner February 6, 2024 19:25
@baywet

Copy link
Copy Markdown
Member

for context to other reviewers microsoftgraph/msgraph-sdk-ruby#185

for information, all the settings are saved here

But you won't be able to generate a PR, there are other limitations we need to address in ruby generation for a full generation to work right away. see the CI on this PR for more context

Now, the question I have for you: why do you think this guard is necessary? What issue are you running into without it?

@olafura

Copy link
Copy Markdown
Author

for context to other reviewers microsoftgraph/msgraph-sdk-ruby#185

for information, all the settings are saved here

But you won't be able to generate a PR, there are other limitations we need to address in ruby generation for a full generation to work right away. see the CI on this PR for more context

Now, the question I have for you: why do you think this guard is necessary? What issue are you running into without it?

The problem is that we have a bunch of different serializers for the values, so for a nil value you would get:

  • bool: false
  • string: ""
    etc

So there is no way of filtering out the empty values after the serialization step only during it. And the MS Graph doesn't like random values like that. I had a bunch of complaints from it about values being set to an empty string for example

@baywet

Copy link
Copy Markdown
Member

Thanks for the additional information.
I'm still not sure I understand the problem.

Are you saying that if you do something like this (sorry, my Ruby is rusty)

my_user = new User()
my_user.last_name = "Johnson"
client.users.by_user_id("jane@contoso.com").patch(my_user)

you end up with a payload where other properties, that have never been set, end up being sent with their defaults? (e.g. displayName to null/string empty)

@olafura

Copy link
Copy Markdown
Author

Here is an example result from running it:

-                writer.write_object_value("broadcastSettings", @broadcast_settings)
+                writer.write_object_value("broadcastSettings", @broadcast_settings) unless @broadcast_settings.nil?

@olafura

Copy link
Copy Markdown
Author

Thanks for the additional information. I'm still not sure I understand the problem.

Are you saying that if you do something like this (sorry, my Ruby is rusty)

my_user = new User()
my_user.last_name = "Johnson"
client.users.by_user_id("jane@contoso.com").patch(my_user)

you end up with a payload where other properties, that have never been set, end up being sent with their defaults? (e.g. displayName to null/string empty)

Yeah exactly

@baywet

Copy link
Copy Markdown
Member

Thanks for the additional context. If we focus on this string example for a minute, shouldn't this guard clause prevent this behaviour?
https://github.com/microsoft/kiota-serialization-json-ruby/blob/1f9ffe3df487684f9fee09dbcb47954c38db0428/lib/microsoft_kiota_serialization_json/json_serialization_writer.rb#L20

@olafura

Olafur Arason (olafura) commented Feb 6, 2024 •

Copy link
Copy Markdown
Author

Thanks for the additional context. If we focus on this string example for a minute, shouldn't this guard clause prevent this behaviour? https://github.com/microsoft/kiota-serialization-json-ruby/blob/1f9ffe3df487684f9fee09dbcb47954c38db0428/lib/microsoft_kiota_serialization_json/json_serialization_writer.rb#L20

Yeah it seems to be the enum type which casts the nil into a string:
https://github.com/microsoft/kiota-serialization-json-ruby/blob/1f9ffe3df487684f9fee09dbcb47954c38db0428/lib/microsoft_kiota_serialization_json/json_serialization_writer.rb#L177-L179

model = MicrosoftGraph::Models::OnlineMeeting.new
model.subject = "Subject"
writer = MicrosoftKiotaSerializationJson::JsonSerializationWriter.new
model.serialize(writer)
writer.writer.compact
{"allowMeetingChat"=>"", "allowedPresenters"=>"", "shareMeetingChatHistoryDefault"=>"", "subject"=>"Subject"}

I'll create a PR for https://github.com/microsoft/kiota-serialization-json-ruby

@baywet

Copy link
Copy Markdown
Member

Thanks for confirming here.
Since this issue doesn't require any code generation change at this point, would it be ok to close this PR?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants