< Summary - Syki

Information
Class: Syki.Back.Filters.AuthOperationsFilter
Assembly: Back
File(s): /home/runner/work/syki/syki/Back/Filters/AuthOperationsFilter.cs
Tag: 4_16869239191
Line coverage
0%
Covered lines: 0
Uncovered lines: 21
Coverable lines: 21
Total lines: 34
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Apply(...)0%620%

File(s)

/home/runner/work/syki/syki/Back/Filters/AuthOperationsFilter.cs

#LineLine coverage
 1using Microsoft.OpenApi.Models;
 2using Swashbuckle.AspNetCore.SwaggerGen;
 3
 4namespace Syki.Back.Filters;
 5
 6public class AuthOperationsFilter : IOperationFilter
 7{
 8    public void Apply(OpenApiOperation operation, OperationFilterContext context)
 9    {
 010        var authAttributes = context.MethodInfo.DeclaringType.GetCustomAttributes(true)
 011            .Union(context.MethodInfo.GetCustomAttributes(true))
 012            .OfType<AuthorizeAttribute>();
 13
 014        if (authAttributes.Any())
 15        {
 016            var securityRequirement = new OpenApiSecurityRequirement()
 017            {
 018                {
 019                    new OpenApiSecurityScheme
 020                    {
 021                        Reference = new OpenApiReference
 022                        {
 023                            Type = ReferenceType.SecurityScheme,
 024                            Id = "Bearer",
 025                        }
 026                    },
 027                    new string[] {}
 028                }
 029            };
 030            operation.Security = [securityRequirement];
 031            operation.Responses.Add("401", new OpenApiResponse { Description = "Unauthorized" });
 32        }
 033    }
 34}