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; }
}
NuGet packages (37) A simple Test Client built on top of ASP.NET Web API Help Page.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With