Skip to content

fix(OpenAPI): add GeneratedCodeAttribute to generated classes #62710

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

Merged
merged 2 commits into from
Jul 14, 2025

Conversation

timdeschryver
Copy link
Contributor

@timdeschryver timdeschryver commented Jul 14, 2025

Add GeneratedCodeAttribute to generated OpenAPI classes

  • You've read the Contributor Guide and Code of Conduct.
  • You've included unit or integration tests for your change, where applicable.
  • You've included inline docs for your change, where applicable.
  • There's an open issue for the PR that you are making. If you'd like to propose a new feature or change, please open an issue to discuss the change or find an existing issue.

Description

This adds the GeneratedCode atribute to generated classes where this attribute was not set.

Fixes #62705

@Copilot Copilot AI review requested due to automatic review settings July 14, 2025 15:59
@timdeschryver timdeschryver requested review from captainsafia and a team as code owners July 14, 2025 15:59
@github-actions github-actions bot added the needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically label Jul 14, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR ensures that generated OpenAPI helper classes are marked with the GeneratedCodeAttribute.

  • Inserts the {{GeneratedCodeAttribute}} placeholder before DocumentationCommentIdHelper and JsonNodeExtensions.
  • Aligns generated classes with tooling metadata requirements.
Comments suppressed due to low confidence (2)

src/OpenApi/gen/XmlCommentGenerator.Emitter.cs:96

  • Consider adding or updating a unit test to verify that generated classes like DocumentationCommentIdHelper and JsonNodeExtensions are decorated with GeneratedCodeAttribute, ensuring this metadata is applied as expected.
    {{GeneratedCodeAttribute}}

src/OpenApi/gen/XmlCommentGenerator.Emitter.cs:96

  • It looks like the GeneratedCodeAttribute is used but its namespace isn’t imported. Add using System.CodeDom.Compiler; at the top of the file so the attribute resolves correctly.
    {{GeneratedCodeAttribute}}

@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jul 14, 2025
@martincostello martincostello added feature-openapi area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc and removed needs-area-label Used by the dotnet-issue-labeler to label those issues which couldn't be triaged automatically labels Jul 14, 2025
@timdeschryver
Copy link
Contributor Author

I was a bit too fast.
I will update the verified tests, and see if additional tests are required.

Copy link
Member

@captainsafia captainsafia left a comment

Choose a reason for hiding this comment

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

LGTM -- thanks for the PR!

My kingdom for a world where we don't have to stick attributes on every type and coverage tools will respect things if the header and filename are marked as generated.

@captainsafia captainsafia merged commit 1b5d54e into dotnet:main Jul 14, 2025
28 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview7 milestone Jul 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-minimal Includes minimal APIs, endpoint filters, parameter binding, request delegate generator etc community-contribution Indicates that the PR has been added by a community member feature-openapi
Projects
None yet
Development

Successfully merging this pull request may close these issues.

OpenAPI Generated Code (DocumentationCommentIdHelper) is not annotated with GeneratedCodeAttribute
3 participants