41 lines
1.0 KiB
C#
41 lines
1.0 KiB
C#
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<SwaggerGenOptions>
|
|
{
|
|
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;
|
|
}
|
|
}
|