sam*_*cow 14 .net swagger swashbuckle asp.net-core
使用.net Core 2 API实现Swashbuckle/Swagger我现在在访问swagger.json时收到500错误:
NotSupportedException:用于操作的不明确的HTTP方法 - EBisAPI.Controllers._class.HandleError(EBisAPI).动作需要为Swagger提供明确的HttpMethod绑定
我已经浏览了所有控制器,并在每个控制器的所有公共方法上看到显式路由.有没有办法确定哪种方法抛出模糊的路由错误?
jps*_*jps 33
当方法在控制器中声明为public但没有REST属性时,可能会发生这种情况.将方法更改为受保护可能会解决此问题.
我之前看过这个错误,通常错误消息指向罪魁祸首:
EBisAPI.Controllers._class.HandleError
我猜你的基类HandleError是一种public方法,对吧?将其更改为protected并重试.
MiF*_*vil 17
类似于totonho 的答案, 您可以使用
[ApiExplorerSettings(IgnoreApi=true)]
Run Code Online (Sandbox Code Playgroud)
(来自https://github.com/domaindrivendev/Swashbuckle/issues/153)
Gui*_*ira 11
我通过使用正确的HTTP属性装饰错误中提到的方法来解决此错误。例如:[HttpGet]
这段代码抛出错误:
public object Get()
{
MongoDbContext dbContext = new MongoDbContext();
return new {
API = true,
Database = dbContext.Status()
};
}
Run Code Online (Sandbox Code Playgroud)
此代码有效:
[HttpGet]
public object Get()
{
MongoDbContext dbContext = new MongoDbContext();
return new {
API = true,
Database = dbContext.Status()
};
}
Run Code Online (Sandbox Code Playgroud)
正如我在“Swashbuckle 未创建 swagger.json 文件”中提到的:
[HttpGet("xxx")],[HttpPost("xxx")]或 ... 而不是[Route("xxx")]。[NoAction]Attribute装饰控制器中的公共方法。| 归档时间: |
|
| 查看次数: |
14040 次 |
| 最近记录: |