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. <br />For example, we are not using this:<br />i.e)<br /> RouteTable.Routes.MapHttpRoute(<br /> name: "DefaultApi",<br /> routeTemplate: "api/{controller}/{id}",<br /> defaults: new { id = RouteParameter.Optional }<br /> );<br /><br />Instead, we map each method from each controller directly our self using RouteTable.Routes.MapHttpRoute.<br /><br />We have following method in controller:<br /><br /> [HttpGet]<br /> [ActionName("GetItemById")]<br /> public string Get(int? id = null, int? id2 = null)<br /> {<br /> return "value";<br /> }<br /><br />If we use routeTemplate: "api/{controller}/{id}", this method will generate the documentation: <br /><br />GET api/Items/{id}?id2={id2}<br /><br />But if we define our routing on this method not using routeTemplate: "api/{controller}/{id}":<br /><br />RouteTable.Routes.MapHttpRoute(name: "ItemApiById", routeTemplate: "api/Items/", defaults: new { controller = "Items", action = "GetItemById", id = RouteParameter.Optional, id2 = RouteParameter.Optional });<br /><br />The documentation for this method will not be generated, because in routeTemplat doesn't contains any of the optional parameter.<br /><br />But once we define:<br /><br />RouteTable.Routes.MapHttpRoute(name: "ItemApiById", routeTemplate: "api/Items/{id}/{id2}", defaults: new { controller = "Items", action = "GetItemById", id = RouteParameter.Optional, id2 = RouteParameter.Optional });<br /><br />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>