MapHttpRoute and Swagger

久未见 提交于 2019-12-24 17:19:47

问题


I'm trying to limit what shows up on swagger by limiting the routes available. Here are my current routes:

config.Routes.MapHttpRoute(
    name: "SiteCache",
    routeTemplate: "{controller}/{id}/{action}",
    defaults: new {
        controller = "Sites",
        action ="Cache"
    },
    constraints: new {
        httpMethod = new HttpMethodConstraint(HttpMethod.Delete),
        controller = "Sites"
    }
);

config.Routes.MapHttpRoute(
    name: "SitePost",
    routeTemplate: "{controller}",
    defaults: new {
        controller = "Sites",
        action ="Post"
    },
    constraints: new
    {
        httpMethod = new HttpMethodConstraint(HttpMethod.Post),
        controller = "Sites"
    }
);

config.Routes.MapHttpRoute(
    name: "DefaultApi",
    routeTemplate: "{controller}/{id}",
    defaults: new { id = RouteParameter.Optional },
    constraints: new
    {
        controller = @"^(?:(?!Sites).)*$"
    }
);

That got rid of a couple routes I wanted to remove but I have two left that I'm trying to remove.

For the two with arrows in the image above, they are the same as the ones above them. I'm not sure why there is a redundancy here but I'd really like to get rid of the ones with the arrows.

What confuses me is I don't have the id as optional in Sites/{id}/Cache so why is that one even showing up.

The methods look like this:

[HttpDelete]
public ResponseMessage<Result> Cache([FromUri] string id)
{

[HttpPost]
public ResponseMessage<Result> Post(Site mainObj, [FromUri] string authKey)
{

来源:https://stackoverflow.com/questions/51879940/maphttproute-and-swagger

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