在我的API中,我试图记录不同的字段描述,但是没有一个属性似乎有效.我知道这个功能应该是最近在WebAPI 5.1中运行的(运行WebAPI.HelpPage 5.1.2).
ASP.Net Web API帮助页面:文档模型数据注释 - 工作项877
我正在尝试记录我的响应模型:
以及各个领域/属性
我尝试过混合使用XML注释,DataMember和Display属性,但似乎没有一个被选中.
////// blah blah blah /// [DataContract(Name = "Application")] public class Application { ////// Please Display! /// [DataMember(Order = 0)] [Display(Description="Please Display!")] [StringLength(11, MinimumLength = 11)] public string ApplicationId { get; set; }
以下是我的Areas/HelpPage/App_Start/HelpPageConfig.cs中的示例
namespace WebAPI.Areas.HelpPage { #pragma warning disable 1591 ////// Use this class to customize the Help Page. /// For example you can set a custom public static class HelpPageConfig { public static void Register(HttpConfiguration config) { // remove unwanted formatters config.Formatters.Clear(); var jsonsettings = new JsonSerializerSettings() { DateParseHandling = DateParseHandling.None }; config.Formatters.Add(new JsonMediaTypeFormatter()); config.Formatters.Add(new XmlMediaTypeFormatter()); config.SetDocumentationProvider(new XmlDocumentationProvider(HttpContext.Current.Server.MapPath("~/bin/WebAPI.XML"))); // create sample objects config.SetSampleObjects(new Dictionaryto supply the documentation /// or you can provide the samples for the requests/responses. /// { { typeof(MyResponse), new MyResponse() { Message = "Key d795677d-6477-494f-80c5-874b318cc020 is not recognised", Code = ResponseCode.InvalidKey, Id = null } } }); //*** More Sample Requests *** } } #pragma warning restore 1591 }
2014年10月10日更新:我的类定义存储在一个单独的库中.我注意到这里存在差异.主API和类定义库生成单独的XML文件.
API项目
定义项目
我试图通过将Definition写入同一个XML项目来纠正这个问题.但是这不起作用,并且不添加类定义条目.