Skip to content

Commit

Permalink
Closes #3376
Browse files Browse the repository at this point in the history
  • Loading branch information
JustArchi committed Feb 12, 2025
1 parent 2c31b5f commit 2f658a3
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 283 deletions.
3 changes: 1 addition & 2 deletions ArchiSteamFarm/ArchiSteamFarm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
<PackageReference Include="Nito.AsyncEx.Coordination" />
<PackageReference Include="NLog.Web.AspNetCore" />
<PackageReference Include="SteamKit2" />
<PackageReference Include="Swashbuckle.AspNetCore" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" />
<PackageReference Include="System.Composition" />
<PackageReference Include="System.Linq.Async" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" />
Expand Down
80 changes: 8 additions & 72 deletions ArchiSteamFarm/IPC/ArchiKestrel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
using ArchiSteamFarm.IPC.Controllers.Api;
using ArchiSteamFarm.IPC.Integration;
using ArchiSteamFarm.IPC.OpenApi;
using ArchiSteamFarm.IPC.Swashbuckle;
using ArchiSteamFarm.Localization;
using ArchiSteamFarm.NLog;
using ArchiSteamFarm.NLog.Targets;
Expand All @@ -54,7 +53,6 @@
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
using Microsoft.Net.Http.Headers;
using Microsoft.OpenApi.Models;
using NLog.Web;
using IPNetwork = Microsoft.AspNetCore.HttpOverrides.IPNetwork;

Expand Down Expand Up @@ -257,11 +255,7 @@ private static void ConfigureApp([SuppressMessage("ReSharper", "SuggestBaseTypeF
app.MapControllers();

// Add support for OpenAPI, responsible for automatic API documentation generation, this should be on the end, once we're done with API
if (Program.UseOpenApi) {
app.MapOpenApi("/swagger/{documentName}/swagger.json");
} else {
app.UseSwagger();
}
app.MapOpenApi("/swagger/{documentName}/swagger.json");

// Add support for swagger UI, this should be after swagger, obviously
app.UseSwaggerUI(
Expand Down Expand Up @@ -338,71 +332,13 @@ private static void ConfigureServices([SuppressMessage("ReSharper", "SuggestBase
}

// Add support for OpenAPI, responsible for automatic API documentation generation
if (Program.UseOpenApi) {
services.AddOpenApi(
SharedInfo.ASF, static options => {
options.AddDocumentTransformer<DocumentTransformer>();
options.AddOperationTransformer<OperationTransformer>();
options.AddSchemaTransformer<SchemaTransformer>();
}
);
} else {
services.AddSwaggerGen(
static options => {
options.AddSecurityDefinition(
nameof(GlobalConfig.IPCPassword), new OpenApiSecurityScheme {
Description = $"{nameof(GlobalConfig.IPCPassword)} authentication using request headers. Check {SharedInfo.ProjectURL}/wiki/IPC#authentication for more info.",
In = ParameterLocation.Header,
Name = ApiAuthenticationMiddleware.HeadersField,
Type = SecuritySchemeType.ApiKey
}
);

options.AddSecurityRequirement(
new OpenApiSecurityRequirement {
{
new OpenApiSecurityScheme {
Reference = new OpenApiReference {
Id = nameof(GlobalConfig.IPCPassword),
Type = ReferenceType.SecurityScheme
}
},

[]
}
}
);

// We require custom schema IDs due to conflicting type names, choosing the proper one is tricky as there is no good answer and any kind of convention has a potential to create conflict
// FullName and Name both do, ToString() for unknown to me reason doesn't, and I don't have courage to call our WebUtilities.GetUnifiedName() better than what .NET ships with (because it isn't)
// Let's use ToString() until we find a good enough reason to change it, also, the name must pass ^[a-zA-Z0-9.-_]+$ regex
options.CustomSchemaIds(static type => type.ToString().Replace('+', '-'));

options.EnableAnnotations(true, true);

options.SchemaFilter<CustomAttributesSchemaFilter>();
options.SchemaFilter<EnumSchemaFilter>();
options.SchemaFilter<ReadOnlyFixesSchemaFilter>();

options.SwaggerDoc(
SharedInfo.ASF, new OpenApiInfo {
Contact = new OpenApiContact {
Name = SharedInfo.GithubRepo,
Url = new Uri(SharedInfo.ProjectURL)
},

License = new OpenApiLicense {
Name = SharedInfo.LicenseName,
Url = new Uri(SharedInfo.LicenseURL)
},

Title = $"{SharedInfo.AssemblyName} API",
Version = SharedInfo.Version.ToString()
}
);
}
);
}
services.AddOpenApi(
SharedInfo.ASF, static options => {
options.AddDocumentTransformer<DocumentTransformer>();
options.AddOperationTransformer<OperationTransformer>();
options.AddSchemaTransformer<SchemaTransformer>();
}
);

// Add support for optional health-checks
services.AddHealthChecks();
Expand Down
53 changes: 0 additions & 53 deletions ArchiSteamFarm/IPC/Swashbuckle/CustomAttributesSchemaFilter.cs

This file was deleted.

107 changes: 0 additions & 107 deletions ArchiSteamFarm/IPC/Swashbuckle/EnumSchemaFilter.cs

This file was deleted.

42 changes: 0 additions & 42 deletions ArchiSteamFarm/IPC/Swashbuckle/ReadOnlyFixesSchemaFilter.cs

This file was deleted.

5 changes: 0 additions & 5 deletions ArchiSteamFarm/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ internal static class Program {
internal static bool Service { get; private set; }
internal static bool ShutdownSequenceInitialized { get; private set; }
internal static bool SteamParentalGeneration { get; private set; } = true;
internal static bool UseOpenApi { get; private set; }

private static readonly Dictionary<PosixSignal, PosixSignalRegistration> RegisteredPosixSignals = new();
private static readonly TaskCompletionSource<byte> ShutdownResetEvent = new();
Expand Down Expand Up @@ -611,10 +610,6 @@ private static async Task<bool> ParseArgs(IReadOnlyCollection<string> args) {
case "--SYSTEM-REQUIRED" when noArgumentValueNext():
SystemRequired = true;

break;
case "--USE-OPENAPI" when noArgumentValueNext():
UseOpenApi = true;

break;
default:
if (cryptKeyNext) {
Expand Down
3 changes: 1 addition & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
<PackageVersion Include="OpenTelemetry.Instrumentation.Http" Version="1.11.0" />
<PackageVersion Include="OpenTelemetry.Instrumentation.Runtime" Version="1.11.0" />
<PackageVersion Include="SteamKit2" Version="3.0.2" />
<PackageVersion Include="Swashbuckle.AspNetCore" Version="7.2.0" />
<PackageVersion Include="Swashbuckle.AspNetCore.Annotations" Version="7.2.0" />
<PackageVersion Include="Swashbuckle.AspNetCore.SwaggerUI" Version="7.2.0" />
<PackageVersion Include="System.Composition" Version="9.0.2" />
<PackageVersion Include="System.Composition.AttributedModel" Version="9.0.2" />
<PackageVersion Include="System.Linq.Async" Version="6.0.1" />
Expand Down

0 comments on commit 2f658a3

Please sign in to comment.