Web Api Help Page - all <see cref="MyClass"/> are missing
Asked Answered
M

1

7

In my source code documentation I often use:

Get a <see cref="Quote"/> for the specified <see cref="apiOrder"/> object.

And this translates nicely into the below string in the XmlDocument.xml, which contains the compiled web api help pages.

Get a <see cref="T:Supertext.API.POCO.Quote"/> for the specified <see cref="!:apiOrder"/> object.

But for some reasons, all these references are not being displayed. What we get is this:

Get a  for the specified  object

We found a few sources, but nothing seems to work. Does not help:
Web Api Help Page- don't escape html in xml documentation

Outdated:
http://thesoftwaredudeblog.wordpress.com/2014/01/04/using-microsoft-asp-net-web-api-2-help-page-part-2/

Any ideas?

Meliamelic answered 17/6, 2014 at 16:32 Comment(0)
Y
4

In the WebAPI 2 Help, there is a class called, XmlDocumentationProvider. In this class there is a method named, GetTagValue which handles the Summary and Returns tags. There is also a method named GetDocumentation (there are multiples, but it is the one with the HttpParameterDescriptor parameter) which handles the Param tags.

I wrote a function that uses a RegEx to find all "See Cref"s and replace them with the last object name found.

The RegEx:

private static Regex SeeCodeReferenceRegEx = new Regex("<see cref=\\\"\\w:([\\w]+\\.)*(\\w+)\\\" */>", RegexOptions.Compiled);

The function:

private static string CleanValue(string value)
{
    value = value.Trim();
    var matches = SeeCodeReferenceRegEx.Matches(value);
    foreach (Match match in matches)
        value = value.Replace(match.Groups[0].Value, match.Groups[2].Value);
    return value;
}

In GetTagValue, replace:

return node.Value.Trim();

with:

return CleanValue(node.InnerXml);

In GetDocumentation replace:

return parameterNode.Value.Trim();

with:

return CleanValue(parameterNode.InnerXml);
Yellow answered 12/5, 2016 at 20:57 Comment(1)
This solution however does not show the reference as link. Instead it displays as plain text, which defeats the whole purpose of adding a reference in the XML documentation. But yes, at least a text, rather than ignoring the whole C ref tag.Lallans

© 2022 - 2024 — McMap. All rights reserved.