1

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?

2
  • 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
    Commented Jun 11, 2013 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
    Commented Jun 11, 2013 at 20:39

1 Answer 1

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.