I have a C# Web API and I am trying to get the auto created help documentation to work with IHttpActionResult. I stripped down the example below so its a little easier to read.
For the object, below is a simple example. BusinessObject is just a wrapper. The CollectionBase is CollectionBase : ObservableCollection<T>, ILoadable where T : BusinessObject
. Its an older code base that is auto generated but reusing it for this.
public class Value : BusinessObject
{
public int Id { get; set; }
}
public class Values : CollectionBase<Value>
{
public override Value LoadObject(System.Data.IDataRecord record)
{
return new Value();
}
}
For the API side of things. The following works.
public class Values : ApiController
{
public IEnumerable<Value> GetThis()
{
Values values = new Values();
return values;
}
}
The issue comes when I try to do
public IHttpActionResult GetThis()
{
Values values = new Values();
return Ok(values);
}
It doesn't recognize that it should use a different return type. The 'Resource Description' ends up being IHttpActionResult with no sample output. Now I can add
config.SetActualResponseType(typeof(IEnumerable<Value>), "Values", "GetThis");
and it will show a sample output but the 'Resource Description' will still be IHttpActionResult. That is the main issue I am having. I would like to use IHttpActionResult because its very easy to use and can return error codes if needed very easily. I would just like to be able to auto construct the documentation.
UPDATE: Upon some further research, I did fine this post.
Resource Description on Web API Help page is showing "None."
Bascially, you add the response type attribute to the method.
[ResponseType(typeof(IEnumerable<Value>))]
public IHttpActionResult GetThis()
{
Values values = new Values();
return Ok(values);
}
Although this technically works and I have modified my existing code to use this. It would still be nice if there was a way to have it automatically figure it out somehow. Not sure if this is possible or not.
Best Answer
This works for what I am doing. Its a little tedious to have to include every time but it allows me to return error codes if necessary and retain the help documentation functionality.
Resource Description on Web API Help page is showing "None."