diff options
| author | JP Dillingham <jpdillingham@gmail.com> | 2021-01-14 07:15:36 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-14 07:15:36 -0600 |
| commit | 6b5e13f955033ada8f4958b36e83fb2937c57378 (patch) | |
| tree | 90a65a5e37e5fafaf6445744e032f87b11c7e366 /src | |
| parent | 6f5aa97da154db69bbbbb7d18879ef3045b85ffe (diff) | |
| parent | 088b8c17fe76f312e6cadcaa57d4c1d0b14a2af3 (diff) | |
| download | slskd-6b5e13f955033ada8f4958b36e83fb2937c57378.tar.gz | |
Merge pull request #10 from slskd/skip-swagger
Add options to disable swagger and specify alternate XmlDoc file
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Startup.cs | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/src/slskd/Startup.cs b/src/slskd/Startup.cs index 97b306ef..83be2e91 100644 --- a/src/slskd/Startup.cs +++ b/src/slskd/Startup.cs @@ -49,6 +49,8 @@ internal static int RoomMessageLimit { get; set; } internal static int ReadBufferSize { get; set; } internal static int WriteBufferSize { get; set; } + internal static bool EnableSwagger { get; set; } + internal static string XmlDocFile { get; set; } internal static SymmetricSecurityKey JwtSigningKey { get; set; } @@ -78,6 +80,8 @@ RoomMessageLimit = Configuration.GetValue<int>("ROOM_MESSAGE_LIMIT", 250); ReadBufferSize = Configuration.GetValue<int>("READ_BUFFER_SIZE", 16384); WriteBufferSize = Configuration.GetValue<int>("WRITE_BUFFER_SIZE", 16384); + EnableSwagger = Configuration.GetValue<bool>("ENABLE_SWAGGER", true); + XmlDocFile = Configuration.GetValue<string>("XML_DOC_FILE", Path.Combine(AppContext.BaseDirectory, typeof(Startup).GetTypeInfo().Assembly.GetName().Name + ".xml")); JwtSigningKey = new SymmetricSecurityKey(PBKDF2.GetKey(Password)); @@ -139,19 +143,25 @@ options.SubstituteApiVersionInUrl = true; }); - services.AddSwaggerGen(options => + if (EnableSwagger) { - options.DescribeAllParametersInCamelCase(); - options.SwaggerDoc("v0", - new OpenApiInfo + services.AddSwaggerGen(options => + { + options.DescribeAllParametersInCamelCase(); + options.SwaggerDoc("v0", + new OpenApiInfo + { + Title = "slskd", + Version = "v0" + } + ); + + if (System.IO.File.Exists(XmlDocFile)) { - Title = "slskd", - Version = "v0" + options.IncludeXmlComments(XmlDocFile); } - ); - - options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, typeof(Startup).GetTypeInfo().Assembly.GetName().Name + ".xml")); - }); + }); + } services.AddSingleton<ISoulseekClient, SoulseekClient>(serviceProvider => Client); services.AddSingleton<ITransferTracker, TransferTracker>(); @@ -212,9 +222,12 @@ app.UseAuthentication(); app.UseMvc(); - app.UseSwagger(); - app.UseSwaggerUI(options => provider.ApiVersionDescriptions.ToList() - .ForEach(description => options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", description.GroupName))); + if (EnableSwagger) + { + app.UseSwagger(); + app.UseSwaggerUI(options => provider.ApiVersionDescriptions.ToList() + .ForEach(description => options.SwaggerEndpoint($"/swagger/{description.GroupName}/swagger.json", description.GroupName))); + } // if we made it this far and the route still wasn't matched, return the index // this is required so that SPA routing (React Router, etc) can work properly |
