< Summary - Jellyfin

Information
Class: Jellyfin.Server.Filters.FlagsEnumSchemaFilter
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/Filters/FlagsEnumSchemaFilter.cs
Line coverage
100%
Covered lines: 15
Uncovered lines: 0
Coverable lines: 15
Total lines: 53
Line coverage: 100%
Branch coverage
100%
Covered branches: 10
Total branches: 10
Branch coverage: 100%
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: 53 1/3/2026 - 12:11:48 AM Line coverage: 100% (15/15) Branch coverage: 100% (10/10) Total lines: 53

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Apply(...)100%1010100%

File(s)

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

#LineLine coverage
 1using System;
 2using Microsoft.OpenApi.Models;
 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(OpenApiSchema schema, SchemaFilterContext context)
 19    {
 509720        var type = context.Type.IsEnum ? context.Type : Nullable.GetUnderlyingType(context.Type);
 509721        if (type is null || !type.IsEnum)
 22        {
 474323            return;
 24        }
 25
 26        // Check if enum has [Flags] attribute
 35427        if (!type.IsDefined(typeof(FlagsAttribute), false))
 28        {
 35229            return;
 30        }
 31
 232        if (context.MemberInfo is null)
 33        {
 34            // Processing the enum definition itself - ensure it's type "string" not "integer"
 135            schema.Type = "string";
 136            schema.Format = null;
 37        }
 38        else
 39        {
 40            // Processing a property that uses the flags enum - transform to array
 41            // Generate the enum schema to ensure it exists in the repository
 142            var enumSchema = context.SchemaGenerator.GenerateSchema(type, context.SchemaRepository);
 43
 44            // Flags enums should be represented as arrays referencing the enum schema
 45            // since multiple values can be combined
 146            schema.Type = "array";
 147            schema.Format = null;
 148            schema.Enum = null;
 149            schema.AllOf = null;
 150            schema.Items = enumSchema;
 51        }
 152    }
 53}