I'm busy creating a Web API (Inside a asp mvc4 application). I am using the library suggested on the asp.net site for generating documentation (http://www.asp.net/web-api/overview/creating-web-apis/creating-api-help-pages).
My problem is that if my parameter is a model, then I can't specify what properties the model contains in the generated help pages.
Here is an example:
MODEL:
public class TestModel
{
property String FirstName {get;set;}
property String Surname {get; set;}
property Boolean Active {get;set;}
}
ACTION:
/// <summary>
/// This is a test action
/// </summary>
/// <param name="model">this is the model</param> <-- this works
/// <param name="FirstName">This is the first name </param> <-- doesn't work
/// <param name ="model.Surname">This is the surname</param> <-- doesn't work
public HttpResponseMessage Post(my.namespace.models.TestModel model)
{
...
}
Only the parameter for model gets generated.
I took a look at the xml document that gets generated for the documentation and it does add the other parameters.
<member name="my.namespace.api.Post(my.namespace.models.TestModel)">
<summary>
this is a test action
</summary>
<param name="model>this is the model</param>
<param name="FirstName">This is the first name </param>
<param name="model.Surname">This is the surname</param>
</member>
But on the help pages it only generates the parameter model.
I have traced it down to the method where it gets the parameters from the xml.
Collection<ApiDescription> apiDescriptions = config.Services.GetApiExplorer().ApiDescriptions;
This is located in the HelpPageConfigurationExtentions.cs which is auto generated.
Am i approaching this the wrong way? Does anyone know of a work around?
Any suggestions or solutions will be appreciated.
josant's answer works great. I did find it was a bit-over zealous however. I found it was reporting simple things like strings as models and reporting them to be a Char array with a length field!
We only needed this for models, so I added this code to the end of the GetModelDocumentation method:
Now it only returns parameter details for non-simple types.
The MVC Web API documentation feature walks through your API classes and methods using reflection. This will build the structure of the documentation but will result in more or less empty (and useless) documentation unless you have added documentation comments.
The body of the documentation is filled using the XML file that is generated using /// documentation comments which has a specific structure that must be followed. That means that you can't fill your xml with whatever you want it to display, it actually has to be connected to something that is in your API and must follow the structure of your classes and properties.
So in your case you can't put model property documentation in an api method. You have to put it into the Model where the property exists.
MODEL:
ACTION:
Modify Help Pages
The default Help pages that are automatically generated do not include Model documentation only the api methods are documented. In order to display more information about the parameters in your api a customisation is required. The instruction that follow are one way to add parameter documentation.
Create two new types in Areas/HelpPage/Models
Add a new property to HelpPageApiModel.cs
Create a new interface
Modify XmlDocumentationProvider to implement the new interface
Add code to HelpPageConfigurationExtension in GenerateApiModel method
Modify HelpPageApiModel.cshtml adding to following where you want the Model documentation to be displayed.
Add a Models.cshtml to DisplayTemplates