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

Emit [GeneratedCode] for C# code generation #4907

Closed
martincostello opened this issue Jun 29, 2024 · 4 comments · Fixed by #4924
Closed

Emit [GeneratedCode] for C# code generation #4907

martincostello opened this issue Jun 29, 2024 · 4 comments · Fixed by #4924
Assignees
Labels
Csharp Pull requests that update .net code type:feature New experience request
Milestone

Comments

@martincostello
Copy link
Contributor

Is your feature request related to a problem? Please describe the problem.

When generating C# client code with Kiota, the classes produced are not annotated with the [GeneratedCode] attribute.

While // <auto-generated/> is added to the source files, which is useful for tools like style analyzers, this is not visible to static analysis tools that work with compiled binaries.

For example, it is common to exclude generated code from tools such as code coverage tools, as often the coverage of such code is not considered interesting when determining test suite coverage. Many tools such as coverlet support excluding code marked with specific attributes, such as [ExcludeFromCodeCoverage] or [GeneratedCode], as these are easy to blanket-apply, rather than requiring types be excluded by specific names/namespaces.

See here for a similar feature request for source-generated code in the .NET runtime: dotnet/runtime#89007

As well as the specific motivating factor of easier code coverage tooling exclusions, such annotations would also be useful for other static analysis that may wish to specifically find code that has been generated by Kiota as opposed to user-written.

Client library/SDK language

Csharp

Describe the solution you'd like

All C# types generated by Kiota are decorated with [GeneratedCode("{tool}", "{version}")].

For example:

+ [System.CodeDom.Compiler.GeneratedCode("kiota", "1.15.0")]
  public class ApiClient : BaseRequestBuilder
  {
  }

Additional context

No response

@martincostello martincostello added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:feature New experience request labels Jun 29, 2024
@msgraph-bot msgraph-bot bot added the Csharp Pull requests that update .net code label Jun 29, 2024
@andrueastman
Copy link
Member

I think this is a valid suggestion. It's great that the attribute is part of .NET, Any objections @baywet?

Essentially, what we'd probably need to do is very similar to the PR at https://github.com/microsoft/kiota/pull/3034/files as well as add usings for System.CodeDom.Compiler (if we don't use the Fully qualified names) similar to

new (static x => x is CodeClass || x is CodeEnum,

@andrueastman andrueastman removed the status:waiting-for-triage An issue that is yet to be reviewed or assigned label Jul 2, 2024
@andrueastman andrueastman added this to the Backlog milestone Jul 2, 2024
@baywet
Copy link
Member

baywet commented Jul 2, 2024

No objections on my side. For some reason I had not caught the subtility of using a doc comment versus using an attribute for the static analysis options. I think adding this attribute will be a great improvement for tools like sonarCloud or others which work on compiled static analysis.
@martincostello are you willing to submit a pull request for that?

@baywet baywet added the status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close label Jul 2, 2024
@martincostello
Copy link
Contributor Author

Sure - I was just waiting for an agreement it would be a wanted change before starting 😄

@microsoft-github-policy-service microsoft-github-policy-service bot added Needs: Attention 👋 and removed status:waiting-for-author-feedback Issue that we've responded but needs author feedback to close labels Jul 2, 2024
martincostello added a commit to martincostello/kiota that referenced this issue Jul 2, 2024
Emit `[GeneratedCode]` attribute for C# types.
Resolves microsoft#4907.
martincostello added a commit to martincostello/kiota that referenced this issue Jul 2, 2024
Emit `[GeneratedCode]` attribute for C# types.
Resolves microsoft#4907.
@martincostello
Copy link
Contributor Author

#4924

andrueastman added a commit that referenced this issue Jul 3, 2024
…tribute

Emit [GeneratedCode] attribute for C# types
@andrueastman andrueastman modified the milestones: Backlog, Kiota v1.16 Jul 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Csharp Pull requests that update .net code type:feature New experience request
Projects
Status: Done ✔️
Development

Successfully merging a pull request may close this issue.

3 participants