Skip to content

OpenAPI source-generated XML comments are missing the return-type for minimal API request delegate in another assembly #62216

Open
@Trivivium

Description

@Trivivium

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

While trying out the changes to the XML source-generated documentation for Open API introduced with .NET 10 preview 4, I ran into an issue regarding Minimal API handlers defined in another assembly.

The Open API XML operation transformer fails to locate the correct source-generated XML comment. It seems to be due to the source-generator missing the ~ReturnType of the cache key.

This only happens if the handler is defined in another assembly. Handlers in the same assembly as the Microsoft.AspNetCore.OpenApi NuGet package works.

Expected Behavior

The OpenAPI to successfully resolve the XML <summary> regardless of the assembly the handler is defined in.

From debugging, it looks like the XmlCommentSchemaTransformer and XmlCommentOperationTransformer (added by the source generator) correctly builds the XML documentation ID with the return type.

Steps To Reproduce

I've reduced the bug to a simple solution: https://github.com/Trivivium/dotnet-xml-comments-bug

Compling the linked solution, and inspecting the source-generated output shows:

    // ... more source-gen code above

    file static class XmlCommentCache
    {
        private static Dictionary<string, XmlComment>? _cache;
        public static Dictionary<string, XmlComment> Cache => _cache ??= GenerateCacheEntries();

        private static Dictionary<string, XmlComment> GenerateCacheEntries()
        {
            var cache = new Dictionary<string, XmlComment>();

            cache.Add(@"M:OtherAssembly.B.Handle", new XmlComment(@"This is B handler", null, null, null, null, false, null, null, null));
            cache.Add(@"M:A.Handle~Foo", new XmlComment(@"This is A handler", null, null, null, null, false, null, null, null));

            return cache;
        }
    }

    // ... more source-gen code after

Notice, the A.Handle have its return type, while the B.Handle in another assembly doesn't.

There are no exceptions at runtime.

There are no warnings at build time (except for the "CS1591 : Missing XML comment for publicly visible type or member", I omitted those to keep the sample concise).

Exceptions (if any)

No response

.NET Version

10.0.100-preview.4.25258.110

Anything else?

.NET SDK:
Version: 10.0.100-preview.4.25258.110
Commit: c22dcd0c7a
Workload version: 10.0.100-manifests.e9b6aa6e
MSBuild version: 17.15.0-preview-25258-110+c22dcd0c7

Runtime Environment:
OS Name: Windows
OS Version: 10.0.26100
OS Platform: Windows
RID: win-x64
Base Path: C:\Program Files\dotnet\sdk\10.0.100-preview.4.25258.110\

.NET workloads installed:
There are no installed workloads to display.
Configured to use workload sets when installing new manifests.
Workloads are configured to install and update using workload versions, but none were found. Run "dotnet workload restore" to install a workload version.

Host:
Version: 10.0.0-preview.4.25258.110
Architecture: x64
Commit: c22dcd0c7a

.NET SDKs installed:
3.1.201 [C:\Program Files\dotnet\sdk]
6.0.103 [C:\Program Files\dotnet\sdk]
9.0.300 [C:\Program Files\dotnet\sdk]
10.0.100-preview.4.25258.110 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 10.0.0-preview.4.25258.110 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 10.0.0-preview.4.25258.110 [C:\Program
Microsoft.WindowsDesktop.App 8.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 9.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 10.0.0-preview.4.25258.110 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
Not set

global.json file:
Not found

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions