< Summary - Jellyfin

Information
Class: Jellyfin.Server.Filters.FlagsEnumSchemaFilter
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/Filters/FlagsEnumSchemaFilter.cs
Line coverage
94%
Covered lines: 16
Uncovered lines: 1
Coverable lines: 17
Total lines: 58
Line coverage: 94.1%
Branch coverage
91%
Covered branches: 11
Total branches: 12
Branch coverage: 91.6%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 1/3/2026 - 12:11:48 AM Line coverage: 100% (15/15) Branch coverage: 100% (10/10) Total lines: 532/27/2026 - 12:13:29 AM Line coverage: 94.1% (16/17) Branch coverage: 91.6% (11/12) Total lines: 58 1/3/2026 - 12:11:48 AM Line coverage: 100% (15/15) Branch coverage: 100% (10/10) Total lines: 532/27/2026 - 12:13:29 AM Line coverage: 94.1% (16/17) Branch coverage: 91.6% (11/12) Total lines: 58

Coverage delta

Coverage delta 9 -9

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Apply(...)91.66%121294.11%

File(s)

/srv/git/jellyfin/Jellyfin.Server/Filters/FlagsEnumSchemaFilter.cs

#LineLine coverage
 1using System;
 2using Microsoft.OpenApi;
 3using Swashbuckle.AspNetCore.SwaggerGen;
 4
 5namespace Jellyfin.Server.Filters;
 6
 7/// <summary>
 8/// Schema filter to ensure flags enums are represented correctly in OpenAPI.
 9/// </summary>
 10/// <remarks>
 11/// For flags enums:
 12/// - The enum schema definition is set to type "string" (not integer).
 13/// - Properties using flags enums are transformed to arrays referencing the enum schema.
 14/// </remarks>
 15public class FlagsEnumSchemaFilter : ISchemaFilter
 16{
 17    /// <inheritdoc />
 18    public void Apply(IOpenApiSchema schema, SchemaFilterContext context)
 19    {
 507720        var type = context.Type.IsEnum ? context.Type : Nullable.GetUnderlyingType(context.Type);
 507721        if (type is null || !type.IsEnum)
 22        {
 472123            return;
 24        }
 25
 26        // Check if enum has [Flags] attribute
 35627        if (!type.IsDefined(typeof(FlagsAttribute), false))
 28        {
 35429            return;
 30        }
 31
 232        if (schema is not OpenApiSchema concreteSchema)
 33        {
 034            return;
 35        }
 36
 237        if (context.MemberInfo is null)
 38        {
 39            // Processing the enum definition itself - ensure it's type "string" not "integer"
 140            concreteSchema.Type = JsonSchemaType.String;
 141            concreteSchema.Format = null;
 42        }
 43        else
 44        {
 45            // Processing a property that uses the flags enum - transform to array
 46            // Generate the enum schema to ensure it exists in the repository
 147            var enumSchema = context.SchemaGenerator.GenerateSchema(type, context.SchemaRepository);
 48
 49            // Flags enums should be represented as arrays referencing the enum schema
 50            // since multiple values can be combined
 151            concreteSchema.Type = JsonSchemaType.Array;
 152            concreteSchema.Format = null;
 153            concreteSchema.Enum = null;
 154            concreteSchema.AllOf = null;
 155            concreteSchema.Items = enumSchema;
 56        }
 157    }
 58}