直接上代码 多余的不说
首先创建 DocumentFilter
////// 向Swagger添加枚举值说明 /// public class EnumDocumentFilter : IDocumentFilter { ////// /// /// /// /// public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer) { // 向结果模型添加枚举描述 foreach (var schemaDictionaryItem in swaggerDoc.definitions) { var schema = schemaDictionaryItem.Value; foreach (var propertyDictionaryItem in schema.properties) { var property = propertyDictionaryItem.Value; var propertyEnums = property.@enum; if (propertyEnums != null && propertyEnums.Count > 0) { property.description += DescribeEnum(propertyEnums); } } } } ////// 描述枚举 /// /// ///private static string DescribeEnum(IEnumerable
然后 在 SwaggerConfig.cs 中 添加 文档筛选器
c.DocumentFilter();
如下图
最后运行结果如下:
枚举类型已经显示出来
教程完毕!



