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 240da0fc4e..fe592d6b45 100644 --- a/framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerGenOptionsExtensions.cs +++ b/framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerGenOptionsExtensions.cs @@ -1,4 +1,6 @@ -using Swashbuckle.AspNetCore.SwaggerGen; +using System; +using System.Linq; +using Swashbuckle.AspNetCore.SwaggerGen; using Volo.Abp.Swashbuckle; namespace Microsoft.Extensions.DependencyInjection; @@ -14,4 +16,22 @@ public static class AbpSwaggerGenOptionsExtensions { swaggerGenOptions.SchemaFilter(); } -} \ No newline at end of file + + public static void CustomAbpSchemaIds(this SwaggerGenOptions options) + { + string SchemaIdSelector(Type modelType) + { + if (!modelType.IsConstructedGenericType) + { + return modelType.FullName!.Replace("[]", "Array"); + } + + var prefix = modelType.GetGenericArguments() + .Select(SchemaIdSelector) + .Aggregate((previous, current) => previous + current); + return modelType.FullName!.Split('`').First() + "Of" + prefix; + } + + options.CustomSchemaIds(SchemaIdSelector); + } +}