Custom ApiExplorer with Namespace based ApiControllers

api, asp.net-apicontroller, asp.net-mvc, asp.net-mvc-apiexplorer, documentation

Solution

Turned out that there is nothing to do with ApiExplorer. As instead you should modify your namespace based controller selector:

NamespaceHttpControllerSelector : DefaultHttpControllerSelector
{
//...
    public override IDictionary<string, HttpControllerDescriptor> GetControllerMapping() 
    {
        var mapping = base.GetControllerMapping();
        mapping["User"] = new HttpControllerDescriptor
        {
            Configuration = _httpConfig,
            ControllerName = "User",
            ControllerType = typeof(UserController)
        };
        //...
        return mapping;
    }
    //...  }

That is. After that default ApiExplorer will find you controllers and fetch all the actions.

Problem

I'm trying to add API documentation at my backend system. Default ApiExplorer and Help page worked absolutely great until the moment I introduced versions to my Api Controllers. In order to add versions I created sub folders under the Controllers folder: - v1 - v2 - v3 and have version based Api Controllers there. In order to have my Api discoverable I have to rewrite DefaultHttpControllerSelector to take into account namespaces provided by any client and map them to right controllers: - http://backend.com/api/v1/controller/action - http://backend.com/api/v2/controller/action This have broken my default ApiExplorer and the following property returns ZERO api descriptions ``` Configuration.Services.GetApiExplorer().ApiDescriptions ``` How can I customize existent ApiExplorer and help him to find my Api Controllers and not to rewrite whole ApiExplorer implementation. I really need just to show where to find my Api Controllers. Please advise.

Original source