diff --git a/Shoko.Server/API/APIExtensions.cs b/Shoko.Server/API/APIExtensions.cs index 5a7a9dc2f..8de88ad21 100644 --- a/Shoko.Server/API/APIExtensions.cs +++ b/Shoko.Server/API/APIExtensions.cs @@ -21,11 +21,11 @@ using Shoko.Server.API.SignalR.Aggregate; using Shoko.Server.API.Swagger; using Shoko.Server.API.v3.Helpers; -using Shoko.Server.API.v3.Models.Shoko; using Shoko.Server.API.FileProviders; using Shoko.Server.Plugin; using Shoko.Server.Services; using Shoko.Server.Utilities; +using Swashbuckle.AspNetCore.SwaggerGen; using File = System.IO.File; using AniDBEmitter = Shoko.Server.API.SignalR.Aggregate.AniDBEmitter; using ShokoEventEmitter = Shoko.Server.API.SignalR.Aggregate.ShokoEventEmitter; @@ -116,11 +116,24 @@ public static IServiceCollection AddAPI(this IServiceCollection services) options.AddPlugins(); - options.SchemaFilter>(); - options.SchemaFilter>(); + var v3Enums = typeof(APIExtensions).Assembly.GetTypes().Where(a => + { + if (!a.IsEnum) return false; + return a.FullName?.StartsWith("Shoko.Server.API.v3", StringComparison.InvariantCultureIgnoreCase) ?? false; + }); + foreach (var type in v3Enums) + { + var descriptorType = typeof(EnumSchemaFilter<>).MakeGenericType(type); + options.RequestBodyFilterDescriptors.Add(new FilterDescriptor + { + Type = descriptorType, + Arguments = [] + }); + } + + // these are in Plugin Abstractions options.SchemaFilter>(); options.SchemaFilter>(); - options.SchemaFilter>(); options.CustomSchemaIds(GetTypeName); }); diff --git a/Shoko.Server/API/v3/Models/Shoko/Episode.cs b/Shoko.Server/API/v3/Models/Shoko/Episode.cs index c62ef9159..a87c2c767 100644 --- a/Shoko.Server/API/v3/Models/Shoko/Episode.cs +++ b/Shoko.Server/API/v3/Models/Shoko/Episode.cs @@ -388,6 +388,7 @@ public class EpisodeTitleOverrideBody } } +[JsonConverter(typeof(StringEnumConverter))] public enum EpisodeType { /// diff --git a/Shoko.Server/API/v3/Models/Shoko/File.cs b/Shoko.Server/API/v3/Models/Shoko/File.cs index 154666bbe..bbf6c5b7d 100644 --- a/Shoko.Server/API/v3/Models/Shoko/File.cs +++ b/Shoko.Server/API/v3/Models/Shoko/File.cs @@ -560,6 +560,7 @@ public class BatchDeleteBody } } + [JsonConverter(typeof(StringEnumConverter))] public enum FileSortCriteria { None = 0, diff --git a/Shoko.Server/API/v3/Models/Shoko/Filter.cs b/Shoko.Server/API/v3/Models/Shoko/Filter.cs index 6727017f8..514cdbd81 100644 --- a/Shoko.Server/API/v3/Models/Shoko/Filter.cs +++ b/Shoko.Server/API/v3/Models/Shoko/Filter.cs @@ -218,6 +218,7 @@ public bool ShouldSerializePossibleParameterPairs() /// Dates are in yyyy-MM-dd format
/// TimeSpans are in d:HH:mm:ss.ffff format (f is milliseconds) ///
+ [JsonConverter(typeof(StringEnumConverter))] public enum FilterExpressionParameterType { Expression, diff --git a/Shoko.Server/API/v3/Models/Shoko/ImportFolder.cs b/Shoko.Server/API/v3/Models/Shoko/ImportFolder.cs index 6f36eff51..4c5fe5f18 100644 --- a/Shoko.Server/API/v3/Models/Shoko/ImportFolder.cs +++ b/Shoko.Server/API/v3/Models/Shoko/ImportFolder.cs @@ -1,5 +1,7 @@ using System; using System.Linq; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; using Shoko.Commons.Extensions; using Shoko.Models.Enums; using Shoko.Server.API.v3.Models.Common; @@ -96,6 +98,7 @@ public SVR_ImportFolder GetServerModel() } [Flags] +[JsonConverter(typeof(StringEnumConverter))] public enum DropFolderType { None = 0, diff --git a/Shoko.Server/API/v3/Models/Shoko/Series.cs b/Shoko.Server/API/v3/Models/Shoko/Series.cs index d96d0d2a0..1a94aa776 100644 --- a/Shoko.Server/API/v3/Models/Shoko/Series.cs +++ b/Shoko.Server/API/v3/Models/Shoko/Series.cs @@ -893,6 +893,7 @@ public WithEpisodeCount(int episodeCount, SVR_AnimeSeries ser, int userId = 0, H } } +[JsonConverter(typeof(StringEnumConverter))] public enum SeriesType { /// diff --git a/Shoko.Server/API/v3/Models/Shoko/ServerStatus.cs b/Shoko.Server/API/v3/Models/Shoko/ServerStatus.cs index 095a6545f..d694de53a 100644 --- a/Shoko.Server/API/v3/Models/Shoko/ServerStatus.cs +++ b/Shoko.Server/API/v3/Models/Shoko/ServerStatus.cs @@ -1,4 +1,6 @@ using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Converters; using Shoko.Server.Server; namespace Shoko.Server.API.v3.Models.Shoko; @@ -20,6 +22,7 @@ public class ServerStatus /// public TimeSpan? Uptime { get; set; } + [JsonConverter(typeof(StringEnumConverter))] public enum StartupState { /// diff --git a/Shoko.Tests/TestFilterable.cs b/Shoko.Tests/TestFilterable.cs index b96cea1fa..cd2099ddb 100644 --- a/Shoko.Tests/TestFilterable.cs +++ b/Shoko.Tests/TestFilterable.cs @@ -24,10 +24,12 @@ public class TestFilterable : IFilterable public IReadOnlySet AvailableImageTypes { get; } public IReadOnlySet PreferredImageTypes { get; } public bool HasTmdbLink { get; init; } + public bool HasTmdbAutoLinkingDisabled { get; init; } public bool HasMissingTmdbLink { get; init; } public int AutomaticTmdbEpisodeLinks { get; init; } public int UserVerifiedTmdbEpisodeLinks { get; init; } public bool HasTraktLink { get; init; } + public bool HasTraktAutoLinkingDisabled { get; init; } public bool HasMissingTraktLink { get; init; } public bool IsFinished { get; init; } public DateTime? AirDate { get; init; }