Skip to content

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

Merged
merged 6 commits into from
Jul 14, 2025

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jul 12, 2025

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

  1. In-memory compilation: DocumentationCommentId.CreateDeclarationId(method) returns IDs with return type suffixes:

    M:Api.ProjectBoardApis.DeleteProjectBoard(System.Int32)~System.Threading.Tasks.Task
    
  2. XML files: Referenced assemblies contain compiler-style IDs without return type suffixes:

    <member name="M:Api.ProjectBoardApis.DeleteProjectBoard(System.Int32)">
  3. 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:

  • Strips return type suffixes (~ReturnType) from ordinary method documentation IDs
  • Preserves return type suffixes for conversion operators (op_Implicit/op_Explicit)
  • Normalizes both collection-phase and runtime lookup keys to the compiler-style format

Changes

  • Parser: Updated ParseXmlFile and ParseCompilation to normalize documentation IDs during collection
  • Emitter: Added NormalizeDocId method to generated code and updated transformers to use normalized lookup keys
  • Tests: Added comprehensive unit tests for normalization logic and integration tests for cross-assembly XML comment merging

Example

Before the fix, XML comments from referenced assemblies were ignored:

// Referenced assembly XML: M:TestApi.Method(System.Int32)
// In-memory lookup:        M:TestApi.Method(System.Int32)~System.Threading.Tasks.Task
// Result: No match, comment dropped

After the fix, both are normalized to the same format:

// Normalized cache key:    M:TestApi.Method(System.Int32)
// Normalized lookup key:   M:TestApi.Method(System.Int32)  
// Result: Match found, comment applied

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.

Copilot AI and others added 3 commits July 12, 2025 00:52
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>
@Copilot Copilot AI changed the title [WIP] Unify handling of documentation IDs in OpenAPI XML comment generator Unify handling of documentation IDs in OpenAPI XML comment generator Jul 12, 2025
@Copilot Copilot AI requested a review from captainsafia July 12, 2025 01:03
Copilot finished work on behalf of captainsafia July 12, 2025 01:03
@captainsafia captainsafia marked this pull request as ready for review July 14, 2025 16:31
@Copilot Copilot AI review requested due to automatic review settings July 14, 2025 16:31
@captainsafia captainsafia requested a review from a team as a code owner July 14, 2025 16:31
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 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>
@captainsafia
Copy link
Member

@copilot Can you fix the following build error?

src/OpenApi/gen/XmlCommentGenerator.Parser.cs(35,43): error CS0103: (NETCORE_ENGINEERING_TELEMETRY=Build) The name 'StringComparison' does not exist in the current context

Co-authored-by: captainsafia <1857993+captainsafia@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jul 14, 2025

@copilot Can you fix the following build error?

...

Fixed the build error by adding the missing using System; directive to enable use of StringComparison.Ordinal in the NormalizeDocId method. Build now succeeds without errors. (01943b5)

Copilot finished work on behalf of captainsafia July 14, 2025 19:20
@captainsafia captainsafia enabled auto-merge (squash) July 14, 2025 21:04
@captainsafia captainsafia merged commit 84cd99a into main Jul 14, 2025
26 of 28 checks passed
@captainsafia captainsafia deleted the copilot/fix-62691 branch July 14, 2025 21:40
@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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unify handling of documentation IDs in OpenAPI XML comment generator
3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy