23 lines
594 B
C#
23 lines
594 B
C#
using System;
|
|
using System.Linq;
|
|
using Microsoft.OpenApi.Any;
|
|
using Microsoft.OpenApi.Models;
|
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
|
|
|
namespace BlueWest.WebApi.Tools
|
|
{
|
|
internal class SwaggerEnumSchemaFilter : ISchemaFilter
|
|
{
|
|
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)));
|
|
}
|
|
}
|
|
}
|
|
|
|
} |