Quantcast
Channel: ASPNETWebStack Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 7215

Edited Issue: ApiExplorer - Document not generated when routeTemplate not includes optional parameter [730]

$
0
0
So I have Web Application project (not MVC), in Global.asax.cs we didn't do RouteTable.Routes.MapHttpRoute to maps all controller.
For example, we are not using this:
i.e)
RouteTable.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);

Instead, we map each method from each controller directly our self using RouteTable.Routes.MapHttpRoute.

We have following method in controller:

[HttpGet]
[ActionName("GetItemById")]
public string Get(int? id = null, int? id2 = null)
{
return "value";
}

If we use routeTemplate: "api/{controller}/{id}", this method will generate the documentation:

GET api/Items/{id}?id2={id2}

But if we define our routing on this method not using routeTemplate: "api/{controller}/{id}":

RouteTable.Routes.MapHttpRoute(name: "ItemApiById", routeTemplate: "api/Items/", defaults: new { controller = "Items", action = "GetItemById", id = RouteParameter.Optional, id2 = RouteParameter.Optional });

The documentation for this method will not be generated, because in routeTemplat doesn't contains any of the optional parameter.

But once we define:

RouteTable.Routes.MapHttpRoute(name: "ItemApiById", routeTemplate: "api/Items/{id}/{id2}", defaults: new { controller = "Items", action = "GetItemById", id = RouteParameter.Optional, id2 = RouteParameter.Optional });

The documentation will be generated.

Viewing all articles
Browse latest Browse all 7215

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>