为什么 Swagger/Swashbuckle 会破坏我的路线?

Why is Swagger/Swashbuckle mangling my routes?

我有一个带有以下方法的控制器:

[System.Web.Mvc.HttpGet]
[System.Web.Mvc.Route("api/v1.0/foo/{id}")]
[ResponseType(typeof(MyObject))]
public IHttpActionResult Get(int id)

[System.Web.Mvc.HttpGet]
[System.Web.Mvc.Route("api/v1.0/foo/{id}/address")]
[ResponseType(typeof(MyObject))]
public IHttpActionResult Get(int id)

如果我删除第二种方法,控制器在 Swagger 中呈现得很好。但是,如果我包含它,路由将呈现如下:

GET /api/Foo
GET /api/Foo/{id}

这是怎么回事,我该如何解决?

原来是我使用的属性造成的。 (复制粘贴又来了。)

这些正确:

[System.Web.Mvc.HttpGet]
[System.Web.Mvc.Route("api/v1.0/foo/{id}")]

相反,这些正确的:

[System.Web.Http.HttpGet]
[System.Web.Http.Route("api/v1.0/foo/{id}")]