Skip to content

Commit

Permalink
Fix EnableTryItOut UI option (#5031)
Browse files Browse the repository at this point in the history
  • Loading branch information
Saibamen authored Nov 20, 2024
1 parent 2888363 commit 588d18f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 42 deletions.
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

0 comments on commit 588d18f

Please sign in to comment.