Skip to content

Commit

Permalink
Merge pull request #1481 from tomkerkhove/ignoreExistingOptions-for-b…
Browse files Browse the repository at this point in the history
…ackwards-compat

Provide capability to ignore existing SwaggerOptions/SwaggerUiOptions
  • Loading branch information
domaindrivendev authored Mar 20, 2020
2 parents 4e473ec + 2f89e26 commit e33dba2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
12 changes: 10 additions & 2 deletions src/Swashbuckle.AspNetCore.ReDoc/ReDocBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ public static IApplicationBuilder UseReDoc(
this IApplicationBuilder app,
Action<ReDocOptions> setupAction = null)
{
var options = app.ApplicationServices.GetService<IOptions<ReDocOptions>>()?.Value ?? new ReDocOptions();
setupAction?.Invoke(options);
var options = new ReDocOptions();
if (setupAction != null)
{
setupAction(options);
}
else
{
options = app.ApplicationServices.GetRequiredService<IOptions<ReDocOptions>>().Value;
}

app.UseMiddleware<ReDocMiddleware>(options);

return app;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ public static IApplicationBuilder UseSwagger(
this IApplicationBuilder app,
Action<SwaggerOptions> setupAction = null)
{
var options = app.ApplicationServices.GetService<IOptions<SwaggerOptions>>()?.Value ?? new SwaggerOptions();
setupAction?.Invoke(options);
SwaggerOptions options = new SwaggerOptions();
if (setupAction != null)
{
setupAction(options);
}
else
{
options = app.ApplicationServices.GetRequiredService<IOptions<SwaggerOptions>>().Value;
}

app.UseMiddleware<SwaggerMiddleware>(options);

return app;
Expand Down
12 changes: 10 additions & 2 deletions src/Swashbuckle.AspNetCore.SwaggerUI/SwaggerUIBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ public static IApplicationBuilder UseSwaggerUI(
this IApplicationBuilder app,
Action<SwaggerUIOptions> setupAction = null)
{
var options = app.ApplicationServices.GetService<IOptions<SwaggerUIOptions>>()?.Value ?? new SwaggerUIOptions();
setupAction?.Invoke(options);
var options = new SwaggerUIOptions();
if (setupAction != null)
{
setupAction(options);
}
else
{
options = app.ApplicationServices.GetRequiredService<IOptions<SwaggerUIOptions>>().Value;
}

app.UseMiddleware<SwaggerUIMiddleware>(options);

return app;
Expand Down

0 comments on commit e33dba2

Please sign in to comment.