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

[C# analyzers] Update AZC0030 so that it doesn't prevent clients from having serializable models with the Options suffix #9335

Open
annelo-msft opened this issue Nov 6, 2024 · 5 comments · May be fixed by #9370

Comments

@annelo-msft
Copy link
Member

It is a common pattern in data plane clients to have model types with the Options suffix.

This issue tracks the work to understand and document the intended scope of analyzer warning AZC0030, so it can be scoped down to address only intended cases.

This warning was introduced in #6916 and modified in #7250. @jsquire has suggested that it was intended to prevent subtypes of ClientOptions from being serializable. We need to confirm this is the intended scope so we don't change an analyzer that is needed for other cases.

If this is the correct intended scope, the analyzer should be updated to validate specifically that subtypes of ClientOptions do not implement the IPersistableModel<T> interface, and not prevent any type with the Options suffix from being serializable.

@archerzz, @m-nash, @christothes, would it be possible to help us understand the intended scope of this warning?

@archerzz
Copy link
Member

archerzz commented Nov 6, 2024

@annelo-msft This rule was from .NET Mgmt SDK Review Guide:
Image

The rule regarding Options seems have been changed since I implemented the analyzer. The latest version is opposite to what Jesse suggested.

Anyway, the key point is that when I wrote those rules, they were for mgmt SDK only. See the original repo: https://github.com/archerzz/Azure.MgmtSdk.Analyzers

Then when we added them into current analyzer package, we thought those are generic and we should them enable for all SDKs.

To resolve this issue, I think we could:

  • remove Options suffix check from AZC0030
  • create a Azure.MgmtSdk.Analzyers package, put that rule and any further mgmt specific rules into that package
  • in our build script, enable Azure.MgmtSdk.Analzyers only for mgmt SDKs

cc @ArthurMa1978

@ArthurMa1978
Copy link
Member

This convention rule has been confirmed by @KrzysztofCwalina. If we need alternative suggestions, we'll require input from KC.

@annelo-msft
Copy link
Member Author

annelo-msft commented Nov 6, 2024

Super helpful context, many thanks for sharing it, @archerzz and @ArthurMa1978!

I worked with @m-nash and @KrzysztofCwalina to clarify the guidance around the options parameter pattern in our Azure SDK C# guidelines. Existing guidance is here:

I will update the guidelines and I expect that to be completed in a few days -- I can CC you on the PR if you are interested.

We decided that with regard to the analyzer, if it is possible to scope the rule to management-plane only, that would be ideal. @m-nash has shared that the analyzer has been very helpful in the development of management plane libraries, and we of course don't want to remove something that is bringing value here! On the data-plane side, the rule is creating some friction for TypeSpec-first partners, and we are seeking to make that as streamlined a process as possible.

@archerzz, is having a separate package the easiest way to scope this analyzer to management-plane only? Are there other approaches that could keep the analyzer in a single package, for example, by checking whether the Options-suffixed type is in a namespace that begins with Azure.ResourceManager before raising the warning? If the latter would catch all management plane cases, it might be faster to implement and deploy ... but let me know if you can think of more efficient approaches here.

@KrzysztofCwalina
Copy link
Member

This convention rule has been confirmed by @KrzysztofCwalina. If we need alternative suggestions, we'll require input from KC.

I don't remember this, though my memory might be failing me :-). But, in .NET, the term "config" is associated with configuration systems, i.e. the ability to change apps without recompiling them.

@archerzz
Copy link
Member

archerzz commented Nov 7, 2024

Super helpful context, many thanks for sharing it, @archerzz and @ArthurMa1978!

I worked with @m-nash and @KrzysztofCwalina to clarify the guidance around the options parameter pattern in our Azure SDK C# guidelines. Existing guidance is here:

I will update the guidelines and I expect that to be completed in a few days -- I can CC you on the PR if you are interested.

We decided that with regard to the analyzer, if it is possible to scope the rule to management-plane only, that would be ideal. @m-nash has shared that the analyzer has been very helpful in the development of management plane libraries, and we of course don't want to remove something that is bringing value here! On the data-plane side, the rule is creating some friction for TypeSpec-first partners, and we are seeking to make that as streamlined a process as possible.

@archerzz, is having a separate package the easiest way to scope this analyzer to management-plane only? Are there other approaches that could keep the analyzer in a single package, for example, by checking whether the Options-suffixed type is in a namespace that begins with Azure.ResourceManager before raising the warning? If the latter would catch all management plane cases, it might be faster to implement and deploy ... but let me know if you can think of more efficient approaches here.

@annelo-msft Of course. We've done similar thing before, like:

if (IsTypeOf(symbol, "Azure.ResourceManager", "ArmResource"))
return true;

@archerzz archerzz self-assigned this Nov 8, 2024
@archerzz archerzz added this to the 2024-12 milestone Nov 8, 2024
archerzz pushed a commit to archerzz/azure-sdk-tools that referenced this issue Nov 13, 2024
- update analyzer to only check `Options` suffix if the class is under a mgmt SDK namespace
- update test cases accordingly

fix Azure#9335
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants