swagger .net core API ambiguous HTTP Action debugging

后端 未结 7 1895
[愿得一人]
[愿得一人] 2021-02-12 10:49

Implementing Swashbuckle/Swagger with .net Core 2 API I am now receiving the 500 error when accessing swagger.json:

NotSupportedException: Ambiguous HTTP

相关标签:
7条回答
  • 2021-02-12 11:42

    I solved this error by decorating the method mentioned in the error with the correct HTTP attribute. For exemple: [HttpGet]

    This code throws error:

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

    This code works:

    [HttpGet]
    public object Get()
    {
        MongoDbContext dbContext = new MongoDbContext();
        return new {
            API = true,
            Database = dbContext.Status()
        };
    }
    
    0 讨论(0)
提交回复
热议问题