From 4b5c763f244dbf55cbbcadb8141481de6b3b4442 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 21 Jul 2026 15:01:38 +0200 Subject: [PATCH] refactor(swagger): Read SwaggerConfiguration from appsettings - Update AddSwaggerDocumentation to accept IConfiguration parameter - Read SwaggerSettings from configuration (Title/Version/Description) - Replace hardcoded values with dynamic settings - Add Microsoft.Extensions.Options using for IOptions support --- .../Configuration/SwaggerConfiguration.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/DocumentOperator.API/Configuration/SwaggerConfiguration.cs b/DocumentOperator.API/Configuration/SwaggerConfiguration.cs index d280ff7..dee6bfb 100644 --- a/DocumentOperator.API/Configuration/SwaggerConfiguration.cs +++ b/DocumentOperator.API/Configuration/SwaggerConfiguration.cs @@ -1,4 +1,5 @@ -using Microsoft.OpenApi.Models; +using Microsoft.Extensions.Options; +using Microsoft.OpenApi.Models; using System.Reflection; namespace DocumentOperator.API.Configuration @@ -12,16 +13,22 @@ namespace DocumentOperator.API.Configuration /// Adds Swagger documentation generation to the service collection. /// /// The service collection to add Swagger to. + /// Configuration to read SwaggerSettings from. /// The modified service collection. - public static IServiceCollection AddSwaggerDocumentation(this IServiceCollection services) + public static IServiceCollection AddSwaggerDocumentation( + this IServiceCollection services, + IConfiguration configuration) { + var swaggerSettings = configuration.GetSection(SwaggerSettings.SectionName).Get() + ?? new SwaggerSettings(); + services.AddSwaggerGen(options => { - options.SwaggerDoc("v1", new OpenApiInfo + options.SwaggerDoc(swaggerSettings.Version, new OpenApiInfo { - Title = "DD Document Operator API", - Version = "v1", - Description = "PDF Verarbeitungs-Service für Validierung, Stempel, Zertifikate, Anhänge & Zusammenführung" + Title = swaggerSettings.Title, + Version = swaggerSettings.Version, + Description = swaggerSettings.Description }); // Resolve conflicting actions: Keep first variant