diff --git a/Webshop.Api/Program.cs b/Webshop.Api/Program.cs index 16bf36c..dd78dc1 100644 --- a/Webshop.Api/Program.cs +++ b/Webshop.Api/Program.cs @@ -126,55 +126,46 @@ builder.Services.AddEndpointsApiExplorer(); // Swagger / OpenAPI Konfiguration builder.Services.AddSwaggerGen(c => { - // --- 1. Gruppierung der Endpunkte (mit Unterpunkten) --- + // --- 1. Gruppierung der Endpunkte (visuelle Tags) --- c.TagActionsBy(api => { - // Der Name des Controllers wird als Unterpunkt verwendet (z.B. "Products", "Users") - // Wir entfernen das "Controller"-Suffix für einen sauberen Tag. var controllerName = api.ActionDescriptor.RouteValues["controller"]; - if (controllerName == null) - { - return new[] { "Default" }; - } - var tag = controllerName.Replace("Admin", "").Replace("Controller", ""); // Entfernt Präfixe/Suffixe + if (controllerName == null) return new[] { "Default" }; + + // Bereinige den Controller-Namen für einen sauberen Tag + var tag = controllerName.Replace("Admin", "").Replace("Controller", ""); + if (api.RelativePath.StartsWith("api/v1/auth")) { - // Auth hat normalerweise nur einen Controller, daher keine Untergruppe return new[] { "Auth" }; - } - // Erkenne den Hauptbereich anhand des Routen-Prä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/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 }; }); + // --- NEU: Sortierung der Gruppen in der UI --- c.OrderActionsBy(apiDesc => { var relativePath = apiDesc.RelativePath ?? ""; + // Die Reihenfolge der if-Bedingungen HIER ist entscheidend für die Sortierung! if (relativePath.StartsWith("api/v1/auth")) return "1"; // Auth ganz oben - if (relativePath.StartsWith("api/v1/admin")) return "2"; // Admin als letztes + if (relativePath.StartsWith("api/v1/public")) return "2"; // Public als nächstes if (relativePath.StartsWith("api/v1/customer")) return "3"; // Customer danach - if (relativePath.StartsWith("api/v1/public")) return "4"; // Public als nächstes - - + if (relativePath.StartsWith("api/v1/admin")) return "4"; // Admin als letztes return "5"; // Fallback });