.NET Core Swagger Actions require a unique method/path combination for Swagger/OpenAPI 3.0. Use ConflictingActionsResolver as a workaround

遇到的问题

因为新增了一个控制器方法,从而导致在运行Swagger的时候直接报错,异常如下:

SwaggerGeneratorException: Conflicting method/path combination "POST api/UserOperationExample" for actions - WebApi.Controllers.UserOperationExampleController.GetUserInfoByPageList (WebApi),WebApi.Controllers.UserOperationExampleController.AddUserInfo (WebApi). Actions require a unique method/path combination for Swagger/OpenAPI 3.0. Use ConflictingActionsResolver as a workaround

 

解决方案

从上面报错的字面描述来看,说的就是对于Swagger/OpenAPI 3.0,Actions需要一个唯一的方法/路径组合,所以我们只需要在每个控制器的Route特性中增加完整的路由即可,如下所示:

[Route("api/[controller]/[action]")]

添加完成后重新运行成功

 

posted @ 2023-03-24 23:53  追逐时光者  阅读(2185)  评论(2编辑  收藏  举报