From 78356eb68a4f49ce6da84d0c32638f5cdf93c77a Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Mon, 17 Aug 2020 13:00:53 -0400 Subject: [PATCH] Adds configuration option for swagger UI - Config version to 2.1.0 --- .../Configuration/GeneralConfiguration.cs | 9 +++++++-- src/Tgstation.Server.Host/Core/Application.cs | 3 ++- src/Tgstation.Server.Host/Setup/SetupWizard.cs | 4 +++- src/Tgstation.Server.Host/appsettings.json | 5 +++-- .../Tgstation.Server.Host.Tests/Setup/TestSetupWizard.cs | 5 ++++- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs b/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs index 69d5ec1b30..4b925e9342 100644 --- a/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs +++ b/src/Tgstation.Server.Host/Configuration/GeneralConfiguration.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging; using Newtonsoft.Json; using Newtonsoft.Json.Converters; using System; @@ -24,7 +24,7 @@ namespace Tgstation.Server.Host.Configuration /// /// The current . /// - public static readonly Version CurrentConfigVersion = new Version(2, 0, 0); + public static readonly Version CurrentConfigVersion = new Version(2, 1, 0); /// /// The default value for . @@ -87,6 +87,11 @@ namespace Tgstation.Server.Host.Configuration /// public bool UseBasicWatchdog { get; set; } + /// + /// If the swagger UI should be made avaiable. + /// + public bool HostApiDocumemtation { get; set; } + /// /// Initializes a new instance of the . /// diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index a5104530bc..52a837f345 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -394,7 +394,8 @@ namespace Tgstation.Server.Host.Core // suppress OperationCancelledExceptions, they are just aborted HTTP requests applicationBuilder.UseCancelledRequestSuppression(); - if (hostingEnvironment.IsDevelopment()) + if (hostingEnvironment.IsDevelopment() + || generalConfiguration.HostApiDocumemtation) { applicationBuilder.UseSwagger(); applicationBuilder.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "TGS API V4")); diff --git a/src/Tgstation.Server.Host/Setup/SetupWizard.cs b/src/Tgstation.Server.Host/Setup/SetupWizard.cs index fe7fdf4e00..b32bd9206d 100644 --- a/src/Tgstation.Server.Host/Setup/SetupWizard.cs +++ b/src/Tgstation.Server.Host/Setup/SetupWizard.cs @@ -1,4 +1,4 @@ -using Microsoft.Data.Sqlite; +using Microsoft.Data.Sqlite; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; @@ -613,6 +613,8 @@ namespace Tgstation.Server.Host.Setup if (String.IsNullOrWhiteSpace(newGeneralConfiguration.GitHubAccessToken)) newGeneralConfiguration.GitHubAccessToken = null; + newGeneralConfiguration.HostApiDocumemtation = await PromptYesNo("Host API Documentation? (y/n): ", cancellationToken).ConfigureAwait(false); + return newGeneralConfiguration; } diff --git a/src/Tgstation.Server.Host/appsettings.json b/src/Tgstation.Server.Host/appsettings.json index 49409225a3..8bcf394cc2 100644 --- a/src/Tgstation.Server.Host/appsettings.json +++ b/src/Tgstation.Server.Host/appsettings.json @@ -1,4 +1,4 @@ -{ +{ "General": { "MinimumPasswordLength": 15, "GitHubAccessToken": null, @@ -9,7 +9,8 @@ "UseBasicWatchdog": false, "UserLimit": 100, "InstanceLimit": 10, - "ValidInstancePaths": null + "ValidInstancePaths": null, + "HostApiDocumemtation": false }, "FileLogging": { "Directory": null, diff --git a/tests/Tgstation.Server.Host.Tests/Setup/TestSetupWizard.cs b/tests/Tgstation.Server.Host.Tests/Setup/TestSetupWizard.cs index 8d9d760faa..3d99525bdf 100644 --- a/tests/Tgstation.Server.Host.Tests/Setup/TestSetupWizard.cs +++ b/tests/Tgstation.Server.Host.Tests/Setup/TestSetupWizard.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; using Microsoft.VisualStudio.TestTools.UnitTesting; @@ -144,6 +144,7 @@ namespace Tgstation.Server.Host.Setup.Tests "-27", "5000", "fake token", + "y", //logging config "no", //cp config @@ -166,6 +167,7 @@ namespace Tgstation.Server.Host.Setup.Tests String.Empty, String.Empty, "n", + "n", //logging config "y", "not actually verified because lol mocks /../!@#$%^&*()/..///.", @@ -189,6 +191,7 @@ namespace Tgstation.Server.Host.Setup.Tests String.Empty, String.Empty, "y", + "y", "will faile", String.Empty, String.Empty,