Browse Source

Add `CustomAbpSchemaIds` extension method.

Resolve #19666
pull/19669/head
maliming 2 years ago
parent
commit
b7f337f2a6
No known key found for this signature in database GPG Key ID: A646B9CB645ECEA4
  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;
namespace Microsoft.Extensions.DependencyInjection;
@ -14,4 +16,22 @@ public static class AbpSwaggerGenOptionsExtensions
{
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