问题描述
在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正常运行,大张旗鼓的页面会加载并显示我声明的两个版本,但是无法加载它们的定义。
有人可以指出我正确的方向吗?
解决方法
解决方案:AddVersionedApiExplore位于Microsoft.AspNetCore.Mvc.Versioning.ApiExplorer NuGet程序包中。