Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 946
Remy Avatar asked Jun 17 '14 16:06

Remy


People also ask

How do I add a help page to an existing API?

Each API has a link to a page with more detailed information, including example request and response bodies. You can add help pages to an existing Web API project by using NuGet Package Manager. This option is useful you start from a different project template than the "Web API" template.

How to create an API help page in mvc4?

Click on New Project and select the MVC4 application. Now select the Web API application from the template. Now we see the Areas folder in Solution Explorer. The Areas folder contains the help page folder. Now we execute the application. When we execute the application we will see the API help page Link.

How do I integrate help pages into the web API project template?

This update integrates help pages into the Web API project template. Next, create a new ASP.NET MVC 4 project and select the Web API project template. The project template creates an example API controller named ValuesController. The template also creates the API help pages.

What does CREF mean in XML?

The XML file can be processed to format this word in some distinct way, such as with a bold or italic font. cref = " member ": A reference to an exception that is available from the current compilation environment.


1 Answers

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);
like image 136
phokus Avatar answered Oct 14 '22 04:10

phokus