Skip to content

Commit a23ab2e

Browse files
feat: agregar todas as APIs no Swagger do Gateway
Adiciona proxy middleware e configura SwaggerUI para exibir todas as APIs (Usuarios, Clientes, Emprestimos, Notificacoes, Reports e Gateway) em um único dropdown. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 3247575 commit a23ab2e

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

src/backend/Gateway/Program.cs

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
builder.Services.AddControllers();
2121
builder.Services.AddEndpointsApiExplorer();
2222
builder.Services.AddSwaggerGen();
23+
builder.Services.AddHttpClient();
2324

2425
// 3. CONFIGURAÇÃO JWT
2526
var jwtSettingsSection = builder.Configuration.GetSection("GatewaySettings");
@@ -78,7 +79,12 @@
7879
app.UseSwagger();
7980
app.UseSwaggerUI(c =>
8081
{
81-
c.SwaggerEndpoint("/swagger/v1/swagger.json", "PagaAi Gateway V1");
82+
c.SwaggerEndpoint("/swagger-proxy/usuarios", "Usuarios API");
83+
c.SwaggerEndpoint("/swagger-proxy/clientes", "Clientes API");
84+
c.SwaggerEndpoint("/swagger-proxy/emprestimos", "Emprestimos API");
85+
c.SwaggerEndpoint("/swagger-proxy/notificacoes", "Notificacoes API");
86+
c.SwaggerEndpoint("/swagger-proxy/reports", "Reports API");
87+
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Gateway V1");
8288
c.RoutePrefix = "swagger";
8389
});
8490

@@ -90,6 +96,30 @@
9096
app.UseAuthentication();
9197
app.UseAuthorization();
9298

99+
// Proxy para swagger.json das APIs — middleware inline antes do Ocelot
100+
var swaggerProxies = new Dictionary<string, string>
101+
{
102+
["/swagger-proxy/usuarios"] = "http://localhost:5133/swagger/v1/swagger.json",
103+
["/swagger-proxy/clientes"] = "http://localhost:5156/swagger/v1/swagger.json",
104+
["/swagger-proxy/emprestimos"] = "http://localhost:5276/swagger/v1/swagger.json",
105+
["/swagger-proxy/notificacoes"] = "http://localhost:5243/swagger/v1/swagger.json",
106+
["/swagger-proxy/reports"] = "http://localhost:5169/swagger/v1/swagger.json",
107+
};
108+
109+
app.Use(async (context, next) =>
110+
{
111+
var path = context.Request.Path.Value ?? "";
112+
if (swaggerProxies.TryGetValue(path, out var targetUrl))
113+
{
114+
var client = context.RequestServices.GetRequiredService<IHttpClientFactory>().CreateClient();
115+
var json = await client.GetStringAsync(targetUrl);
116+
context.Response.ContentType = "application/json";
117+
await context.Response.WriteAsync(json);
118+
return;
119+
}
120+
await next();
121+
});
122+
93123
// Rotas de status — antes do Ocelot
94124
app.MapGet("/", () => Results.Ok(new
95125
{

0 commit comments

Comments
 (0)