Swagger 试图在导致内部服务错误的依赖项中公开 API

Swagger attempting to expose API within dependencies causing internal service error

尝试设置 swagger 时,我在导航到 'swagger/v1/swagger.json' 后得到以下 'unhandled exception':

NotSupportedException: HTTP method "POST" & path "connect/authorize" >overloaded by actions - (references to 3 API)

Actions require unique method/path combination for Swagger 2.0. Use ConflictingActionsResolver as a workaround

否则这会有所帮助,但此问题的根源在于此错误消息引用了在我的 VS 2017 项目中 NuGet 分支下的依赖项中定义的 API。他们是一种让我大摇大摆地忽略项目依赖项分支中的 API 或任何可能类似于 API 的方法吗?

解决方案:

考虑到 API 是在依赖库中定义的,许多更常见的解决方案即 [ApiExplorerSettings(IgnoreApi = true)](附加到 API 定义的标签)是不够的。

为了解决 method/path 组合在 API 超出项目范围(依赖项)时的问题,请按如下方式更改 ConfigureServices() 方法:

services.AddSwaggerGen(c =>
{
    c.SwaggerDoc("v1", new Info { Title = "API WSVAP (WebSmartView)", Version = "v1" });
    c.ResolveConflictingActions(apiDescriptions => apiDescriptions.First());
});