MapHttpRoute and Swagger

2019-07-29 09:28发布

问题:

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)
{