diff --git a/src/Lumina.Presentation.Api/Common/Configuration/ConfigureSwaggerOptions.cs b/src/Lumina.Presentation.Api/Common/Configuration/ConfigureSwaggerOptions.cs new file mode 100644 index 00000000..dbafc65b --- /dev/null +++ b/src/Lumina.Presentation.Api/Common/Configuration/ConfigureSwaggerOptions.cs @@ -0,0 +1,69 @@ +#region ========================================================================= USING ===================================================================================== +using Microsoft.AspNetCore.Mvc.ApiExplorer; +using Microsoft.Extensions.Options; +using Microsoft.OpenApi.Models; +using Swashbuckle.AspNetCore.SwaggerGen; +#endregion + +namespace Lumina.Presentation.Api.Common.Configuration; + +/// +/// Configures the Swagger options. +/// +public class ConfigureSwaggerOptions : IConfigureNamedOptions +{ + #region ================================================================== FIELD MEMBERS ================================================================================ + private readonly IApiVersionDescriptionProvider _provider; + #endregion + + #region ====================================================================== CTOR ===================================================================================== + /// + /// Initializes a new instance of the class. + /// + /// Provider for API version descriptions. + public ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) + { + _provider = provider; + } + #endregion + + #region ===================================================================== METHODS =================================================================================== + /// + /// Configures the Swagger options. + /// + /// The options instance to configure. + public void Configure(SwaggerGenOptions options) + { + // add swagger document for every API version discovered + foreach (var description in _provider.ApiVersionDescriptions) + options.SwaggerDoc(description.GroupName,CreateVersionInfo(description)); + } + + /// + /// Configures the Swagger options. + /// + /// The name of the options instance being configured. + /// The options instance to configure. + public void Configure(string? name, SwaggerGenOptions options) + { + Configure(options); + } + + /// + /// Creates the version information for the Swagger document. + /// + /// The API version description. + /// The created instance. + private OpenApiInfo CreateVersionInfo(ApiVersionDescription description) + { + var info = new OpenApiInfo() + { + Title = "Lumina API", + Version = description.ApiVersion.ToString() + }; + if (description.IsDeprecated) + info.Description += " This API version has been deprecated."; + return info; + } + #endregion +} \ No newline at end of file