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

Update Autorest C# - IOT #13558

Merged
merged 3 commits into from
Jul 21, 2020
Merged

Conversation

pakrym
Copy link
Contributor

@pakrym pakrym commented Jul 17, 2020

Contributes to #13511

Major features

  1. Collections are now always initialized and collection properties are readonly by default
  2. Internal deserialization ctors are removed for input-only models
  3. Improved nullability support - fewer extra null checks, correct nullable types generated. Might require adding missing annotations to the swagger spec.
  4. Improved header support - descriptions and x-ms-client-name honored.
  5. Single value, modelAsString enums are generated as types, they were string constants before.
  6. Readonly properties are not serialized - affects recordings.

What you might need to do:

  1. If you copied and overrode the serialization code you might want to update it to be in sync with new generator patterns.
  2. Please follow up on updating the centralized swagger file if there were workarounds applied to autorest.md

/// <summary>
/// Helper functions for mutating the <see cref="ExportImportDevice"/> instance.
/// </summary>
internal static class ExportImportDeviceExtensions
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 class handcrafted, or generated by autorest?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Handcrafted.

ImportMode = ExportImportDeviceImportMode.Create
});
}.WithTags(x.Value.Tags).WithPropertiesFrom(x.Value.Properties).WithParentScopes(x.Key.ParentScopes));
Copy link
Member

@abhipsaMisra abhipsaMisra Jul 18, 2020

Choose a reason for hiding this comment

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

As per # 1: So this is because these fields, being collections, are readonly by default, and so they need additional helper methods?
https://github.com/pakrym/azure-sdk-for-net/blob/pakrym/update-generator-IOT/sdk/iot/Azure.Iot.Hub.Service/src/Generated/Models/ExportImportDevice.cs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct.

Copy link
Member

Choose a reason for hiding this comment

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

I see, what was the driving force behind this change? Should collections not be settable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The following guideline:

https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/guidelines-for-collections#collection-properties-and-return-values

❌ DO NOT provide settable collection properties.

Users can replace the contents of the collection by clearing the collection first and then adding the new contents.

Copy link
Member

Choose a reason for hiding this comment

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

This class can probably be internal. Will check and let you know. If it is internal, we would not need the extensions right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure I understand why not. We would still need to create instances of this class and the code-gen for properties doesn't change depending on the class being internal or not.

Copy link
Member

Choose a reason for hiding this comment

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

And I want to add here that this is still work in progress and we are yet to make some classes internal which we do not expose. Just curious, is there something you use to be able to detect these in the API surface?

Copy link
Member

@abhipsaMisra abhipsaMisra left a comment

Choose a reason for hiding this comment

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

We'll go through the Model types, as we work on the APIs, and make necessary changes.

@pakrym pakrym merged commit e241ebe into Azure:master Jul 21, 2020
@pakrym pakrym deleted the pakrym/update-generator-IOT branch July 21, 2020 18:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants