Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm trying to create documentation for my API's. So far I've tried with Swagger.Net and Web API help pages

Both tools provided me with correct documentation which is generated from XML but both of them showed me duplicate entries. I'm supposing that's related how my routes are configured:

            config.Routes.MapHttpRoute(
           name: "Sample1",
           routeTemplate: "sample1/{controller}/{id}",
           defaults: new { id = RouteParameter.Optional }
       );
        config.Routes.MapHttpRoute(
           name: "Sample2",
           routeTemplate: "sample2/{controller}/{id}",
           defaults: new { id = RouteParameter.Optional }
       );

What I see in view is methods both from Sample1 and Sample2, something like this:

../sample1/method1
../sample1/method2

../sample2/method1
../sample2/method2

And I want this:

../sample1/method1

../sample2/method2

Any ideas?

share|improve this question
    
I am a bit confused by your post. Can you give more details as to why do you have 2 routes here which look similar? like what is your scenario? also when you say /sample1/method1, is sample1 a controller or is method1 a controller...in any case, the way HelpPage works is that it iterates through each route in the route collection and gets all the controllers and actions which can be reached from that route.... –  Kiran Challa Jun 11 '13 at 20:26
    
oh sorry, didn't explained very well. sample1 and sample2 are sub-folders under Controllers, so therefore I've configured two routes. I'm guessing because of that, HelpPage iterates twice through all api controllers. So question would be how to distinct controllers inside those sub folder and not to display duplicate methods? –  jasenkoh Jun 11 '13 at 20:39

1 Answer 1

up vote 2 down vote accepted

Based on your last comment, you could do this by setting route constraints and expect HelpPage to show up correctly. Example below:

config.Routes.MapHttpRoute(
            name: "AdminRoute",
            routeTemplate: "api/folder1/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional },
            constraints: new { controller = "Roles|Users" }
        );

        config.Routes.MapHttpRoute(
            name: "RegularRoute",
            routeTemplate: "api/folder2/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional },
            constraints: new { controller = "Products|Reviews" }
        );

NOTE: if you try to make folder to be route variable, then HelpPage will not be able to show up the help documentation.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.