From 802624e7eab5a3703bcdfb26a7ba45ffd315f792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8E=E9=B9=8F?= <1069269649@qq.com> Date: Sun, 26 Oct 2025 22:13:17 +0800 Subject: [PATCH] =?UTF-8?q?upd:=20=E7=BD=91=E5=85=B3swagger?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Extensions/YarpSwaggerUIBuilderExtensions.cs | 4 +++- gateways/KonSoft.InternalGateway/Program.cs | 7 ++++++- gateways/KonSoft.InternalGateway/appsettings.json | 5 +++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/gateways/KonSoft.InternalGateway/Extensions/YarpSwaggerUIBuilderExtensions.cs b/gateways/KonSoft.InternalGateway/Extensions/YarpSwaggerUIBuilderExtensions.cs index 425bba7..e2a4355 100644 --- a/gateways/KonSoft.InternalGateway/Extensions/YarpSwaggerUIBuilderExtensions.cs +++ b/gateways/KonSoft.InternalGateway/Extensions/YarpSwaggerUIBuilderExtensions.cs @@ -25,6 +25,8 @@ namespace KonSoft.InternalGateway.Extensions .Select(t => t.First()) .Distinct() .ToList(); + var gatewayUrl = configuration["GatewayUrl"]; + foreach (var clusterGroup in groupedClusters) { var routeConfig = yarpConfig.Routes.FirstOrDefault(q => @@ -36,7 +38,7 @@ namespace KonSoft.InternalGateway.Extensions } // options.SwaggerEndpoint($"{clusterGroup.Value.Address}/swagger/v1/swagger.json", $"{routeConfig.RouteId} API"); - options.SwaggerEndpoint(new Uri(new Uri(clusterGroup.Value.Address), "/swagger/v1/swagger.json").AbsoluteUri, $"{routeConfig.RouteId} API"); + options.SwaggerEndpoint(new Uri(new Uri(!string.IsNullOrWhiteSpace(gatewayUrl)? gatewayUrl: clusterGroup.Value.Address), "/swagger/v1/swagger.json").AbsoluteUri, $"{routeConfig.RouteId} API"); options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]); options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]); } diff --git a/gateways/KonSoft.InternalGateway/Program.cs b/gateways/KonSoft.InternalGateway/Program.cs index b6677f5..4e8499b 100644 --- a/gateways/KonSoft.InternalGateway/Program.cs +++ b/gateways/KonSoft.InternalGateway/Program.cs @@ -2,6 +2,7 @@ using KonSoft.InternalGateway; using KonSoft.InternalGateway.Extensions; using KonSoft.Shared.Hosting.AspNetCore; using Microsoft.AspNetCore.Rewrite; +using Microsoft.Extensions.DependencyInjection; using Microsoft.OpenApi.Models; using Serilog; @@ -21,7 +22,11 @@ try .UseAutofac() .UseSerilog(); - builder.Services.AddSwaggerGen(options => + builder.Services.AddAbpSwaggerGenWithOAuth(builder.Configuration["AuthServer:Authority"]!, + new Dictionary + { + { "Clean", "Clean API" } + }, options => { options.SwaggerDoc("v1", new OpenApiInfo { diff --git a/gateways/KonSoft.InternalGateway/appsettings.json b/gateways/KonSoft.InternalGateway/appsettings.json index 8b93288..b8bf3cc 100644 --- a/gateways/KonSoft.InternalGateway/appsettings.json +++ b/gateways/KonSoft.InternalGateway/appsettings.json @@ -4,5 +4,10 @@ "name": "KonSoft.InternalGateway", "nodes": "https://config.konsoft.top/", "secret": "DBE31703-14F9-4B01-893D-900B8380CE04" + }, + "AuthServer": { + "Authority": "https://localhost:44322", + "RequireHttpsMetadata": true, + "SwaggerClientId": "Gateway_Swagger" } }