Web API Help page showing two versions of every method

你离开我真会死。 提交于 2019-12-22 10:44:11

问题


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.


回答1:


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.




回答2:


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);
        }


来源:https://stackoverflow.com/questions/13394993/web-api-help-page-showing-two-versions-of-every-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!