namespace Diligent.WebAPI.Host.Extensions { public static class SwaggerConfigurationExtension { public static void ConfigureSwagger(this WebApplicationBuilder builder) { IServiceCollection services = builder.Services; services.AddVersionedApiExplorer(setup => { setup.GroupNameFormat = "'v'VVV"; setup.SubstituteApiVersionInUrl = true; }); services.AddSwaggerGen(options => { var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"; options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename)); } ); services.ConfigureOptions(); services.AddApiVersioning(options => { options.AssumeDefaultVersionWhenUnspecified = true; options.ReportApiVersions = true; options.DefaultApiVersion = new ApiVersion(1, 0); options.ApiVersionReader = new UrlSegmentApiVersionReader(); }); } public static void ConfigureSwagger(this WebApplication app) { if (app.Environment.IsDevelopment()) { app.UseSwagger(); app.UseSwaggerUI(options => { options.SwaggerEndpoint("/swagger/v1/swagger.json", "v1"); options.SwaggerEndpoint("/swagger/v2/swagger.json", "v2"); options.RoutePrefix = string.Empty; }); } } } }