MapHttpRoute and Swagger

2019-07-29 09:19发布

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.

enter image description here

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

0条回答
登录 后发表回答