Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Web API help page - how to show generic return type in documentation

I'm using a generic return type for all my api responses:

    public HttpStatusCode statusCode { get; set; }
    public string error { get; set; }
    public IDictionary<string, string> errorfor { get; set; }
    public T result { get; set; }

and in API:

 /// <summary>
 /// GET Order API
 /// </summary>
 /// <returns> return list of orders {Order} </returns>

 public HttpResponseMessage Get(){
   var response = new BaseResponseMessage<IList<Order>>();
   //some more codes
   response.result = orders;
   return Request.CreateResponse(HttpStatusCode.OK, response);
}

Now of course my API Help page don't show Order in sample Response body. Is it possible to configure Help Page generator to show generic type? Thanks!

like image 409
Amitava Avatar asked Jun 18 '13 07:06

Amitava


People also ask

What is return type in ASP NET Core web API?

Specific Type as the Return type in ASP.NET Core Web API. We can return any type of primitive data like string, integer, Boolean, etc., or complex data like Employee, Product, etc, directly from the controller action method. Returning String from ASP.NET Core Web API Controller Action Method:

What is the actionresult<t> return type in web API controller?

The ASP.NET Core 2.1 introduced the ActionResult<T> return type for the Web API controller action methods. It enables us to return a type deriving either from ActionResult or return a specific type. Let us understand this with an example.

How can I create all of the documentation manually in web API?

You could create all of the documentation manually, but it is better to autogenerate as much as possible. To make this task easier, ASP.NET Web API provides a library for auto-generating help pages at run time. Install ASP.NET and Web Tools 2012.2 Update. This update integrates help pages into the Web API project template.

How do I create a help page in ASP NET Web API?

To make this task easier, ASP.NET Web API provides a library for auto-generating help pages at run time. Install ASP.NET and Web Tools 2012.2 Update. This update integrates help pages into the Web API project template. Next, create a new ASP.NET MVC 4 project and select the Web API project template.


1 Answers

Web API 2.1 Help Pages now do this: http://www.asp.net/web-api/overview/releases/whats-new-in-aspnet-web-api-21#help-page

You might also check out returning the standard HttpResponseMessage with the new ResponseTypeAttribute:

/// <summary>
/// GET Order API
/// </summary>
[ResponseType(typeof(List<Order>))]
public HttpResponseMessage Get()
{
    var orders = new List<Order>();
    return Request.CreateResponse(HttpStatusCode.OK, orders);
}
like image 129
user1683646 Avatar answered Nov 15 '22 08:11

user1683646