2021-12-06 02:49:27 +03:00
|
|
|
|
using System;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Microsoft.OpenApi.Any;
|
|
|
|
|
using Microsoft.OpenApi.Models;
|
|
|
|
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
|
|
|
|
|
|
|
|
|
namespace BlueWest.WebApi.Tools
|
|
|
|
|
{
|
2022-08-22 02:51:45 +03:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
public class SwaggerEnumSchemaFilter : ISchemaFilter
|
2021-12-06 02:49:27 +03:00
|
|
|
|
{
|
2022-08-22 02:51:45 +03:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Apply Swagger OpenApi schema
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="model">OpenApiSchema model</param>
|
|
|
|
|
/// <param name="context">Schema filter context</param>
|
2021-12-06 02:49:27 +03:00
|
|
|
|
public void Apply(OpenApiSchema model, SchemaFilterContext context)
|
|
|
|
|
{
|
|
|
|
|
if (context.Type.IsEnum)
|
|
|
|
|
{
|
|
|
|
|
model.Enum.Clear();
|
|
|
|
|
Enum.GetNames(context.Type)
|
|
|
|
|
.ToList()
|
|
|
|
|
.ForEach(n => model.Enum.Add(new OpenApiString(n)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|