Skip to content

Commit

Permalink
Ensure UseSwaggerUI & AddSwaggerGen defaults match
Browse files Browse the repository at this point in the history
Updated the defaults for `IApplicationBuilder.UseSwaggerUI` to better match the [defaults of `IServiceCollection.AddSwaggerGen`](https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/master/src/Swashbuckle.AspNetCore.SwaggerGen/DependencyInjection/ConfigureSwaggerGeneratorOptions.cs#L51) so that the displayed document name in the Swagger UI matches the actual document name and title.

We intend to change the default webapi project template code in ASP.NET Core in .NET 6.0 to simply use the Swashbuckle defaults and this change makes the UX align more clearly.
  • Loading branch information
DamianEdwards committed Sep 21, 2021
1 parent 923c7e6 commit 51b77f1
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ public static IApplicationBuilder UseSwaggerUI(this IApplicationBuilder app, Swa
// To simplify the common case, use a default that will work with the SwaggerMiddleware defaults
if (options.ConfigObject.Urls == null)
{
options.ConfigObject.Urls = new[] { new UrlDescriptor { Name = "V1 Docs", Url = "v1/swagger.json" } };
var hostingEnv = app.ApplicationServices.GetRequiredService<IWebHostEnvironment>();

options.ConfigObject.Urls = new[] { new UrlDescriptor { Name = $"{hostingEnv.ApplicationName} v1", Url = "v1/swagger.json" } };
}

return app.UseSwaggerUI(options);
Expand Down

0 comments on commit 51b77f1

Please sign in to comment.