using Asp.Versioning.ApiExplorer; using Microsoft.Extensions.Options; using Microsoft.OpenApi.Models; using Swashbuckle.AspNetCore.SwaggerGen; namespace OliverBooth.Api; internal sealed class ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) : IConfigureNamedOptions { public void Configure(SwaggerGenOptions options) { foreach (var description in provider.ApiVersionDescriptions) { options.SwaggerDoc(description.GroupName, CreateVersionInfo(description)); } } public void Configure(string? name, SwaggerGenOptions options) { Configure(options); } private OpenApiInfo CreateVersionInfo( ApiVersionDescription description) { var info = new OpenApiInfo { Title = "api.oliverbooth.dev", Version = description.ApiVersion.ToString() }; if (description.IsDeprecated) { info.Description += " This API version has been deprecated."; } return info; } }