添加 WEB API 方法毁了我的 SWAGGER UI
Adding a WEB API method ruins my SWAGGER UI
第一种方法就可以了。但是当我添加第二种方法时,SWAGGER UI 的主体是一堆 html 乱码。我以错误的方式创建路线?
// GET api/checklist/1288
[HttpGet("{id}")]
public async Task<IActionResult> Get(int id)
{
var model = _checkListService.Get(id);
return Ok(model);
}
// http://localhost:64783/api/checklist/GetDelinquentItems?id=1288
[Route("GetDelinquentItems")]
public async Task<IActionResult> GetDelinquentItems(int id)
{
var model = _checkListService.GetDelinquentItems(id);
return Ok(model);
}
那个'html gibberish'(确实不是显示错误的最优雅的方式)仍然包含一些有用的信息。第一行说:
500 internal server error
在最后三行中,您可以阅读:
Ambiguos HTTP method for action...CheckListController.GetDelinquentItems... Actions require explicit HttpMethod binding for Swagger
因此另一个
[HttpGet("{id}")]
之前的GetDelinquentItems()
方法应该可以解决问题。
第一种方法就可以了。但是当我添加第二种方法时,SWAGGER UI 的主体是一堆 html 乱码。我以错误的方式创建路线?
// GET api/checklist/1288
[HttpGet("{id}")]
public async Task<IActionResult> Get(int id)
{
var model = _checkListService.Get(id);
return Ok(model);
}
// http://localhost:64783/api/checklist/GetDelinquentItems?id=1288
[Route("GetDelinquentItems")]
public async Task<IActionResult> GetDelinquentItems(int id)
{
var model = _checkListService.GetDelinquentItems(id);
return Ok(model);
}
那个'html gibberish'(确实不是显示错误的最优雅的方式)仍然包含一些有用的信息。第一行说:
500 internal server error
在最后三行中,您可以阅读:
Ambiguos HTTP method for action...CheckListController.GetDelinquentItems... Actions require explicit HttpMethod binding for Swagger
因此另一个
[HttpGet("{id}")]
之前的GetDelinquentItems()
方法应该可以解决问题。