diff --git a/src/OpenApiXmlCommentGenerator/gen/Helpers/INamedTypeSymbolExtensions.cs b/src/OpenApiXmlCommentGenerator/gen/Helpers/INamedTypeSymbolExtensions.cs index 7bcde0fa6..cd58c07c1 100644 --- a/src/OpenApiXmlCommentGenerator/gen/Helpers/INamedTypeSymbolExtensions.cs +++ b/src/OpenApiXmlCommentGenerator/gen/Helpers/INamedTypeSymbolExtensions.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using Microsoft.CodeAnalysis; public static class INamedTypeSymbolExtensions @@ -16,4 +17,26 @@ public static bool IsAccessibleOutsideOfAssembly(this ISymbol symbol) => Accessibility.Public => true, _ => true, //Here should be some reasonable default }; + + /// + /// Converts a type symbol to its normalized display string representation. For generic types, this returns the + /// unbounded generic form (e.g., "IMarker` `" instead of "IMarker`T`"). For non-generic types, returns the + /// standard display string. + /// + /// The type symbol to convert + /// Optional display format settings + /// A normalized string representation of the type + public static string ToNormalizedDisplayString(this INamedTypeSymbol symbol, SymbolDisplayFormat? format = null) + { + if (symbol == null) + throw new ArgumentNullException(nameof(symbol)); + + if (symbol.IsGenericType) + { + var genericType = symbol.ConstructUnboundGenericType(); + return genericType.ToDisplayString(format); + } + + return symbol.ToDisplayString(format); + } } diff --git a/src/OpenApiXmlCommentGenerator/gen/XmlCommentGenerator.Parser.cs b/src/OpenApiXmlCommentGenerator/gen/XmlCommentGenerator.Parser.cs index e40b548a1..f97fcfb66 100644 --- a/src/OpenApiXmlCommentGenerator/gen/XmlCommentGenerator.Parser.cs +++ b/src/OpenApiXmlCommentGenerator/gen/XmlCommentGenerator.Parser.cs @@ -30,7 +30,7 @@ public sealed partial class XmlCommentGenerator cancellationToken: cancellationToken); if (!string.IsNullOrEmpty(comment) && !string.Equals("", comment, StringComparison.Ordinal)) { - var typeInfo = type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); + var typeInfo = type.ToNormalizedDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); var typeComment = XmlComment.Parse(comment, new()); comments.Add((typeInfo, null, typeComment)); } @@ -46,7 +46,7 @@ public sealed partial class XmlCommentGenerator cancellationToken: cancellationToken); if (!string.IsNullOrEmpty(comment) && !string.Equals("", comment, StringComparison.Ordinal)) { - var typeInfo = property.ContainingType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); + var typeInfo = property.ContainingType.ToNormalizedDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); var propertyInfo = property.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); var propertyComment = XmlComment.Parse(comment, new()); if (propertyComment is not null) @@ -72,7 +72,7 @@ public sealed partial class XmlCommentGenerator { continue; } - var typeInfo = method.ContainingType.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); + var typeInfo = method.ContainingType.ToNormalizedDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); var methodInfo = method.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat); comments.Add((typeInfo, methodInfo, XmlComment.Parse(comment, new()))); }