-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Unify handling of documentation IDs in OpenAPI XML comment generator #62692
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
Conversation
Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
There was a problem hiding this 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 documentation comment IDs are normalized (by stripping return type suffixes) so that XML comments from both in-memory compilation and referenced XML files can be consistently matched and merged.
- Introduced a
NormalizeDocId
helper in the source generator parser and emitter - Updated code generation to normalize IDs during XML and compilation parsing and at runtime lookup
- Added and updated unit tests and snapshot files to validate the normalization logic
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
File | Description |
---|---|
src/OpenApi/gen/XmlCommentGenerator.Parser.cs | Added NormalizeDocId and applied it when collecting XML and compilation-generated comment IDs |
src/OpenApi/gen/XmlCommentGenerator.Emitter.cs | Added NormalizeDocId and used it for lookups in the generated transformers |
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/XmlCommentDocumentationIdTests.cs | Added unit tests for NormalizeDocId |
src/OpenApi/test/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/snapshots/* | Updated generated snapshots to remove return type suffixes and reflect normalized IDs |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@copilot Can you fix the following build error?
|
Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
The OpenAPI XML comment generator was producing different documentation comment IDs for the same symbols depending on whether they came from in-memory compilation or XML files from referenced assemblies. This mismatch caused valid XML comments to be silently dropped during the merge process.
Problem
In-memory compilation:
DocumentationCommentId.CreateDeclarationId(method)
returns IDs with return type suffixes:XML files: Referenced assemblies contain compiler-style IDs without return type suffixes:
Merge failure:
DocumentationCommentId.GetFirstSymbolForDeclarationId(name, compilation)
fails to find symbols when the key includes the return type suffix, causing comments to be discarded.Solution
Implemented a
NormalizeDocId
helper method that:~ReturnType
) from ordinary method documentation IDsop_Implicit
/op_Explicit
)Changes
ParseXmlFile
andParseCompilation
to normalize documentation IDs during collectionNormalizeDocId
method to generated code and updated transformers to use normalized lookup keysExample
Before the fix, XML comments from referenced assemblies were ignored:
After the fix, both are normalized to the same format:
All existing tests pass, confirming the fix doesn't break any existing functionality while resolving the XML comment merge issue.
Fixes #62691.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.