< Summary - ZhEaIsNsAaBn.Libraries coverage (affected: 23 packages)

Information
Class: ZhEaIsNsAaBn.Utilities.Swagger.SwaggerSchemaExampleFilter
Assembly: ZhEaIsNsAaBn.Utilities.Swagger
File(s): /home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/UtilitiesPackages/ZhEaIsNsAaBn.Utilities.Swagger/Swagger/SwaggerSchemaExampleFilter.cs
Line coverage
100%
Covered lines: 7
Uncovered lines: 0
Coverable lines: 7
Total lines: 37
Line coverage: 100%
Branch coverage
78%
Covered branches: 11
Total branches: 14
Branch coverage: 78.5%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
Apply(...)78.57%1414100%

File(s)

/home/runner/work/ZhEaIsNsAaBn.Libraries.V1/ZhEaIsNsAaBn.Libraries.V1/src/UtilitiesPackages/ZhEaIsNsAaBn.Utilities.Swagger/Swagger/SwaggerSchemaExampleFilter.cs

#LineLine coverage
 1#region Usings
 2using System.Reflection;
 3using Microsoft.OpenApi.Any;
 4using Microsoft.OpenApi.Models;
 5using Swashbuckle.AspNetCore.SwaggerGen;
 6#endregion
 7
 8namespace ZhEaIsNsAaBn.Utilities.Swagger;
 9
 10/// <summary>Swashbuckle schema filter that copies <see cref="SwaggerSchemaExampleAttribute.Example"/> into the OpenAPI 
 11/// <example>
 12/// <code>
 13/// services.AddSwaggerGen( options => options.SchemaFilter&lt;SwaggerSchemaExampleFilter&gt;() );
 14/// </code>
 15/// </example>
 16public sealed class SwaggerSchemaExampleFilter : ISchemaFilter
 17{
 18    /// <summary>
 19    /// Sets <see cref="OpenApiSchema.Example"/> from the attribute on the property, else the parameter, else the schema
 20    /// </summary>
 21    /// <param name="schema">The schema being generated.</param>
 22    /// <param name="context">The Swashbuckle context for the schema.</param>
 23    /// <exception cref="ArgumentNullException"><paramref name="schema"/> or <paramref name="context"/> is <see langword
 24    public void Apply( OpenApiSchema schema, SchemaFilterContext context )
 25    {
 7226        ArgumentNullException.ThrowIfNull( schema );
 7227        ArgumentNullException.ThrowIfNull( context );
 28
 29
 7230        var attribute = context.MemberInfo?.GetCustomAttribute<SwaggerSchemaExampleAttribute>()
 7231                     ?? context.ParameterInfo?.GetCustomAttribute<SwaggerSchemaExampleAttribute>()
 7232                     ?? context.Type?.GetCustomAttribute<SwaggerSchemaExampleAttribute>();
 33
 34
 11635        if ( attribute?.Example is not null ) { schema.Example = new OpenApiString( attribute.Example ); }
 7236    }
 37}