Configure ASP.NET for the API to work #7
@ -41,8 +41,33 @@ public class Program
|
||||
policy.AllowAnyOrigin();
|
||||
});
|
||||
});
|
||||
|
||||
builder.Services.AddApiVersioning(options =>
|
||||
{
|
||||
options.DefaultApiVersion = new ApiVersion(1, 0);
|
||||
options.AssumeDefaultVersionWhenUnspecified = true;
|
||||
options.ReportApiVersions = true;
|
||||
options.ApiVersionReader = new UrlSegmentApiVersionReader();
|
||||
});
|
||||
|
||||
builder.Services.AddVersionedApiExplorer(options =>
|
||||
{
|
||||
options.GroupNameFormat = "'v'VVV";
|
||||
options.SubstituteApiVersionInUrl = true;
|
||||
});
|
||||
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
|
||||
builder.Services.AddSwaggerGen(options =>
|
||||
{
|
||||
options.OperationFilter<SwaggerDefaultValues>();
|
||||
var basePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory);
|
||||
|
||||
var xmlPath = Path.Combine(basePath, "docs.xml");
|
||||
options.IncludeXmlComments(xmlPath);
|
||||
});
|
||||
|
||||
builder.Services.AddTransient<IConfigureOptions<SwaggerGenOptions>, ConfigureSwaggerOptions>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
@ -50,7 +75,17 @@ public class Program
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.UseSwaggerUI(options =>
|
||||
{
|
||||
var provider = app.Services.GetService<IApiVersionDescriptionProvider>();
|
||||
|
||||
foreach (var description in provider.ApiVersionDescriptions)
|
||||
{
|
||||
var url = $"/swagger/{description.GroupName}/swagger.json";
|
||||
var name = description.GroupName.ToUpperInvariant();
|
||||
options.SwaggerEndpoint(url, name);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
Loading…
Reference in New Issue
Block a user