c# - 为什么 Swagger/Swashbuckle 会破坏我的路线?
问题描述
我有一个控制器,上面有以下方法:
[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}")]
推荐阅读
- mysql - mysql update left join time out - 有没有更好的解决方案
- r - 合并具有相同名称的行并对其他列行中的其他值求和
- fortran - 如何使用 ISO C BINDINGS 将结构数组转换为派生类型数组?
- python - 使用 input() 函数通过 python 脚本在 Power BI 中弹出
- r - 在条形图中向第三个变量添加另一个标签(ggplot2)
- unity3d - 如何生成一个随机数并确保在 Unity 中使用 Photon 的每个人都相同?
- mysql - sql中join语句如何执行
- android - Facebook 与来自 android 应用的元数据共享链接
- django - 从列表中向下移动后,Django url 无法工作
- c - 这个函数如何将我输入的单词数作为 argc 的参数?当你有一个未声明的 int 参数时总是这样吗?