| | | 1 | | using Elsa.Features.Services; |
| | | 2 | | using FastEndpoints.Swagger; |
| | | 3 | | using Microsoft.AspNetCore.Builder; |
| | | 4 | | |
| | | 5 | | namespace 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 | | { |
| | 0 | 17 | | Version ver = new(3, 0); |
| | | 18 | | |
| | | 19 | | // Swagger API documentation |
| | 0 | 20 | | module.Services.SwaggerDocument(o => |
| | 0 | 21 | | { |
| | 0 | 22 | | o.EnableJWTBearerAuth = true; |
| | 0 | 23 | | o.DocumentSettings = s => |
| | 0 | 24 | | { |
| | 0 | 25 | | s.DocumentName = $"v{ver.Major}"; |
| | 0 | 26 | | s.Title = "Elsa API"; |
| | 0 | 27 | | s.Version = $"v{ver.Major}.{ver.Minor}"; |
| | 0 | 28 | | s.AddAuth("ApiKey", new() |
| | 0 | 29 | | { |
| | 0 | 30 | | Name = "Authorization", |
| | 0 | 31 | | In = NSwag.OpenApiSecurityApiKeyLocation.Header, |
| | 0 | 32 | | Type = NSwag.OpenApiSecuritySchemeType.ApiKey, |
| | 0 | 33 | | Description = "Enter: ApiKey [your API key]" |
| | 0 | 34 | | }); |
| | 0 | 35 | | }; |
| | 0 | 36 | | }); |
| | | 37 | | |
| | 0 | 38 | | 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 | | { |
| | 1 | 46 | | return app.UseSwaggerGen(); |
| | | 47 | | } |
| | | 48 | | |
| | | 49 | | } |
| | | 50 | | } |