MapHttpRoute和Swagger

时间:2018-08-16 14:53:01

标签: c# asp.net-web-api2 swagger swashbuckle

我试图通过限制可用路线来限制大张旗鼓出现的情况。这是我目前的路线:

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).)*$"
    }
);

这摆脱了一些我想删除的路线,但我还有两个要删除的路线。

enter image description here

对于上图中带有箭头的两个,它们与上面的箭头相同。我不确定为什么这里有多余的地方,但是我真的想摆脱带有箭头的地方。

让我感到困惑的是,我在Sites / {id} / Cache中没有可选的ID,所以为什么还要显示该ID。

方法如下:

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

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

0 个答案:

没有答案