Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why aren't actions showing in WebApi Help Page

I have a WebApi project in Visual Studio 2012. I created it from the template and have since added in the HelpPage stuff through the use of NuGet. Below is my example.

HierarchyController.cs

public class HierarchyController : ApiController
{
    [ActionName("DefaultAction")]
    public List<Hierarchy> Get([FromUri]List<Guid> guid)
    {...}

    [HttpGet]
    public List<Hierarchy> Children([FromUri]List<Guid> guid)
    {...}

    [HttpGet]
    public List<Hierarchy> Descendants([FromUri]List<Guid> guid)
    {...}

    [ActionName("DefaultAction")]
    public HttpResponseMessage Post([FromBody]List<Hierarchy> hierarchies)
    {...}

    [ActionName("DefaultAction")]
    public HttpResponseMessage Delete([FromUri]List<Guid> guid)
    {...}
}

WebApiConfig.cs

public static class WebApiConfig
{
    public static void Register(HttpConfiguration config)
    {
        config.Routes.MapHttpRoute(
            name: "ActionApi",
            routeTemplate: "api/{controller}/{action}/{guid}"
        );
        config.Routes.MapHttpRoute(
            name: "GuidApi",
            routeTemplate: "api/{controller}/{guid}",
            defaults: new { action = "DefaultAction", guid = RouteParameter.Optional }
        );
    }
}

Result from .../help

Hierarchy

API--------------------------Description

GET api/Hierarchy-------Gets Hierarchy(s) by guid(s)

POST api/Hierarchy-----No documentation available.

DELETE api/Hierarchy--Deletes Hierarchy(s)

both of the "action" functions are missing from the help page. Any idea what I'm missing?

Also, everything does actually function correctly, the help page displaying everything is the only problem.

Sub Question:

Also a secondary question I have defined xml comments for each of the functions such as

/// <summary>
/// Deletes Hierarchy(s)
/// </summary>
/// <param name="guid">List of Hierarchies</param>
/// <returns>HttpResponseMessage</returns>

They were all auto generated in VS2012 by typing /// then just filling out the sections, but help page section for the Post always says "No documentation available." Is this because I haven't fixed the problem that shows up under the application/x-www-form-urlencoded tab (Cannot use formmater 'JQueryMvcFormUrlEncodedFormatter' error)?

like image 962
jp36 Avatar asked Jun 07 '13 18:06

jp36


1 Answers

Regarding the 1st question:
List<Guid> even though decorated with FromUri cannot be model bound as you might be expecting. This was a bug which was fixed recently and I think you are using the previous release bits and hence might not be able to see this. You can see what i mean by changing all the occurrences of [FromUri]List<Guid> guid with let's say string guid. You should now be seeing all the routes in help page. By the way, ApiExplorer explorers each route and for each route it explores all reachable controllers from that route. So, the results you would be seeing could be surprising, but are correct...just fyi.

Regarding 2nd question:
The documentation on actions is picked up from the documentation file that gets generated when you compile your project. You can enable it by doing: Project properties | Build | Output | check the 'Xml Documentation File'

Now uncomment the following line in the file 'Areas\HelpPage\App_Start\HelpPageConfig.cs' and set the appropriate path to the documentation file location

//// Uncomment the following to use the documentation from XML documentation
//config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/App_Data/XmlDocument.xml")));
like image 163
Kiran Avatar answered Oct 17 '22 04:10

Kiran