1

Closed

ApiExplorer not providing descriptions for route parameters not present on the action

description

For the following ValuesController and default Web API route, the help page is getting generated as expected.

public class ValuesController : ApiController
{
    // GET api/values
    public IEnumerable<string> Get()
    {
        return new string[] { "value1", "value2" };
    }

    // GET api/values/5
    public string Get(int id)
    {
        return "value";
    }

    // POST api/values
    public void Post([FromBody]string value)
    {
    }

    // PUT api/values/5
    public void Put(int id, [FromBody]string value)
    {
    }

    // DELETE api/values/5
    public void Delete(int id)
    {
    }
}
config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
However, whenever I change my route to the following, the help page does not show the ValuesController details totally.(Its actually the ApiExplorer which is not giving back the ApiDescriptions which HelpPage uses to display)

config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{version}/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );
I debugged this and noticed that this is probably due the matching check that the ApiExplorer does for each action against a route. For example, if my action was like below(‘version’ parameter), then the ApiDescription is created…but I do not want to have a version parameter in my action…

// GET api/values/5
    public string Get(int id, string version)
    {
        return "value";
    }
Expected:
Help page should be displayed...there could be any number of route parameters in a url, but for my action to be selected, only a subset of those is required, so in this case my action should still be displayed in the help page..
Closed Aug 30, 2013 at 7:23 PM by kichalla
Verified.

comments

HongmeiG wrote Mar 29, 2013 at 4:11 AM

I think we can relax the requirement here.