ASP.Net Web API帮助页面:文档化复杂类型属性

8

我有一个接收类型为Person的FromBody参数的Post动作。在HelpPage中,我可以获取有关Person参数的信息。是否可以列出Person中的属性信息,并使用XML文档文件中的文档来获取每个属性的描述?

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; }
}

目前这个功能不支持开箱即用。有一个相关的工作项,要求为模型上使用的数据注释属性生成帮助页面。在修复此问题之后,您的情况应该可以正常工作:http://aspnetwebstack.codeplex.com/workitem/877 - Kiran
谢谢!请在此回复,我会将其标记为答案! - Peter Hedberg
你曾经尝试使用“///”注释吗?@KiranChalla链接的工作项似乎已经实现了注释支持,但截至2015年10月,文档仍未在帮助页面上显示。 - Mendhak
1个回答

6

目前这个功能不支持原生。有一个相关的工作项,要求为模型上使用的数据注释属性生成帮助页面。在其修复后,您的情况应该可以正常工作:http://aspnetwebstack.codeplex.com/workitem/877


最新版本(我正在使用ASP.NET Web API 2.2和MVC5)现在包括生成的帮助文件,显示所使用的数据注释。详情请参见http://www.strathweb.com/2014/01/return-types-action-parameters-and-data-annotations-now-available-in-web-api-2-1-help-page/。 - DigitalDan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接