From db8ed2a868457a1d7ad2022900061f6da5d9960b Mon Sep 17 00:00:00 2001
From: Jonas <77726472+kobolol@users.noreply.github.com>
Date: Sat, 18 Apr 2026 15:28:24 +0200
Subject: [PATCH] Add Swagger/OpenAPI support (development only)
Add Swashbuckle.AspNetCore (v6.6.2) to API project and register Swagger services (AddEndpointsApiExplorer, AddSwaggerGen). Enable UseSwagger/UseSwaggerUI only in Development to expose /swagger for API exploration without affecting production behavior. Update codexInfo.md to document the dev-only Swagger endpoint.
---
API/API.csproj | 4 ++++
API/Program.cs | 8 ++++++++
codexInfo.md | 2 ++
3 files changed, 14 insertions(+)
diff --git a/API/API.csproj b/API/API.csproj
index a3a34b6..58e40dc 100644
--- a/API/API.csproj
+++ b/API/API.csproj
@@ -6,4 +6,8 @@
enable
+
+
+
+
diff --git a/API/Program.cs b/API/Program.cs
index c6e5257..0028f4f 100644
--- a/API/Program.cs
+++ b/API/Program.cs
@@ -1,11 +1,19 @@
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
+builder.Services.AddEndpointsApiExplorer();
+builder.Services.AddSwaggerGen();
var app = builder.Build();
var webRootPath = app.Environment.WebRootPath ?? Path.Combine(app.Environment.ContentRootPath, "wwwroot");
var indexFilePath = Path.Combine(webRootPath, "index.html");
+if (app.Environment.IsDevelopment())
+{
+ app.UseSwagger();
+ app.UseSwaggerUI();
+}
+
app.UseDefaultFiles();
app.UseStaticFiles();
diff --git a/codexInfo.md b/codexInfo.md
index 91d3444..162f83f 100644
--- a/codexInfo.md
+++ b/codexInfo.md
@@ -88,6 +88,7 @@ Ich baue alleine neben meiner Ausbildung eine einfache self-hosted Web-App für
- Mobile-Touch-Optimierung ist für alle aktuellen öffentlichen Oberflächen aktiv (Shell, Home, Login, Impressum, 404), inklusive Safe-Area-Unterstützung.
- Desktop-Ansicht bleibt unverändert, da alle neuen Anpassungen ausschließlich in mobilen Breakpoints (`<= 960px`, Feinschliff `<= 600px`) umgesetzt sind.
- Backend-API ist auf ein Minimal-Setup reduziert und stellt aktuell den Test-Endpunkt `GET /api/health` bereit.
+- Swagger/OpenAPI ist im Backend nur im Development-Modus aktiv (`/swagger`).
- Frontend-Build (`npm run build` im `GUI`-Projekt) schreibt direkt nach `API/wwwroot`; das Backend liefert die SPA und statische Assets aus.
## Änderungen durch Codex
@@ -109,3 +110,4 @@ Ich baue alleine neben meiner Ausbildung eine einfache self-hosted Web-App für
- `GUI/vite.config.ts` Build-Ausgabe auf `API/wwwroot` umgestellt (`outDir`) und Bereinigung des Zielordners beim Build aktiviert (`emptyOutDir: true`).
- `API/Program.cs` erweitert, damit statische Dateien aus `wwwroot` inkl. SPA-Fallback (`index.html`) ausgeliefert werden.
- SPA-Fallback im Backend aufgeteilt: Frontend-Routen liefern `index.html`, unbekannte `/api/*`-Routen bleiben korrekt `404` statt auf die SPA zu fallen.
+- Swagger im Backend ergänzt: `Swashbuckle.AspNetCore` eingebunden, Services registriert und UI nur in `Development` aktiviert.