< Summary - Jellyfin

Information
Class: Jellyfin.Server.Filters.SecuritySchemeReferenceFixupFilter
Assembly: jellyfin
File(s): /srv/git/jellyfin/Jellyfin.Server/Filters/SecuritySchemeReferenceFixupFilter.cs
Line coverage
93%
Covered lines: 14
Uncovered lines: 1
Coverable lines: 15
Total lines: 56
Line coverage: 93.3%
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 2/27/2026 - 12:13:29 AM Line coverage: 93.3% (14/15) Branch coverage: 92.8% (13/14) Total lines: 56 2/27/2026 - 12:13:29 AM Line coverage: 93.3% (14/15) Branch coverage: 92.8% (13/14) Total lines: 56

Metrics

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

File(s)

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

#LineLine coverage
 1using Microsoft.OpenApi;
 2using Swashbuckle.AspNetCore.SwaggerGen;
 3
 4namespace Jellyfin.Server.Filters;
 5
 6/// <summary>
 7/// Document filter that fixes security scheme references after document generation.
 8/// </summary>
 9/// <remarks>
 10/// In Microsoft.OpenApi v2, <see cref="OpenApiSecuritySchemeReference"/> requires a resolved
 11/// <c>Target</c> to serialize correctly. References created without a host document (as in
 12/// operation filters) serialize as empty objects. This filter re-creates all security scheme
 13/// references with the document context so they resolve properly during serialization.
 14/// </remarks>
 15internal class SecuritySchemeReferenceFixupFilter : IDocumentFilter
 16{
 17    /// <inheritdoc />
 18    public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
 19    {
 120        swaggerDoc.RegisterComponents();
 21
 122        if (swaggerDoc.Paths is null)
 23        {
 024            return;
 25        }
 26
 63027        foreach (var pathItem in swaggerDoc.Paths.Values)
 28        {
 31429            if (pathItem.Operations is null)
 30            {
 31                continue;
 32            }
 33
 140234            foreach (var operation in pathItem.Operations.Values)
 35            {
 38736                if (operation.Security is null)
 37                {
 38                    continue;
 39                }
 40
 131241                for (int i = 0; i < operation.Security.Count; i++)
 42                {
 32843                    var oldReq = operation.Security[i];
 32844                    var newReq = new OpenApiSecurityRequirement();
 131245                    foreach (var kvp in oldReq)
 46                    {
 32847                        var fixedRef = new OpenApiSecuritySchemeReference(kvp.Key.Reference.Id!, swaggerDoc);
 32848                        newReq[fixedRef] = kvp.Value;
 49                    }
 50
 32851                    operation.Security[i] = newReq;
 52                }
 53            }
 54        }
 155    }
 56}