Web API Help page showing two versions of every method
Asked Answered
B

2

3

How can I avoid the Help page showing both versions of my method?

As you can see, I've set up a custom route for /api/property/search/{finnId}, but I don't want the one using query parameters to show up in the Help page. Any way to get around this? I'm using the built in Help page from the ASP.NET Fall 2012 BUILD preview.

Btw, don't worry about the fact that it says POST, I've since switched it to GET, but I get the same results.

Baronetage answered 15/11, 2012 at 9:53 Comment(2)
Have you removed or otherwise overridden the default routes provided by the framework?Almonry
I think you are going to have to remove the default 'catch-all' route of api/v1/{controller}/{id} and then setup custom/explicit routes for all of your controllers.Czardas
A
4

If you're simply looking to hide this route in the Help page and not actually disable it in the app, you could always tweak the logic in the display template.

You could modify the "...\DisplayTemplates\ApiGroup.cshtml" file by adding logic to look at each api that's going to be rendered and decide whether or not you want to include it based on the presence of a query string in the URL.

Still, the important thing to note is that this does not disable the route. You're just hiding it on this Help page. If you want to disable the route, I think you'll need to define your own custom routes.

Abbreviation answered 15/11, 2012 at 23:30 Comment(1)
Works like a charm. I went for a mix of not showing methods with query parameters, and changing the routes a bit to reflect the controllers better. Thanks.Baronetage
D
0

As there are different combinations of route request for Api, help page by default shows all combination.If we just want to hide the display on the UI, we could remove the items from collection in HelpController.cs

//helpcontroller.cs 
        public ActionResult Index()
        {
            ViewBag.DocumentationProvider = Configuration.Services.GetDocumentationProvider();
            //return View(Configuration.Services.GetApiExplorer().ApiDescriptions); 
            var apiExplorer = Configuration.Services.GetApiExplorer();
            for (int i = apiExplorer.ApiDescriptions.Count - 1; i >= 0; i--)
            {
                if (apiExplorer.ApiDescriptions[i].RelativePath.Contains("?")) { apiExplorer.ApiDescriptions.RemoveAt(i); }
            }
            return View(apiExplorer.ApiDescriptions);
        }
Dosia answered 12/5, 2015 at 2:42 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.