Microsoft Web API帮助页面 - 如何为参数创建注释

时间:2014-09-29 10:47:00

标签: api web attributes documentation

最近,我开始使用最近添加到web api项目模板的新的web api帮助页面功能。我注意到一些"其他信息"列总是“没有”#。

enter image description here

在看了一些标记之后,我发现这个信息应该来自属性

 <td class="parameter-annotations">
                    @if (parameter.Annotations.Count > 0)
                    {
                        foreach (var annotation in parameter.Annotations)
                        {
                            <p>@annotation.Documentation</p>
                        }
                    }
                    else
                    {
                        <p>None.</p>
                    }
                </td>

但我应该使用什么样的属性来填充其他信息? 感谢

1 个答案:

答案 0 :(得分:12)

有关如何添加其他信息的示例,请参阅this site

它基本上是为你的模型注释,所以在你的情况下它会是这样的: -

public class Product
{
    /// <summary>
    ///  The id of the product
    /// </summary>
    [Required]
    public int Id { get; set; }

    /// <summary>
    /// The name of the product
    /// </summary>
    [MaxLength(50)]
    public string Name { get; set; }
}

这会给你一个这样的输出: -

example output