diff --git a/framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerGenOptionsExtensions.cs b/framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerGenOptionsExtensions.cs index 4313041064..240da0fc4e 100644 --- a/framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerGenOptionsExtensions.cs +++ b/framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerGenOptionsExtensions.cs @@ -9,4 +9,9 @@ public static class AbpSwaggerGenOptionsExtensions { swaggerGenOptions.DocumentFilter(); } + + public static void UserFriendlyEnums(this SwaggerGenOptions swaggerGenOptions) + { + swaggerGenOptions.SchemaFilter(); + } } \ No newline at end of file diff --git a/framework/src/Volo.Abp.Swashbuckle/Volo/Abp/Swashbuckle/AbpSwashbuckleEnumSchemaFilter.cs b/framework/src/Volo.Abp.Swashbuckle/Volo/Abp/Swashbuckle/AbpSwashbuckleEnumSchemaFilter.cs new file mode 100644 index 0000000000..f637fb005e --- /dev/null +++ b/framework/src/Volo.Abp.Swashbuckle/Volo/Abp/Swashbuckle/AbpSwashbuckleEnumSchemaFilter.cs @@ -0,0 +1,23 @@ +using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Models; +using Swashbuckle.AspNetCore.SwaggerGen; +using System; +using System.Linq; + +namespace Volo.Abp.Swashbuckle; + +public class AbpSwashbuckleEnumSchemaFilter : ISchemaFilter +{ + public void Apply(OpenApiSchema schema, SchemaFilterContext context) + { + if (context.Type.IsEnum) + { + schema.Enum.Clear(); + schema.Type = nameof(String); + schema.Format = nameof(String); + Enum.GetNames(context.Type) + .ToList() + .ForEach(name => schema.Enum.Add(new OpenApiString($"{name}"))); + } + } +} \ No newline at end of file