Within my API I'm trying to document the different field descriptions, however none of attributes seem to work. I know this functionality is supposed to have been recently implemented within WebAPI 5.1 (running WebAPI.HelpPage 5.1.2).
ASP.Net Web API Help Pages: Document Model Data Annotations - Work Item 877
I'm trying to document both my response model:
And the individual fields/properties
I've tried a mixture of XML comments, DataMember and Display attributes but none seem to be picked up.
/// <summary>
/// blah blah blah
/// </summary>
[DataContract(Name = "Application")]
public class Application
{
/// <summary>
/// Please Display!
/// </summary>
[DataMember(Order = 0)]
[Display(Description="Please Display!")]
[StringLength(11, MinimumLength = 11)]
public string ApplicationId { get; set; }
Here is a sample from my Areas/HelpPage/App_Start/HelpPageConfig.cs
namespace WebAPI.Areas.HelpPage
{
#pragma warning disable 1591
/// <summary>
/// Use this class to customize the Help Page.
/// For example you can set a custom <see cref="System.Web.Http.Description.IDocumentationProvider"/> to supply the documentation
/// or you can provide the samples for the requests/responses.
/// </summary>
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 Dictionary<Type, object>
{
{ 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
}
Update 10/06/2014: My class definitions are stored in a separate library. I've noticed a discrepancy here. The main API and class definition library were generating separate XML files.
API Project
Definition Project
I've attempted to rectify this by making the Definition write to the same XML project. However this doesn't work, and the class definition entries aren't added.
Areas\HelpPage\HelpPageConfig.cs
looks like? – JoktanWebAPI.XML
indeed has the xml comments that you decorated the properties..we by defualt do not support the text present inDisplay
attribute... – Joktan