Skip to content

Commit

Permalink
All of the Enums should be strings
Browse files Browse the repository at this point in the history
  • Loading branch information
da3dsoul committed Feb 7, 2025
1 parent 12e1356 commit e12f58c
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 4 deletions.
21 changes: 17 additions & 4 deletions Shoko.Server/API/APIExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -116,11 +116,24 @@ public static IServiceCollection AddAPI(this IServiceCollection services)

options.AddPlugins();

options.SchemaFilter<EnumSchemaFilter<EpisodeType>>();
options.SchemaFilter<EnumSchemaFilter<SeriesType>>();
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<EnumSchemaFilter<RenamerSettingType>>();
options.SchemaFilter<EnumSchemaFilter<CodeLanguage>>();
options.SchemaFilter<EnumSchemaFilter<Filter.FilterExpressionHelp.FilterExpressionParameterType>>();

options.CustomSchemaIds(GetTypeName);
});
Expand Down
1 change: 1 addition & 0 deletions Shoko.Server/API/v3/Models/Shoko/Episode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ public class EpisodeTitleOverrideBody
}
}

[JsonConverter(typeof(StringEnumConverter))]
public enum EpisodeType
{
/// <summary>
Expand Down
1 change: 1 addition & 0 deletions Shoko.Server/API/v3/Models/Shoko/File.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ public class BatchDeleteBody
}
}

[JsonConverter(typeof(StringEnumConverter))]
public enum FileSortCriteria
{
None = 0,
Expand Down
1 change: 1 addition & 0 deletions Shoko.Server/API/v3/Models/Shoko/Filter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ public bool ShouldSerializePossibleParameterPairs()
/// Dates are in yyyy-MM-dd format<br/>
/// TimeSpans are in d:HH:mm:ss.ffff format (f is milliseconds)
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public enum FilterExpressionParameterType
{
Expression,
Expand Down
3 changes: 3 additions & 0 deletions Shoko.Server/API/v3/Models/Shoko/ImportFolder.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -96,6 +98,7 @@ public SVR_ImportFolder GetServerModel()
}

[Flags]
[JsonConverter(typeof(StringEnumConverter))]
public enum DropFolderType
{
None = 0,
Expand Down
1 change: 1 addition & 0 deletions Shoko.Server/API/v3/Models/Shoko/Series.cs
Original file line number Diff line number Diff line change
Expand Up @@ -893,6 +893,7 @@ public WithEpisodeCount(int episodeCount, SVR_AnimeSeries ser, int userId = 0, H
}
}

[JsonConverter(typeof(StringEnumConverter))]
public enum SeriesType
{
/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions Shoko.Server/API/v3/Models/Shoko/ServerStatus.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Shoko.Server.Server;

namespace Shoko.Server.API.v3.Models.Shoko;
Expand All @@ -20,6 +22,7 @@ public class ServerStatus
/// </summary>
public TimeSpan? Uptime { get; set; }

[JsonConverter(typeof(StringEnumConverter))]
public enum StartupState
{
/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions Shoko.Tests/TestFilterable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ public class TestFilterable : IFilterable
public IReadOnlySet<ImageEntityType> AvailableImageTypes { get; }
public IReadOnlySet<ImageEntityType> 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; }
Expand Down

0 comments on commit e12f58c

Please sign in to comment.