Browse Source

Merge pull request #24800 from abpframework/auto-merge/rel-10-1/4337

Merge branch dev with rel-10.1
pull/24777/merge
Volosoft Agent 2 days ago
committed by GitHub
parent
commit
42324fed75
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 47
      framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerUIOptionsExtensions.cs
  2. 6
      framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.js
  3. 2
      framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js

47
framework/src/Volo.Abp.Swashbuckle/Microsoft/Extensions/DependencyInjection/AbpSwaggerUIOptionsExtensions.cs

@ -0,0 +1,47 @@
using System;
using System.Text;
using System.Text.Json;
using JetBrains.Annotations;
using Swashbuckle.AspNetCore.SwaggerUI;
using Volo.Abp;
namespace Microsoft.Extensions.DependencyInjection;
public static class AbpSwaggerUIOptionsExtensions
{
/// <summary>
/// Sets the abp.appPath used by the Swagger UI scripts.
/// </summary>
/// <param name="options">The Swagger UI options.</param>
/// <param name="appPath">The application base path.</param>
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);
options.HeadContent = BuildAppPathScript(normalizedAppPath, options.HeadContent ?? string.Empty);
}
private static string NormalizeAppPath(string appPath)
{
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("<script>");
builder.AppendLine(" var abp = abp || {};");
builder.AppendLine($" abp.appPath = {JsonSerializer.Serialize(normalizedAppPath)};");
builder.AppendLine("</script>");
return builder.ToString();
}
}

6
framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.js

@ -2,11 +2,7 @@ var abp = abp || {};
(function () {
/* Application paths *****************************************/
//Current application root path (including virtual directory if exists).
var baseElement = document.querySelector('base');
var baseHref = baseElement ? baseElement.getAttribute('href') : null;
abp.appPath = baseHref || abp.appPath || '/';
abp.appPath = abp.appPath || '/';
/* UTILS ***************************************************/

2
framework/src/Volo.Abp.Swashbuckle/wwwroot/swagger/ui/abp.swagger.js

@ -11,7 +11,7 @@ var abp = abp || {};
var oidcSupportedScopes = configObject.oidcSupportedScopes || [];
var oidcDiscoveryEndpoint = configObject.oidcDiscoveryEndpoint || [];
var tenantPlaceHolders = ["{{tenantId}}", "{{tenantName}}", "{0}"]
abp.appPath = configObject.baseUrl || abp.appPath;
abp.appPath = abp.appPath || "/";
var requestInterceptor = configObject.requestInterceptor;
var responseInterceptor = configObject.responseInterceptor;

Loading…
Cancel
Save