我有一个项目,其中包含OData Controller和Api控制器,我想在Swagger UI中显示该文档。
我使用我发现here作为主要参考的Microsoft Api版本控制示例项目。
并在我的startup.cs中实现以下配置
public void ConfigureServices( IServiceCollection services )
{
services.AddMvc();
services.AddApiVersioning( options => options.ReportApiVersions = true );
services.AddOData().EnableApiVersioning();
services.AddODataApiExplorer(
options =>
{
options.GroupNameFormat = "'v'VVV";
options.SubstituteApiVersionInUrl = true;
} );
services.AddSwaggerGen(
options =>
{
var provider = services.BuildServiceProvider().GetRequiredService<IApiVersionDescriptionProvider>();
foreach ( var description in provider.ApiVersionDescriptions )
{
options.SwaggerDoc( description.GroupName, CreateInfoForApiVersion( description ) );
}
} );
}
还有这个
public void Configure( IApplicationBuilder app, IHostingEnvironment env, VersionedODataModelBuilder modelBuilder, IApiVersionDescriptionProvider provider )
{
app.UseMvc( routeBuilder => routeBuilder.MapVersionedODataRoutes( "odata", "api", modelBuilder.GetEdmModels() ) );
app.UseSwagger();
app.UseSwaggerUI(
options =>
{
// build a swagger endpoint for each discovered API version
foreach ( var description in provider.ApiVersionDescriptions )
{
options.SwaggerEndpoint( $"/swagger/{description.GroupName}/swagger.json", description.GroupName.ToUpperInvariant() );
}
} );
}
结果是我的所有odata控制器和方法都出现在Swagger UI中,但我的API Controller却根本没有出现。
有什么想念的吗?