【发布时间】:2020-10-01 05:45:56
【问题描述】:
在 Asp.Net Core v3.1 api、Swagger v3.0 中,当我声明多个版本时,Swagger UI 无法加载 API 定义。
编辑:同样来自 NuGet:
Mcrosoft.AspNetCore.Mvc.Versioning v4.1.1
NSwag.AspNetCore v13.7.0
Following the documentation of NSwag 我意识到我必须在我的 '''Startup.ConfigureServices()''' 中添加以下内容:
services.AddApiVersioning(options =>
{
options.AssumeDefaultVersionWhenUnspecified = true;
options.ApiVersionReader = new UrlSegmentApiVersionReader();
})
.AddMvcCore()
.AddVersionedApiExplorer(options =>
{
options.GroupNameFormat = "VVV";
options.SubstituteApiVersionInUrl = true;
});
但是 '''AddVersionedApiExplore()''' 在那里不可用...然后我发现 this ApiExplorerOptions wiki 它声明(我理解)自 Asp.Net Core 3.0 以来它的用法是:
services.AddVersionedApiExplorer( options => { /* configure options */ } );
但我最终得到错误'IServiceCollection' 不包含'AddVersionedApiExplorer' 的定义
顺便说一句,每个版本的 Postman 服务的所有路径都运行良好,swagger 的页面加载并显示了我声明的两个版本,但它无法加载它们的定义。
有人可以指点我正确的方向吗?
【问题讨论】:
标签: c# asp.net-core swagger nswag