-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
4d97c9b
Initial plan
Copilot 7215cca
Implement NormalizeDocId fix for XML comment generator
Copilot 2d42791
Fix runtime lookup to use normalized documentation IDs
Copilot a6c9247
Update snapshots to reflect normalized documentation IDs
Copilot 22760db
Update src/OpenApi/gen/XmlCommentGenerator.Parser.cs
captainsafia 01943b5
Fix missing using System directive for StringComparison
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
...est/Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests/XmlCommentDocumentationIdTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Net.Http; | ||
using System.Text.Json.Nodes; | ||
|
||
namespace Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests; | ||
|
||
[UsesVerify] | ||
public class XmlCommentDocumentationIdTests | ||
{ | ||
[Fact] | ||
public async Task CanMergeXmlCommentsWithDifferentDocumentationIdFormats() | ||
{ | ||
// This test verifies that XML comments from referenced assemblies (without return type suffix) | ||
// are properly merged with in-memory symbols (with return type suffix) | ||
var source = """ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Builder; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using ReferencedLibrary; | ||
|
||
var builder = WebApplication.CreateBuilder(); | ||
|
||
builder.Services.AddOpenApi(); | ||
|
||
var app = builder.Build(); | ||
|
||
app.MapPost("/test-method", ReferencedLibrary.TestApi.TestMethod); | ||
|
||
app.Run(); | ||
"""; | ||
|
||
var referencedLibrarySource = """ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace ReferencedLibrary; | ||
|
||
public static class TestApi | ||
{ | ||
/// <summary> | ||
/// This method should have its XML comment merged properly. | ||
/// </summary> | ||
/// <param name="id">The identifier for the test.</param> | ||
/// <returns>A task representing the asynchronous operation.</returns> | ||
public static Task TestMethod(int id) | ||
{ | ||
return Task.CompletedTask; | ||
} | ||
} | ||
"""; | ||
|
||
var references = new Dictionary<string, List<string>> | ||
{ | ||
{ "ReferencedLibrary", [referencedLibrarySource] } | ||
}; | ||
|
||
var generator = new XmlCommentGenerator(); | ||
await SnapshotTestHelper.Verify(source, generator, references, out var compilation, out var additionalAssemblies); | ||
await SnapshotTestHelper.VerifyOpenApi(compilation, additionalAssemblies, document => | ||
{ | ||
var path = document.Paths["/test-method"].Operations[HttpMethod.Post]; | ||
|
||
// Verify that the XML comment from the referenced library was properly merged | ||
// This would fail before the fix because the documentation IDs didn't match | ||
Assert.NotNull(path.Summary); | ||
Assert.Equal("This method should have its XML comment merged properly.", path.Summary); | ||
|
||
// Verify the parameter comment is also available | ||
Assert.NotNull(path.Parameters); | ||
Assert.Single(path.Parameters); | ||
Assert.Equal("The identifier for the test.", path.Parameters[0].Description); | ||
}); | ||
} | ||
|
||
[Theory] | ||
[InlineData("M:Sample.MyMethod(System.Int32)~System.Threading.Tasks.Task", "M:Sample.MyMethod(System.Int32)")] | ||
[InlineData("M:Sample.MyMethod(System.Int32)", "M:Sample.MyMethod(System.Int32)")] | ||
[InlineData("M:Sample.op_Implicit(System.Int32)~Sample.MyClass", "M:Sample.op_Implicit(System.Int32)~Sample.MyClass")] | ||
[InlineData("M:Sample.op_Explicit(System.Int32)~Sample.MyClass", "M:Sample.op_Explicit(System.Int32)~Sample.MyClass")] | ||
[InlineData("T:Sample.MyClass", "T:Sample.MyClass")] | ||
[InlineData("P:Sample.MyClass.MyProperty", "P:Sample.MyClass.MyProperty")] | ||
public void NormalizeDocId_ReturnsExpectedResult(string input, string expected) | ||
{ | ||
var result = XmlCommentGenerator.NormalizeDocId(input); | ||
Assert.Equal(expected, result); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.