Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.Net Web API Help Pages: Document complex type properties

I have a post action receiving a FromBody-parameter of type Person. In the HelpPage I get information about the Person paramater. Is it possible to list information about the properties in Person instead and use documentation from XML documentation file to get descriptions for each property?

public class PersonController : ApiController
{
    /// <summary>
    /// Add a person
    /// </summary>
    /// <param name="person">Person to add</param>
    /// <returns></returns>
    [HttpPost]
    public HttpResponseMessage Add([FromBody] Person person)
    {
        // ...

        return Request.CreateResponse(HttpStatusCode.Created);
    }
}

/// <summary>
/// A person
/// </summary>
public class Person
{
    /// <summary>
    /// The name of the person
    /// </summary>
    public String Name { get; set; }

    /// <summary>
    /// The age of the person
    /// </summary>
    public Int32 Age { get; set; }
}
like image 680
Peter Hedberg Avatar asked Mar 28 '13 13:03

Peter Hedberg


People also ask

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

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

What is FromBody and FromUri in web API?

The [FromUri] attribute is prefixed to the parameter to specify that the value should be read from the URI of the request, and the [FromBody] attribute is used to specify that the value should be read from the body of the request.

What is the difference between controller and ControllerBase?

Controller derives from ControllerBase and adds support for views, so it's for handling web pages, not web API requests. If the same controller must support views and web APIs, derive from Controller . The following table contains examples of methods in ControllerBase . Returns 400 status code.


1 Answers

Currently this is not supported out of the box. There is a related work item which asks for help page generation for data annotation attributes used on a model. Your scenario should work afters its fixed: http://aspnetwebstack.codeplex.com/workitem/877

like image 73
Kiran Avatar answered Oct 21 '22 04:10

Kiran