Skip to content

Commit

Permalink
Add support for paramref elements in the XmlDocumentationProvider (#6855
Browse files Browse the repository at this point in the history
)
  • Loading branch information
glen-84 authored Feb 2, 2024
1 parent 0b194f9 commit cdfce1b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ public class XmlDocumentationProvider : IDocumentationProvider
private const string _cref = "cref";
private const string _href = "href";
private const string _code = "code";
private const string _paramref = "paramref";
private const string _name = "name";

private readonly IXmlDocumentationFileResolver _fileResolver;
private readonly ObjectPool<StringBuilder> _stringBuilderPool;
Expand Down Expand Up @@ -164,6 +166,17 @@ private static void AppendText(
continue;
}

if (currentElement.Name == _paramref)
{
var nameAttribute = currentElement.Attribute(_name);

if (nameAttribute != null)
{
description.Append(nameAttribute.Value);
continue;
}
}

if (currentElement.Name != _see)
{
description.Append(currentElement.Value);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace HotChocolate.Types.Descriptors
{
public class WithParamrefTagInXmlDoc
{
/// <summary>
/// This is a parameter reference to <paramref name="id"/>.
/// </summary>
public int Foo(int id) => id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,25 @@ public void When_description_has_see_tag_then_it_is_converted()
description);
}

[Fact]
public void When_description_has_paramref_tag_then_it_is_converted()
{
// arrange
var documentationProvider = new XmlDocumentationProvider(
new XmlDocumentationFileResolver(),
new NoOpStringBuilderPool());

// act
var description = documentationProvider.GetDescription(
typeof(WithParamrefTagInXmlDoc)
.GetMethod(nameof(WithParamrefTagInXmlDoc.Foo))!);

// assert
Assert.Equal(
"This is a parameter reference to id.",
description);
}

[Fact]
public void When_description_has_generic_tags_then_it_is_converted()
{
Expand Down

0 comments on commit cdfce1b

Please sign in to comment.