Вам необходимо установить API Explorer для Microsoft ASP.NET Core и OData v4.0 , а затем просмотреть некоторые образцы и документацию .
Фрагмент кода из документов:
public void ConfigureServices( IServiceCollection services )
{
// format the version as "'v'major[.minor][-status]"
services.AddMvc();
services.AddVersionedApiExplorer( o => o.GroupNameFormat = "'v'VVV" );
services.AddApiVersioning();
services.AddOData().EnableApiVersioning();
services.AddSwaggerGen(
options =>
{
var provider = services.BuildServiceProvider()
.GetRequiredService<IApiVersionDescriptionProvider>();
foreach ( var description in provider.ApiVersionDescriptions )
{
options.SwaggerDoc(
description.GroupName,
new Info()
{
Title = $"Sample API {description.ApiVersion}",
Version = description.ApiVersion.ToString()
} );
}
} );
}
public void Configure(
IApplicationBuilder app,
VersionedODataModelBuilder modelBuilder,
IApiVersionDescriptionProvider provider )
{
var models = modelBuilder.GetEdmModels();
app.UseMvc( routes => routes.MapVersionedODataRoutes( "odata", null, models ) );
app.UseSwagger();
app.UseSwaggerUI(
options =>
{
foreach ( var description in provider.ApiVersionDescriptions )
{
options.SwaggerEndpoint(
$"/swagger/{description.GroupName}/swagger.json",
description.GroupName.ToUpperInvariant() );
}
} );
}