Browse Source

Updated swagger config and gateway hosting

pull/186/head
Galip Tolga Erdem 3 years ago
parent
commit
df2386e970
  1. 2
      shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbp.Shared.Hosting.AspNetCore.csproj
  2. 24
      shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerConfigurationHelper.cs
  3. 2
      shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj
  4. 31
      shared/EShopOnAbp.Shared.Hosting.Gateways/YarpSwaggerUIBuilderExtensions.cs

2
shared/EShopOnAbp.Shared.Hosting.AspNetCore/EShopOnAbp.Shared.Hosting.AspNetCore.csproj

@ -8,7 +8,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Serilog.AspNetCore" Version="5.0.0" /> <PackageReference Include="Serilog.AspNetCore" Version="5.0.0" />
<PackageReference Include="Volo.Abp.AspNetCore.Serilog" Version="7.0.0" /> <PackageReference Include="Volo.Abp.AspNetCore.Serilog" Version="7.0.0" />
<PackageReference Include="Volo.Abp.Swashbuckle" Version="7.0.0" /> <PackageReference Include="Volo.Abp.Swashbuckle" Version="7.4.0-rc.2" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

24
shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerConfigurationHelper.cs

@ -38,4 +38,28 @@ public static class SwaggerConfigurationHelper
options.CustomSchemaIds(type => type.FullName); options.CustomSchemaIds(type => type.FullName);
}); });
} }
public static void ConfigureWithOidc(
ServiceConfigurationContext context,
string authority,
string[] scopes,
string apiTitle,
string apiVersion = "v1",
string apiName = "v1",
string[]? flows = null,
string? discoveryEndpoint = null
)
{
context.Services.AddAbpSwaggerGenWithOidc(
authority: authority,
scopes: scopes,
flows: flows,
discoveryEndpoint: discoveryEndpoint,
options =>
{
options.SwaggerDoc(apiName, new OpenApiInfo { Title = apiTitle, Version = apiVersion });
options.DocInclusionPredicate((docName, description) => true);
options.CustomSchemaIds(type => type.FullName);
});
}
} }

2
shared/EShopOnAbp.Shared.Hosting.Gateways/EShopOnAbp.Shared.Hosting.Gateways.csproj

@ -5,7 +5,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Yarp.ReverseProxy" Version="1.0.0" /> <PackageReference Include="Yarp.ReverseProxy" Version="2.0.1" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

31
shared/EShopOnAbp.Shared.Hosting.Gateways/YarpSwaggerUIBuilderExtensions.cs

@ -1,5 +1,4 @@
using System.Linq; using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
@ -18,32 +17,12 @@ public static class YarpSwaggerUIBuilderExtensions
{ {
var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>(); var configuration = context.ServiceProvider.GetRequiredService<IConfiguration>();
var logger = context.ServiceProvider.GetRequiredService<ILogger<ApplicationInitializationContext>>(); var logger = context.ServiceProvider.GetRequiredService<ILogger<ApplicationInitializationContext>>();
var proxyConfigProvider = context.ServiceProvider.GetRequiredService<IProxyConfigProvider>(); var proxyConfig = context.ServiceProvider.GetRequiredService<IProxyConfigProvider>().GetConfig();
var yarpConfig = proxyConfigProvider.GetConfig();
var routedClusters = yarpConfig.Clusters foreach (var cluster in proxyConfig.Clusters)
.SelectMany(t => t.Destinations,
(clusterId, destination) => new {clusterId.ClusterId, destination.Value});
var groupedClusters = routedClusters
.GroupBy(q => q.Value.Address)
.Select(t => t.First())
.Distinct()
.ToList();
foreach (var clusterGroup in groupedClusters)
{ {
var routeConfig = yarpConfig.Routes.FirstOrDefault(q => options.SwaggerEndpoint($"/swagger-json/{cluster.ClusterId}/swagger/v1/swagger.json",
q.ClusterId == clusterGroup.ClusterId); $"{cluster.ClusterId} API");
if (routeConfig == null)
{
logger.LogWarning($"Swagger UI: Couldn't find route configuration for {clusterGroup.ClusterId}...");
continue;
}
options.SwaggerEndpoint($"{clusterGroup.Value.Address}/swagger/v1/swagger.json", $"{routeConfig.RouteId} API");
options.OAuthClientId(configuration["AuthServer:SwaggerClientId"]);
options.OAuthClientSecret(configuration["AuthServer:SwaggerClientSecret"]);
} }
}); });

Loading…
Cancel
Save