Skip to content

Commit

Permalink
fix: missing SwaggerUiTheme and url for swagger-json
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkallesen committed Aug 6, 2024
1 parent 8d0a560 commit cd333af
Showing 1 changed file with 14 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,27 @@ public static IApplicationBuilder ConfigureRestApi(
if ((env.IsDevelopment() || restApiOptions.UseSwaggerUi) &&
restApiOptions.SwaggerUiTheme is not null)
{
var cssFile = string.Empty;
if (restApiOptions.SwaggerUiTheme.EndsWith(".css", StringComparison.Ordinal) &&
restApiOptions.SwaggerUiTheme.Contains("Light", StringComparison.OrdinalIgnoreCase))
var cssFile = restApiOptions.SwaggerUiTheme.EndsWith(".css", StringComparison.Ordinal) switch
{
cssFile = "SwaggerLight.css";
}
else if (restApiOptions.SwaggerUiTheme.EndsWith(".css", StringComparison.Ordinal) &&
restApiOptions.SwaggerUiTheme.Contains("Dark", StringComparison.OrdinalIgnoreCase))
{
cssFile = "SwaggerDark.css";
}
false when restApiOptions.SwaggerUiTheme.Contains("Light", StringComparison.OrdinalIgnoreCase) =>
"SwaggerLight.css",
false when restApiOptions.SwaggerUiTheme.Contains("Dark", StringComparison.OrdinalIgnoreCase) =>
"SwaggerDark.css",
_ => string.Empty,
};

var options = new SwaggerUIOptions();
options.InjectStylesheet(restApiOptions.SwaggerUiTheme);
options.EnableTryItOutByDefault();
options.InjectStylesheet($"/swagger-ui/{cssFile}");
options.InjectJavascript("/swagger-ui/main.js");

// TODO: Add support for multiple versions
var groupName = "v1.0";
var url = $"/swagger/{groupName}/swagger.json";
var applicationName = env.ApplicationName;
var name = groupName.ToUpperInvariant();
options.SwaggerEndpoint(url, $"{applicationName} {name}");

app.UseOpenApiSpec(env, restApiOptions, options);
}
else
Expand Down

0 comments on commit cd333af

Please sign in to comment.