< Summary - Jellyfin

Information
Class: Jellyfin.Server.Filters.IgnoreEnumSchemaFilter
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/Filters/IgnoreEnumSchemaFilter.cs
Line coverage
90%
Covered lines: 10
Uncovered lines: 1
Coverable lines: 11
Total lines: 42
Line coverage: 90.9%
Branch coverage
92%
Covered branches: 13
Total branches: 14
Branch coverage: 92.8%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Apply(...)92.85%14.151490.9%

File(s)

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

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Reflection;
 5using Jellyfin.Data.Attributes;
 6using Microsoft.OpenApi.Any;
 7using Microsoft.OpenApi.Models;
 8using Swashbuckle.AspNetCore.SwaggerGen;
 9
 10namespace Jellyfin.Server.Filters;
 11
 12/// <summary>
 13/// Filter to remove ignored enum values.
 14/// </summary>
 15public class IgnoreEnumSchemaFilter : ISchemaFilter
 16{
 17    /// <inheritdoc />
 18    public void Apply(OpenApiSchema schema, SchemaFilterContext context)
 19    {
 501820        if (context.Type.IsEnum || (Nullable.GetUnderlyingType(context.Type)?.IsEnum ?? false))
 21        {
 34422            var type = context.Type.IsEnum ? context.Type : Nullable.GetUnderlyingType(context.Type);
 34423            if (type is null)
 24            {
 025                return;
 26            }
 27
 34428            var enumOpenApiStrings = new List<IOpenApiAny>();
 29
 790830            foreach (var enumName in Enum.GetNames(type))
 31            {
 361032                var member = type.GetMember(enumName)[0];
 361033                if (!member.GetCustomAttributes<OpenApiIgnoreEnumAttribute>().Any())
 34                {
 355035                    enumOpenApiStrings.Add(new OpenApiString(enumName));
 36                }
 37            }
 38
 34439            schema.Enum = enumOpenApiStrings;
 40        }
 501841    }
 42}