fix 聚合swagger
This commit is contained in:
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Ocelot" Version="23.1.0" />
|
<PackageReference Include="Ocelot" Version="23.1.0" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
|
||||||
|
<PackageReference Include="Swashbuckle.AspNetCore.Filters" Version="7.0.8" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,16 +1,19 @@
|
|||||||
using Ocelot.DependencyInjection;
|
|
||||||
using Ocelot.Middleware;
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
using Gateway;
|
||||||
builder.Configuration.AddJsonFile("ocelot.json", true, true);
|
|
||||||
// Add services to the container.
|
|
||||||
|
|
||||||
builder.Services.AddOcelot();
|
public class Program
|
||||||
|
{
|
||||||
var app = builder.Build();
|
public static void Main(string[] args)
|
||||||
|
{
|
||||||
// Configure the HTTP request pipeline.
|
Host.CreateDefaultBuilder(args)
|
||||||
|
.ConfigureAppConfiguration(builder =>
|
||||||
app.UseOcelot().Wait();
|
{
|
||||||
|
builder.AddJsonFile("ocelot.json", true, true);
|
||||||
app.Run();
|
})
|
||||||
|
.ConfigureWebHostDefaults(webBuilder =>
|
||||||
|
{
|
||||||
|
webBuilder.UseStartup<Startup>();
|
||||||
|
})
|
||||||
|
.Build().Run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -5,5 +5,13 @@
|
|||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*"
|
"AllowedHosts": "*",
|
||||||
|
"Services": [
|
||||||
|
"Basic",
|
||||||
|
"Common",
|
||||||
|
"Canteen",
|
||||||
|
"Scheduled",
|
||||||
|
"User",
|
||||||
|
"Sys"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,17 @@
|
|||||||
"Port": 31007
|
"Port": 31007
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"UpstreamPathTemplate": "/{url}/swagger/v1/swagger.json",
|
||||||
|
"DownstreamPathTemplate": "/{url}/swagger/v1/swagger.json",
|
||||||
|
"DownstreamScheme": "https",
|
||||||
|
"DownstreamHostAndPorts": [
|
||||||
|
{
|
||||||
|
"Host": "yikatong.isawesome.cn",
|
||||||
|
"Port": 443
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"GlobalConfiguration": {}
|
"GlobalConfiguration": {}
|
||||||
|
|||||||
Reference in New Issue
Block a user