I'm trying to auto generate the help docs for my Web Api.
However I see on one particular method a sample request could not be generated, as shown in the picture:
Below are the arguments request parameters:
Why is it unable to generate a sample request format?
I have found that actions returning an IHttpActionResult
had a missing sample. In order to get samples generated for these methods I had to decorate the action with a ResponseTypeAttribute
, for example:
[ResponseType(typeof(Model))]
public async Task<IHttpActionResult> Get(int key)
{
var entity = await dbContext.Models.FindAsync(key);
if (entity == null)
{
return NotFound();
}
return Ok(entity);
}
Make sure any objects you create have an empty constructor. Objects without an empty constructor cannot be 'automatically' created by the Web API Help Page. If creating an empty constructor is not an option, you could 'manually' create them using the config.SetSampleObjects
For anyone that is curious about which one of these answers between @chris and @wade-wright is correct.
The answer is BOTH. Both are required. So for example if you're doing a VM to consolidate content returned by your API to the necessary data you'd be looking at doing something like:
[ResponseType(typeof(YourVM))]
over top of your controller action
and an empty constructor in your VM:
public class YourVM
{
public YourVM() { }
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With