aufräumen
This commit is contained in:
@@ -126,15 +126,46 @@ builder.Services.AddEndpointsApiExplorer();
|
|||||||
// Swagger / OpenAPI Konfiguration
|
// Swagger / OpenAPI Konfiguration
|
||||||
builder.Services.AddSwaggerGen(c =>
|
builder.Services.AddSwaggerGen(c =>
|
||||||
{
|
{
|
||||||
|
// --- 1. Gruppierung der Endpunkte (mit Unterpunkten) ---
|
||||||
c.TagActionsBy(api =>
|
c.TagActionsBy(api =>
|
||||||
{
|
{
|
||||||
if (api.RelativePath.StartsWith("api/v1/admin")) return new[] { "Admin" };
|
// Der Name des Controllers wird als Unterpunkt verwendet (z.B. "Products", "Users")
|
||||||
if (api.RelativePath.StartsWith("api/v1/auth")) return new[] { "Auth" };
|
// Wir entfernen das "Controller"-Suffix f<>r einen sauberen Tag.
|
||||||
if (api.RelativePath.StartsWith("api/v1/customer")) return new[] { "Customer" };
|
var controllerName = api.ActionDescriptor.RouteValues["controller"];
|
||||||
if (api.RelativePath.StartsWith("api/v1/public")) return new[] { "Public" };
|
if (controllerName == null)
|
||||||
return new[] { "Default" };
|
{
|
||||||
|
return new[] { "Default" };
|
||||||
|
}
|
||||||
|
var tag = controllerName.Replace("Admin", "").Replace("Controller", ""); // Entfernt Pr<50>fixe/Suffixe
|
||||||
|
|
||||||
|
// Erkenne den Hauptbereich anhand des Routen-Pr<50>fixes
|
||||||
|
if (api.RelativePath.StartsWith("api/v1/admin"))
|
||||||
|
{
|
||||||
|
// Erzeugt einen Tag wie "Admin - Products", "Admin - Users" etc.
|
||||||
|
return new[] { $"Admin - {tag}" };
|
||||||
|
}
|
||||||
|
if (api.RelativePath.StartsWith("api/v1/auth"))
|
||||||
|
{
|
||||||
|
// Auth hat normalerweise nur einen Controller, daher keine Untergruppe
|
||||||
|
return new[] { "Auth" };
|
||||||
|
|
||||||
|
}
|
||||||
|
if (api.RelativePath.StartsWith("api/v1/customer"))
|
||||||
|
{
|
||||||
|
// Erzeugt einen Tag wie "Customer - Profile", "Customer - Orders"
|
||||||
|
return new[] { $"Customer - {tag}" };
|
||||||
|
}
|
||||||
|
if (api.RelativePath.StartsWith("api/v1/public"))
|
||||||
|
{
|
||||||
|
// Erzeugt einen Tag wie "Public - Products", "Public - Categorys"
|
||||||
|
return new[] { $"Public - {tag}" };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback-Tag
|
||||||
|
return new[] { tag };
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// --- 2. JWT Security Konfiguration ---
|
||||||
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
|
||||||
{
|
{
|
||||||
Description = "JWT Authorization header. Example: \"Authorization: Bearer {token}\"",
|
Description = "JWT Authorization header. Example: \"Authorization: Bearer {token}\"",
|
||||||
@@ -144,6 +175,21 @@ builder.Services.AddSwaggerGen(c =>
|
|||||||
Scheme = "Bearer"
|
Scheme = "Bearer"
|
||||||
});
|
});
|
||||||
|
|
||||||
|
c.AddSecurityRequirement(new OpenApiSecurityRequirement
|
||||||
|
{
|
||||||
|
{
|
||||||
|
new OpenApiSecurityScheme
|
||||||
|
{
|
||||||
|
Reference = new OpenApiReference
|
||||||
|
{
|
||||||
|
Type = ReferenceType.SecurityScheme,
|
||||||
|
Id = "Bearer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new string[] {}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
c.OperationFilter<AuthorizeOperationFilter>();
|
c.OperationFilter<AuthorizeOperationFilter>();
|
||||||
c.OperationFilter<LoginExampleOperationFilter>();
|
c.OperationFilter<LoginExampleOperationFilter>();
|
||||||
c.OperationFilter<PaymentMethodExampleOperationFilter>();
|
c.OperationFilter<PaymentMethodExampleOperationFilter>();
|
||||||
|
|||||||
Reference in New Issue
Block a user