Convert CollectionType, SpecialFolderType to enum (#9764)
* Convert CollectionType, SpecialFolderType to enum * Hide internal enum CollectionType values * Apply suggestions from code review Co-authored-by: Shadowghost <Shadowghost@users.noreply.github.com> * Fix recent change * Update Jellyfin.Data/Attributes/OpenApiIgnoreEnumAttribute.cs Co-authored-by: Patrick Barron <barronpm@gmail.com> --------- Co-authored-by: Shadowghost <Shadowghost@users.noreply.github.com> Co-authored-by: Patrick Barron <barronpm@gmail.com>pull/10557/head
parent
c7a94d48ae
commit
906f701fa8
@ -0,0 +1,11 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Jellyfin.Data.Attributes;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Attribute to specify that the enum value is to be ignored when generating the openapi spec.
|
||||||
|
/// </summary>
|
||||||
|
[AttributeUsage(AttributeTargets.Field)]
|
||||||
|
public sealed class OpenApiIgnoreEnumAttribute : Attribute
|
||||||
|
{
|
||||||
|
}
|
@ -0,0 +1,164 @@
|
|||||||
|
using Jellyfin.Data.Attributes;
|
||||||
|
|
||||||
|
namespace Jellyfin.Data.Enums;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Collection type.
|
||||||
|
/// </summary>
|
||||||
|
public enum CollectionType
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Unknown collection.
|
||||||
|
/// </summary>
|
||||||
|
Unknown = 0,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Movies collection.
|
||||||
|
/// </summary>
|
||||||
|
Movies = 1,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tv shows collection.
|
||||||
|
/// </summary>
|
||||||
|
TvShows = 2,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Music collection.
|
||||||
|
/// </summary>
|
||||||
|
Music = 3,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Music videos collection.
|
||||||
|
/// </summary>
|
||||||
|
MusicVideos = 4,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Trailers collection.
|
||||||
|
/// </summary>
|
||||||
|
Trailers = 5,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Home videos collection.
|
||||||
|
/// </summary>
|
||||||
|
HomeVideos = 6,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Box sets collection.
|
||||||
|
/// </summary>
|
||||||
|
BoxSets = 7,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Books collection.
|
||||||
|
/// </summary>
|
||||||
|
Books = 8,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Photos collection.
|
||||||
|
/// </summary>
|
||||||
|
Photos = 9,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Live tv collection.
|
||||||
|
/// </summary>
|
||||||
|
LiveTv = 10,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Playlists collection.
|
||||||
|
/// </summary>
|
||||||
|
Playlists = 11,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Folders collection.
|
||||||
|
/// </summary>
|
||||||
|
Folders = 12,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tv show series collection.
|
||||||
|
/// </summary>
|
||||||
|
[OpenApiIgnoreEnum]
|
||||||
|
TvShowSeries = 101,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tv genres collection.
|
||||||
|
/// </summary>
|
||||||
|
[OpenApiIgnoreEnum]
|
||||||
|
TvGenres = 102,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tv genre collection.
|
||||||
|
/// </summary>
|
||||||
|
[OpenApiIgnoreEnum]
|
||||||
|
TvGenre = 103,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tv latest collection.
|
||||||
|
/// </summary>
|
||||||
|
[OpenApiIgnoreEnum]
|
||||||
|
TvLatest = 104,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tv next up collection.
|
||||||
|
/// </summary>
|
||||||
|
[OpenApiIgnoreEnum]
|
||||||
|
TvNextUp = 105,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tv resume collection.
|
||||||
|
/// </summary>
|
||||||
|
[OpenApiIgnoreEnum]
|
||||||
|
TvResume = 106,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tv favorite series collection.
|
||||||
|
/// </summary>
|
||||||
|
[OpenApiIgnoreEnum]
|
||||||
|
TvFavoriteSeries = 107,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Tv favorite episodes collection.
|
||||||
|
/// </summary>
|
||||||
|
[OpenApiIgnoreEnum]
|
||||||
|
TvFavoriteEpisodes = 108,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Latest movies collection.
|
||||||
|
/// </summary>
|
||||||
|
[OpenApiIgnoreEnum]
|
||||||
|
MovieLatest = 109,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Movies to resume collection.
|
||||||
|
/// </summary>
|
||||||
|
[OpenApiIgnoreEnum]
|
||||||
|
MovieResume = 110,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Movie movie collection.
|
||||||
|
/// </summary>
|
||||||
|
[OpenApiIgnoreEnum]
|
||||||
|
MovieMovies = 111,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Movie collections collection.
|
||||||
|
/// </summary>
|
||||||
|
[OpenApiIgnoreEnum]
|
||||||
|
MovieCollections = 112,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Movie favorites collection.
|
||||||
|
/// </summary>
|
||||||
|
[OpenApiIgnoreEnum]
|
||||||
|
MovieFavorites = 113,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Movie genres collection.
|
||||||
|
/// </summary>
|
||||||
|
[OpenApiIgnoreEnum]
|
||||||
|
MovieGenres = 114,
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Movie genre collection.
|
||||||
|
/// </summary>
|
||||||
|
[OpenApiIgnoreEnum]
|
||||||
|
MovieGenre = 115
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
|
using Jellyfin.Data.Attributes;
|
||||||
|
using Microsoft.OpenApi.Any;
|
||||||
|
using Microsoft.OpenApi.Models;
|
||||||
|
using Swashbuckle.AspNetCore.SwaggerGen;
|
||||||
|
|
||||||
|
namespace Jellyfin.Server.Filters;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Filter to remove ignored enum values.
|
||||||
|
/// </summary>
|
||||||
|
public class IgnoreEnumSchemaFilter : ISchemaFilter
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Apply(OpenApiSchema schema, SchemaFilterContext context)
|
||||||
|
{
|
||||||
|
if (context.Type.IsEnum || (Nullable.GetUnderlyingType(context.Type)?.IsEnum ?? false))
|
||||||
|
{
|
||||||
|
var type = context.Type.IsEnum ? context.Type : Nullable.GetUnderlyingType(context.Type);
|
||||||
|
if (type is null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var enumOpenApiStrings = new List<IOpenApiAny>();
|
||||||
|
|
||||||
|
foreach (var enumName in Enum.GetNames(type))
|
||||||
|
{
|
||||||
|
var member = type.GetMember(enumName)[0];
|
||||||
|
if (!member.GetCustomAttributes<OpenApiIgnoreEnumAttribute>().Any())
|
||||||
|
{
|
||||||
|
enumOpenApiStrings.Add(new OpenApiString(enumName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
schema.Enum = enumOpenApiStrings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,27 +0,0 @@
|
|||||||
#pragma warning disable CS1591
|
|
||||||
|
|
||||||
namespace MediaBrowser.Model.Entities
|
|
||||||
{
|
|
||||||
public static class CollectionType
|
|
||||||
{
|
|
||||||
public const string Movies = "movies";
|
|
||||||
|
|
||||||
public const string TvShows = "tvshows";
|
|
||||||
|
|
||||||
public const string Music = "music";
|
|
||||||
|
|
||||||
public const string MusicVideos = "musicvideos";
|
|
||||||
|
|
||||||
public const string Trailers = "trailers";
|
|
||||||
|
|
||||||
public const string HomeVideos = "homevideos";
|
|
||||||
|
|
||||||
public const string BoxSets = "boxsets";
|
|
||||||
|
|
||||||
public const string Books = "books";
|
|
||||||
public const string Photos = "photos";
|
|
||||||
public const string LiveTv = "livetv";
|
|
||||||
public const string Playlists = "playlists";
|
|
||||||
public const string Folders = "folders";
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in new issue