Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make ASP.NET WEB API HELP PAGES Xml Documentation Comments to have new line

I have a rest api developed using ASP.NET WEB API. I used help pages nuget package in order to create documentation. One problem I encountered is the following. For my model objects, I have xml documentation comments and they become descriptions on the help pages for each member of the model. I want certain part of the description to be on a new line, but everything in the comment comes as one paragraph. I tried to add <br/> in the comments, but didn't help. Does anyone know how to achieve this?

like image 853
neo Avatar asked Aug 20 '14 14:08

neo


People also ask

What is one step you must take to enable XML comments to appear in the default Web API?

At compile time, you can generate an XML file that contains the documentation comments. To enable that option, select Generate a file containing API documentation on the Build > Output tab of your project's properties.

What is one step you must take to enable XML comments to appear?

The XmlDocumentationProvider is looking for the xml file(having your xml code comments) which gets generated when you compile your project. You can enable generating this by going to your project Properties -> Build -> Output.

What sequence of characters indicates the start of an XML style documentation comment in C# code?

The use of XML doc comments requires delimiters that indicate where a documentation comment begins and ends. You use the following delimiters with the XML documentation tags: /// Single-line delimiter: The documentation examples and C# project templates use this form.


1 Answers

A similar question has been asked here: Web Api Help Page- don't escape html in xml documentation and the accepted answer (which is given by Kiran Challa - one of the ASP.NET Web API team members) describes a work around.

I just tried it myself, and it works fine.

However, instead of adding <br/> to my code comments, I changed the proposed solution from:

return node.InnerXml;

to:

return node.InnerXml.Replace("\r\n", "<br/>").Replace("\n", "<br/>");

... and as pointed out in the comments, there might be several places where you need to add @Html.Raw(), i.e., ApiGroup.cshtml, HelpPageApiModel.cshtml, and ResourceModel.cshtml and some of the partial views as well.

To figure out which views I had to change, I basically just launched the debugger in Chrome to help me inspect the html and locate the files to be changed based on that.

like image 199
Lasse Christiansen Avatar answered Sep 21 '22 00:09

Lasse Christiansen