From 7dcbb0cd5a62c25479a92945541d70b4628f51d8 Mon Sep 17 00:00:00 2001 From: anurag Date: Wed, 19 Nov 2025 12:27:49 +0530 Subject: [PATCH 1/2] add swagger --- .../Configurations/MiddlewareConfig.cs | 21 ++++++++++++------- src/Clean.Architecture.Web/Program.cs | 6 ++++++ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/Clean.Architecture.Web/Configurations/MiddlewareConfig.cs b/src/Clean.Architecture.Web/Configurations/MiddlewareConfig.cs index e5e1e14a7..ce27395d9 100644 --- a/src/Clean.Architecture.Web/Configurations/MiddlewareConfig.cs +++ b/src/Clean.Architecture.Web/Configurations/MiddlewareConfig.cs @@ -21,14 +21,21 @@ public static async Task UseAppMiddlewareAndSeedDatabase(th app.UseFastEndpoints(); - if (app.Environment.IsDevelopment()) + app.UseSwaggerGen(options => { - app.UseSwaggerGen(options => - { - options.Path = "/openapi/{documentName}.json"; - }); - app.MapScalarApiReference(); - } + options.Path = "/openapi/{documentName}.json"; + }, + settings => + { + settings.Path = "/swagger"; + settings.DocumentPath = "/openapi/{documentName}.json"; + }); + + app.MapScalarApiReference(options => + { + options.WithTitle("Clean Architecture API"); + options.WithOpenApiRoutePattern("/openapi/{documentName}.json"); + }); app.UseHttpsRedirection(); // Note this will drop Authorization headers diff --git a/src/Clean.Architecture.Web/Program.cs b/src/Clean.Architecture.Web/Program.cs index 051d3f863..e45ac2437 100644 --- a/src/Clean.Architecture.Web/Program.cs +++ b/src/Clean.Architecture.Web/Program.cs @@ -16,6 +16,12 @@ builder.Services.AddFastEndpoints() .SwaggerDocument(o => { + o.DocumentSettings = s => + { + s.Title = "Clean Architecture API"; + s.Version = "v1"; + s.Description = "HTTP endpoints for the Clean Architecture sample application."; + }; o.ShortSchemaNames = true; }); From df2031661b21fad161de57b76b67583a14e503e0 Mon Sep 17 00:00:00 2001 From: Anurag Bairagi <55396959+padfoot044@users.noreply.github.com> Date: Wed, 19 Nov 2025 12:51:06 +0530 Subject: [PATCH 2/2] Refactor SwaggerGen and MapScalarApiReference usage --- .../Configurations/MiddlewareConfig.cs | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Clean.Architecture.Web/Configurations/MiddlewareConfig.cs b/src/Clean.Architecture.Web/Configurations/MiddlewareConfig.cs index ce27395d9..121324bf1 100644 --- a/src/Clean.Architecture.Web/Configurations/MiddlewareConfig.cs +++ b/src/Clean.Architecture.Web/Configurations/MiddlewareConfig.cs @@ -21,21 +21,24 @@ public static async Task UseAppMiddlewareAndSeedDatabase(th app.UseFastEndpoints(); - app.UseSwaggerGen(options => - { - options.Path = "/openapi/{documentName}.json"; - }, - settings => - { - settings.Path = "/swagger"; - settings.DocumentPath = "/openapi/{documentName}.json"; - }); - - app.MapScalarApiReference(options => + if (app.Environment.IsDevelopment()) { - options.WithTitle("Clean Architecture API"); - options.WithOpenApiRoutePattern("/openapi/{documentName}.json"); - }); + app.UseSwaggerGen(options => + { + options.Path = "/openapi/{documentName}.json"; + }, + settings => + { + settings.Path = "/swagger"; + settings.DocumentPath = "/openapi/{documentName}.json"; + }); + + app.MapScalarApiReference(options => + { + options.WithTitle("Clean Architecture API"); + options.WithOpenApiRoutePattern("/openapi/{documentName}.json"); + }); + } app.UseHttpsRedirection(); // Note this will drop Authorization headers