fix 聚合swagger
This commit is contained in:
41
Src/Gateway/Startup.cs
Normal file
41
Src/Gateway/Startup.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
using Microsoft.OpenApi.Models;
|
||||
using Ocelot.DependencyInjection;
|
||||
using Ocelot.Middleware;
|
||||
|
||||
namespace Gateway;
|
||||
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
public void ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
services.AddEndpointsApiExplorer();
|
||||
services.AddSwaggerGen(c =>
|
||||
{
|
||||
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Gateway API", Version = "v1", Description = "# gateway api..." });
|
||||
});
|
||||
|
||||
services.AddOcelot();
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI(c =>
|
||||
{
|
||||
var services = Configuration.GetSection("Services").Get<List<string>>();
|
||||
foreach (var s in services)
|
||||
{
|
||||
c.SwaggerEndpoint($"/{s.ToLower()}/swagger/v1/swagger.json", s);
|
||||
}
|
||||
});
|
||||
app.UseOcelot().Wait();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user