Skip to content

Commit cdfce1b

Browse files
authored
Add support for paramref elements in the XmlDocumentationProvider (#6855)
1 parent 0b194f9 commit cdfce1b

File tree

3 files changed

+42
-0
lines changed

3 files changed

+42
-0
lines changed

src/HotChocolate/Core/src/Types/Types/Descriptors/Conventions/XmlDocumentationProvider.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public class XmlDocumentationProvider : IDocumentationProvider
2525
private const string _cref = "cref";
2626
private const string _href = "href";
2727
private const string _code = "code";
28+
private const string _paramref = "paramref";
29+
private const string _name = "name";
2830

2931
private readonly IXmlDocumentationFileResolver _fileResolver;
3032
private readonly ObjectPool<StringBuilder> _stringBuilderPool;
@@ -164,6 +166,17 @@ private static void AppendText(
164166
continue;
165167
}
166168

169+
if (currentElement.Name == _paramref)
170+
{
171+
var nameAttribute = currentElement.Attribute(_name);
172+
173+
if (nameAttribute != null)
174+
{
175+
description.Append(nameAttribute.Value);
176+
continue;
177+
}
178+
}
179+
167180
if (currentElement.Name != _see)
168181
{
169182
description.Append(currentElement.Value);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace HotChocolate.Types.Descriptors
2+
{
3+
public class WithParamrefTagInXmlDoc
4+
{
5+
/// <summary>
6+
/// This is a parameter reference to <paramref name="id"/>.
7+
/// </summary>
8+
public int Foo(int id) => id;
9+
}
10+
}

src/HotChocolate/Core/test/Types.Tests/Types/Descriptors/Conventions/XmlDocumentationProviderTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,25 @@ public void When_description_has_see_tag_then_it_is_converted()
6262
description);
6363
}
6464

65+
[Fact]
66+
public void When_description_has_paramref_tag_then_it_is_converted()
67+
{
68+
// arrange
69+
var documentationProvider = new XmlDocumentationProvider(
70+
new XmlDocumentationFileResolver(),
71+
new NoOpStringBuilderPool());
72+
73+
// act
74+
var description = documentationProvider.GetDescription(
75+
typeof(WithParamrefTagInXmlDoc)
76+
.GetMethod(nameof(WithParamrefTagInXmlDoc.Foo))!);
77+
78+
// assert
79+
Assert.Equal(
80+
"This is a parameter reference to id.",
81+
description);
82+
}
83+
6584
[Fact]
6685
public void When_description_has_generic_tags_then_it_is_converted()
6786
{

0 commit comments

Comments
 (0)