Browse Source

Merge pull request #19669 from abpframework/CustomAbpSchemaIds

Add `CustomAbpSchemaIds` extension method.
pull/19703/head
Engincan VESKE 2 years ago
committed by GitHub
parent
commit
a367c7a3a3
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 24
      framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerGenOptionsExtensions.cs

24
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; using Volo.Abp.Swashbuckle;
namespace Microsoft.Extensions.DependencyInjection; namespace Microsoft.Extensions.DependencyInjection;
@ -14,4 +16,22 @@ public static class AbpSwaggerGenOptionsExtensions
{ {
swaggerGenOptions.SchemaFilter<AbpSwashbuckleEnumSchemaFilter>(); swaggerGenOptions.SchemaFilter<AbpSwashbuckleEnumSchemaFilter>();
} }
}
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);
}
}

Loading…
Cancel
Save