From f207440ae6fc86367bb3685e48ec5b03d769b2d0 Mon Sep 17 00:00:00 2001 From: triggermeelmo Date: Fri, 10 Oct 2025 18:00:41 +0200 Subject: [PATCH] added swagger for automatic API Documentation --- Watcher/Program.cs | 15 +++++++++++++++ Watcher/Watcher.csproj | 1 + 2 files changed, 16 insertions(+) diff --git a/Watcher/Program.cs b/Watcher/Program.cs index b41a2de..9522004 100644 --- a/Watcher/Program.cs +++ b/Watcher/Program.cs @@ -1,5 +1,6 @@ using Microsoft.AspNetCore.Authentication.OpenIdConnect; using Microsoft.EntityFrameworkCore; +using Microsoft.OpenApi.Models; using Serilog; @@ -42,6 +43,11 @@ builder.Services.AddSingleton(); builder.Services.AddHostedService(); builder.Services.AddHostedService(); +// Swagger API-Dokumentation +builder.Services.AddSwaggerGen(options => +{ + options.SwaggerDoc("v1", new OpenApiInfo { Title = "Watcher-Server API", Version = "v1" }); +}); // ---------- Konfiguration ---------- DotNetEnv.Env.Load(); @@ -213,6 +219,8 @@ if (!app.Environment.IsDevelopment()) app.UseHttpsRedirection(); app.UseRouting(); +app.UseSwagger(); + app.UseAuthentication(); app.UseAuthorization(); @@ -223,4 +231,11 @@ app.MapControllerRoute( pattern: "{controller=Home}/{action=Index}/{id?}" ); +app.MapSwagger(); + +app.UseSwaggerUI(options => +{ + options.SwaggerEndpoint("v1/swagger.json", "Watcher-Server API v1"); +}); + app.Run(); \ No newline at end of file diff --git a/Watcher/Watcher.csproj b/Watcher/Watcher.csproj index 7eb3182..4ec814e 100644 --- a/Watcher/Watcher.csproj +++ b/Watcher/Watcher.csproj @@ -23,6 +23,7 @@ +