Explicitly set default value for enums used in API models (#13821)

Enums in response model with no nullability or default value will make the API very fragile as each extension to the enum will break the API for some clients, but a lot of enums actually do have an unknown value which should be used as a default. This set all model properties that are non-nullable using an enum that has an Unknown member in 10.10, except MediaStream.VideoRangeType which is refactored in #13277
This commit is contained in:
gnattu 2025-04-01 07:43:31 +08:00 committed by GitHub
parent e9729a536f
commit 4a4fef830e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 9 additions and 0 deletions

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Jellyfin.Data.Enums;
using Jellyfin.Database.Implementations.Entities;
using MediaBrowser.Model.Drawing;
@ -586,6 +587,7 @@ namespace MediaBrowser.Model.Dto
/// Gets or sets the type of the media.
/// </summary>
/// <value>The type of the media.</value>
[DefaultValue(MediaType.Unknown)]
public MediaType MediaType { get; set; }
/// <summary>

View File

@ -1,6 +1,7 @@
#nullable disable
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text.Json.Serialization;
using Jellyfin.Data.Enums;
using MediaBrowser.Model.Entities;
@ -34,6 +35,7 @@ namespace MediaBrowser.Model.Dto
/// Gets or sets the type.
/// </summary>
/// <value>The type.</value>
[DefaultValue(PersonKind.Unknown)]
public PersonKind Type { get; set; }
/// <summary>

View File

@ -157,6 +157,7 @@ namespace MediaBrowser.Model.Entities
/// Gets the video range.
/// </summary>
/// <value>The video range.</value>
[DefaultValue(VideoRange.Unknown)]
public VideoRange VideoRange
{
get

View File

@ -1,4 +1,5 @@
using System;
using System.ComponentModel;
using Jellyfin.Database.Implementations.Enums;
namespace MediaBrowser.Model.MediaSegments;
@ -21,6 +22,7 @@ public class MediaSegmentDto
/// <summary>
/// Gets or sets the type of content this segment defines.
/// </summary>
[DefaultValue(MediaSegmentType.Unknown)]
public MediaSegmentType Type { get; set; }
/// <summary>

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using Jellyfin.Data.Enums;
namespace MediaBrowser.Model.Search
@ -115,6 +116,7 @@ namespace MediaBrowser.Model.Search
/// Gets or sets the type of the media.
/// </summary>
/// <value>The type of the media.</value>
[DefaultValue(MediaType.Unknown)]
public MediaType MediaType { get; set; }
/// <summary>