Ambiguous HTTP method Actions require an explicit HttpMethod binding for Swagger 2.0 异常

2021-05-12 00:29

阅读:498

标签:方案   overflow   family   pos   src   exp   tps   private   alt   

 

网上看了很多关于此异常的解决方案,但是大多数都是不能用的,今天把正确的解决方案记录下来,以帮助需要的人

问题:有些接口没有设置HttpPost或HttpGet,非接口设置访问权限为private,控制台可以看到报错位置为UserController.Info

技术图片

 

 

接口错误示例:
public object Get()
{
    MongoDbContext dbContext = new MongoDbContext();
    return new {
        API = true,
        Database = dbContext.Status()
    };
}

接口正确示例:

[HttpGet]
public object Get()
{
    MongoDbContext dbContext = new MongoDbContext();
    return new {
        API = true,
        Database = dbContext.Status()
    };
}

非接口(方法)示例:(访问权限设置成private,protected)

        private DateTime SecondsToDateTime(long seconds)
        {
            var d1970 = new DateTime(1970, 1, 1);
            DateTime now = new DateTime(d1970.Ticks + seconds * 10000);
            ///零时区
            return TimeZoneInfo.ConvertTimeFromUtc(now, TimeZoneInfo.Local);
        }

参考

https://stackoverflow.com/questions/47822177/swagger-net-core-api-ambiguous-http-action-debugging

Ambiguous HTTP method Actions require an explicit HttpMethod binding for Swagger 2.0 异常

标签:方案   overflow   family   pos   src   exp   tps   private   alt   

原文地址:https://www.cnblogs.com/mlh1421/p/12013260.html


评论


亲,登录后才可以留言!