Skip to content

Commit 5770078

Browse files
padfoot044ardalis
authored andcommitted
Refactor SwaggerGen and MapScalarApiReference usage
1 parent 813f765 commit 5770078

File tree

1 file changed

+17
-14
lines changed

1 file changed

+17
-14
lines changed

src/Clean.Architecture.Web/Configurations/MiddlewareConfig.cs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,24 @@ public static async Task<IApplicationBuilder> UseAppMiddlewareAndSeedDatabase(th
2121

2222
app.UseFastEndpoints();
2323

24-
app.UseSwaggerGen(options =>
25-
{
26-
options.Path = "/openapi/{documentName}.json";
27-
},
28-
settings =>
29-
{
30-
settings.Path = "/swagger";
31-
settings.DocumentPath = "/openapi/{documentName}.json";
32-
});
33-
34-
app.MapScalarApiReference(options =>
24+
if (app.Environment.IsDevelopment())
3525
{
36-
options.WithTitle("Clean Architecture API");
37-
options.WithOpenApiRoutePattern("/openapi/{documentName}.json");
38-
});
26+
app.UseSwaggerGen(options =>
27+
{
28+
options.Path = "/openapi/{documentName}.json";
29+
},
30+
settings =>
31+
{
32+
settings.Path = "/swagger";
33+
settings.DocumentPath = "/openapi/{documentName}.json";
34+
});
35+
36+
app.MapScalarApiReference(options =>
37+
{
38+
options.WithTitle("Clean Architecture API");
39+
options.WithOpenApiRoutePattern("/openapi/{documentName}.json");
40+
});
41+
}
3942

4043
app.UseHttpsRedirection(); // Note this will drop Authorization headers
4144

0 commit comments

Comments
 (0)