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 00:14:50 +03:00
|
|
|
|
internal class SwaggerEnumSchemaFilter : ISchemaFilter
|
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)));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|