Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix EnableTryItOut UI option #5031

Merged
merged 1 commit into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions src/NSwag.AspNet.Owin/SwaggerUi/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,10 @@
}
var urls = {Urls};

const disableTryItOutPlugin = function() {
return {
statePlugins: {
spec: {
wrapSelectors: {
allowTryItOutFor: function() {
return function() {
return {EnableTryItOut};
}
}
}
}
}
}
}

// Build a system
var ui = SwaggerUIBundle({
url: url,
urls: urls,
urls: urls,
validatorUrl: {ValidatorUrl},
oauth2RedirectUrl: {RedirectUrl},

Expand All @@ -58,8 +42,7 @@
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl,
disableTryItOutPlugin
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});
Expand Down
21 changes: 2 additions & 19 deletions src/NSwag.AspNetCore/SwaggerUi/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,10 @@
}
var urls = {Urls};

const disableTryItOutPlugin = function() {
return {
statePlugins: {
spec: {
wrapSelectors: {
allowTryItOutFor: function() {
return function() {
return {EnableTryItOut};
}
}
}
}
}
}
}

// Build a system
var ui = SwaggerUIBundle({
url: url,
urls: urls,
urls: urls,
validatorUrl: {ValidatorUrl},
oauth2RedirectUrl: {RedirectUrl},

Expand All @@ -58,8 +42,7 @@
SwaggerUIStandalonePreset
],
plugins: [
SwaggerUIBundle.plugins.DownloadUrl,
disableTryItOutPlugin
SwaggerUIBundle.plugins.DownloadUrl
],
layout: "StandaloneLayout"
});
Expand Down
11 changes: 7 additions & 4 deletions src/NSwag.AspNetCore/SwaggerUiSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ public SwaggerUiSettings()
public string ServerUrl { get; set; } = "";

/// <summary>Specifies whether the "Try it out" option is enabled in Swagger UI 3.</summary>
public bool EnableTryItOut { get; set; } = true;
public bool EnableTryItOut
{
get => (bool)AdditionalSettings["tryItOutEnabled"];
set => AdditionalSettings["tryItOutEnabled"] = value;
}

/// <summary>
/// Gets or sets a title for the Swagger UI page.
Expand Down Expand Up @@ -157,8 +161,8 @@ internal override async Task<string> TransformHtmlAsync(string html, HttpRequest
}
}

var swaggerRoutes = SwaggerRoutesFactory != null ?
(await SwaggerRoutesFactory(request, cancellationToken)).ToList() :
var swaggerRoutes = SwaggerRoutesFactory != null ?
(await SwaggerRoutesFactory(request, cancellationToken)).ToList() :
SwaggerRoutes;

htmlBuilder.Replace("{Urls}", !swaggerRoutes.Any()
Expand All @@ -172,7 +176,6 @@ internal override async Task<string> TransformHtmlAsync(string html, HttpRequest

htmlBuilder.Replace("{ValidatorUrl}", ValidateSpecification ? "undefined" : "null")
.Replace("{AdditionalSettings}", GenerateAdditionalSettings(AdditionalSettings))
.Replace("{EnableTryItOut}", EnableTryItOut.ToString().ToLower())
.Replace("{RedirectUrl}",
string.IsNullOrEmpty(ServerUrl)
? "window.location.origin + \"" + TransformToExternalPath(Path, request) +
Expand Down
Loading