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

do not skip_serializing of read only schemas #317

Merged
merged 1 commit into from
Jun 29, 2021

Conversation

ctaggart
Copy link
Contributor

This allows the models to be used from the server-side and makes testing easier.

@ctaggart ctaggart marked this pull request as ready for review June 25, 2021 21:43
Copy link
Member

@heaths heaths left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Just a couple of questions, really. Maybe there's follow-up from those, but no reason to hold up this PR.

@@ -240,15 +240,11 @@ impl CodeGen {
if &nm.to_string() != property_name {
serde_attrs.push(quote! { rename = #property_name });
}
if property.schema.read_only == Some(true) {
serde_attrs.push(quote! { skip_serializing });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this just because the read-only authoring couldn't necessarily be trusted? More so just curious. I think the change here looks safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is specific to the client side. I want to be able to do round-trip testing and I want to use the models from the server-side. One reason for read-only is so that the client doesn't send a bunch of the data back to the server. It is an optimization that isn't needed right now. Another design would be to generate a function that could clear the read only values, may be .clear_read_only().

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good optimization that I don't think we do in other language SDKs right now. I imagine the fear is that, for PATCH operations (could be implemented as a PUT as well), missing data handled incorrectly could result in data loss. @pakrym might have more insight into why we still send read-only data back, or if it's just an optimization we haven't yet done.

Copy link

@pakrym pakrym Jun 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know we don't for .NET. Thanks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And, that said, if it hasn't been a detected problem yet this is probably a safe optimization. Ideally, if we did find a problem it should be a service-side fix since Azure has guidelines on patching resources.

@@ -83,13 +83,13 @@ pub struct EgressConfig {}
pub struct AlertContext {}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Essentials {
#[serde(skip_serializing)]
#[serde(default, skip_serializing_if = "Option::is_none")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More of a general comment: I'm surprised serde doesn't do this for Option<T> in general like serializers do in our other languages. Is there some way we can modify the behavior and not have to attribute every optional or vectored field?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason would be that some serialization formats require all fields to be present. serde is for more than just json so even if you could argue that for json the field should just not be present (which I don't think is a thing one could claim), it might not work for other seralization formats.

@ctaggart ctaggart merged commit f9921d1 into Azure:master Jun 29, 2021
@ctaggart ctaggart deleted the do_not_skip_serializing branch June 29, 2021 20:03
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.

4 participants