Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Web API Help Page documentation using Xml comments on controllers

I installed the ASP.NET Web API Help Page package and would like to use it to generate documentation for my API controller actions using the Xml comments already on them.

I came across an article on Yao's MSDN blog where he discusses how the documentation can be generated based on the XML comments.

However, in the Register method of HelpPageConfig, the SetDocumentationProvider method expects an instance of XmlDocumentationProvider constructed with a physical path to an Xml documentation file.

Is there another way to do this? I'm not clear why I need to point to an Xml documentation file.

Thanks

like image 908
George Durzi Avatar asked Feb 12 '13 22:02

George Durzi


People also ask

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

Now enable XML documentation. In Solution Explorer, right-click the project and select Properties. Select the Build page. Under Output, check XML documentation file.

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

You can enable generating this by going to your project Properties -> Build -> Output. Here select the checkbox for XML Documentation file.

Which one from the following will run on top of ASP Net Web API help pages?

NuGet packages (36) A simple Test Client built on top of ASP.NET Web API Help Page.

What is the advantage of using XML comments?

XML comments help speed development by providing IntelliSense on custom methods and other code constructs. XML comments encourage code reuse by providing a path to generate API style reference documentation from your source code.


2 Answers

If you still problem then see below steps.

Step 1 - Add comment on the controller level

// GET api/documentation /// <summary> /// This is how we create a documentation /// </summary> /// <returns></returns> public IEnumerable<string> Get() 

Step 2 - Build Property Project Properties page and set up the xml output for documentation

enter image description here

Step 3 - HelpPage Config

To set up the HelpPageConfig to use our documentation xml file, go to ~\Areas\HelpPage\HelpPageConfig.cs.

By default, the config.SetDocumentationProvider statement is commented out. Use that statement, and point the location of DocumentationProvider to our xml file:

public static void Register(HttpConfiguration config) {    // Uncomment the following to use the documentation from XML documentation file.    config.SetDocumentationProvider(             new XmlDocumentationProvider(                 HttpContext.Current.Server.MapPath("~/App_Data/Documentation.xml"))); } 

EDIT:

The location of the HelpPageConfig in a new Web API 2.2 project created in VS2013 is ~\Areas\HelpPage\App_Start\HelpPageConfig.cs

like image 94
Rikin Patel Avatar answered Sep 20 '22 18:09

Rikin Patel


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. Here select the checkbox for XML Documentation file.

like image 35
Kiran Avatar answered Sep 22 '22 18:09

Kiran