< Summary

Information
Class: Elsa.Extensions.SwaggerExtensions
Assembly: Elsa.Api.Common
File(s): /home/runner/work/elsa-core/elsa-core/src/common/Elsa.Api.Common/Extensions/SwaggerExtensions.cs
Line coverage
5%
Covered lines: 1
Uncovered lines: 19
Coverable lines: 20
Total lines: 50
Line coverage: 5%
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
AddSwagger(...)0%620%
UseSwaggerUI(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/common/Elsa.Api.Common/Extensions/SwaggerExtensions.cs

#LineLine coverage
 1using Elsa.Features.Services;
 2using FastEndpoints.Swagger;
 3using Microsoft.AspNetCore.Builder;
 4
 5namespace Elsa.Extensions
 6{
 7    /// <summary>
 8    /// Extensions to enable the generation of Swagger API Documentation and associated Swagger UI.
 9    /// </summary>
 10    public static class SwaggerExtensions
 11    {
 12        /// <summary>
 13        /// Registers Swagger document generator.
 14        /// </summary>
 15        public static IModule AddSwagger(this IModule module)
 16        {
 017            Version ver = new(3, 0);
 18
 19            // Swagger API documentation
 020            module.Services.SwaggerDocument(o =>
 021            {
 022                o.EnableJWTBearerAuth = true;
 023                o.DocumentSettings = s =>
 024                {
 025                    s.DocumentName = $"v{ver.Major}";
 026                    s.Title = "Elsa API";
 027                    s.Version = $"v{ver.Major}.{ver.Minor}";
 028                    s.AddAuth("ApiKey", new()
 029                    {
 030                        Name = "Authorization",
 031                        In = NSwag.OpenApiSecurityApiKeyLocation.Header,
 032                        Type = NSwag.OpenApiSecuritySchemeType.ApiKey,
 033                        Description = "Enter: ApiKey [your API key]"
 034                    });
 035                };
 036            });
 37
 038            return module;
 39        }
 40
 41        /// <summary>
 42        /// Adds middleware to enable the Swagger UI at '/swagger'
 43        /// </summary>
 44        public static IApplicationBuilder UseSwaggerUI(this IApplicationBuilder app)
 45        {
 146            return app.UseSwaggerGen();
 47        }
 48
 49    }
 50}