added swagger for automatic API Documentation

This commit is contained in:
2025-10-10 18:00:41 +02:00
parent ef187f8750
commit f207440ae6
2 changed files with 16 additions and 0 deletions

View File

@@ -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<ISystemStore, SystemStore>();
builder.Services.AddHostedService<NetworkCheck>();
builder.Services.AddHostedService<DatabaseCheck>();
// 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();

View File

@@ -23,6 +23,7 @@
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="8.0.6" />
<PackageReference Include="Serilog.AspNetCore" Version="9.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="7.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.6" />
</ItemGroup>
</Project>