1. Edison Chuang
  2. MVC.ApiExplorer
  3. Issues
Issue #11 new

Valid routes not discovered by ApiExplorer when more than one matching rule exists

rheone
created an issue

When using ASP.NET Web API Help Page and the related MVC.ApiExplorer I have valid routes that are accessible via http yet aren't discovered by ApiExplorer. These routes are only found when a general routing rule is used. Usage of a more specific rule (in conjunction with the general one) seems to hide routes from the ApiExplorer.

In an example case of three rules two routes relate to a GET and a POST action on a controller method which take no query parameters go MIA.

public class SomeControllerController : ApiController
{
    [HttpPost] public HttpResponseMessage Post(PostObject value) { ... }
    [HttpGet] public IEnumerable<DisplayObject> GetAll() { ... }
    [HttpGet] public DisplayObject GetById(string id) { ... }
}

When using a routing rule of

routes.MapHttpRoute(
    name: "ApiDefault",
    routeTemplate: "api/{controller}/{id}",
    defaults: new
              {
                  id = RouteParameter.Optional
              }
    );

The routes are discovered appropriately by Api Explorer as

  • POST: api/SomeController
  • GET: api/SomeController
  • GET: api/SomeController/{id}

yet when adding the less generic and more meaningful rule

routes.MapHttpRoute(
    name: "ApiSomeControllerDefault",
    routeTemplate: "api/somecontroller/{id}",
    defaults: new
              {
                controller = "SomeController",
                id = RouteParameter.Optional
              }
    );

routes.MapHttpRoute(
    name: "ApiDefault",
    routeTemplate: "api/{controller}/{id}",
    defaults: new
              {
                  id = RouteParameter.Optional
              }
    );

Api Explorer only returns * GET: api/somecontroller/{id}

Similarily removing the "ApiDefault" rule and leaving the "ApiSomeControllerDefault" rule

The routes are discovered appropriately by Api Explorer as

  • POST: api/somecontroller
  • GET: api/somecontroller
  • GET: api/somecontroller/{id}

are found

Comments (4)

  1. rheone reporter

    Maybe I wan't being clear enough in my original comment or am misunderstanding your response. The issue I encountered wasn't that of only one match. The issue was that no matches were being returned. Despite having two routes that were valid for the input there was no return.

    For additional reference here is my Stackoverflow question related to this issue that I asked prior to filing the above bug report.

  2. Edison Chuang repo owner

    Thank you for reporting the issue. Just let you know, ApiExplorer has never been tested with ASP.NET MVC4 due to the MVC4 wasn't unveiled at the time.

    Anyway, I've noticed that all methods in your example code. None of them return an ActionResult. ApiExplorer tries to filter out that kind of methods. Because in MVC3 a valid "Action" should be public and returns ActionResult. However, I'll take time to investigate it.

    If it is convenient to you. May I ask you to provide complete example code which can reproduce the issue. (Just zip and attach it to the issue, thanks)

  3. rheone reporter

    Unfortunately at this time I cannot provide the original source in which I'm having issues with ApiExplorer. In the near future, assuming I get some free time, I will see if I can create a sample project which duplicates the issues that I can share.

  4. Log in to comment