diff --git a/framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerUIOptionsExtensions.cs b/framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerUIOptionsExtensions.cs index b73cf8a7d0..d307bc7e34 100644 --- a/framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerUIOptionsExtensions.cs +++ b/framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerUIOptionsExtensions.cs @@ -1,7 +1,9 @@ using System; using System.Text; using System.Text.Json; +using JetBrains.Annotations; using Swashbuckle.AspNetCore.SwaggerUI; +using Volo.Abp; namespace Microsoft.Extensions.DependencyInjection; @@ -12,19 +14,34 @@ public static class AbpSwaggerUIOptionsExtensions /// /// The Swagger UI options. /// The application base path. - public static void AbpAppPath(this SwaggerUIOptions options, string appPath) + public static void AbpAppPath([NotNull] this SwaggerUIOptions options, [NotNull] string appPath) { + Check.NotNull(options, nameof(options)); + Check.NotNull(appPath, nameof(appPath)); + var normalizedAppPath = NormalizeAppPath(appPath); - var builder = new StringBuilder(options.HeadContent ?? string.Empty); - builder.AppendLine(""); - options.HeadContent = builder.ToString(); + options.HeadContent = BuildAppPathScript(normalizedAppPath, options.HeadContent ?? string.Empty); } private static string NormalizeAppPath(string appPath) { - return string.IsNullOrWhiteSpace(appPath) ? "/" : appPath.Trim().EnsureStartsWith('/').EnsureEndsWith('/'); + return string.IsNullOrWhiteSpace(appPath) + ? "/" + : appPath.Trim().EnsureStartsWith('/').EnsureEndsWith('/'); + } + + private static string BuildAppPathScript(string normalizedAppPath, string headContent) + { + var builder = new StringBuilder(headContent); + if (builder.Length > 0) + { + builder.AppendLine(); + } + + builder.AppendLine(""); + return builder.ToString(); } }