sunpengfei
2025-08-04 7c7d0899d5cbf2de57238d845a6a7ef07603ff77
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Models;
using Swashbuckle.AspNetCore.SwaggerGen;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
 
namespace FlexJobApi.Core
{
    public class EnumSchemaFilter : ISchemaFilter
    {
        public void Apply(OpenApiSchema schema, SchemaFilterContext context)
        {
            if (context.Type.IsEnum && context.Type.FullName.Contains("FlexJobApi."))
            {
                // 枚举类型的描述(来自枚举本身的注释)
                var model = EnumUtils.GetModel(context.Type).Result;
                var items = model.Items
                    .Select(it => $"{it.Name ?? it.Value.ToString()}-{it.Value}-{it.Description ?? "没写注释"}")
                    .SplitJoin(",");
                schema.Description = $"{model.Description ?? "没写注释"}|{items}";
            }
        }
    }
}