aboutsummaryrefslogtreecommitdiff
path: root/BackEnd/Timeline/Swagger/OpenApiServiceCollectionExtensions.cs
blob: e1266d7a63f4320cc367a8ea953f944994bf61a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using Microsoft.Extensions.DependencyInjection;
using NSwag;
using NSwag.Generation.Processors.Security;

namespace Timeline.Swagger
{
    public static class OpenApiServiceCollectionExtensions
    {
        public static void AddOpenApiDocs(this IServiceCollection services)
        {
            services.AddSwaggerDocument(document =>
            {
                document.DocumentName = "Timeline";
                document.Title = "Timeline REST API Reference";
                document.Version = typeof(Startup).Assembly.GetName().Version?.ToString() ?? "unknown version";
                document.DocumentProcessors.Add(new DocumentDescriptionDocumentProcessor());
                document.DocumentProcessors.Add(
                    new SecurityDefinitionAppender("JWT",
                    new OpenApiSecurityScheme
                    {
                        Type = OpenApiSecuritySchemeType.ApiKey,
                        Name = "Authorization",
                        In = OpenApiSecurityApiKeyLocation.Header,
                        Description = "Create token via `/api/token/create` ."
                    }));
                document.OperationProcessors.Add(new AspNetCoreOperationSecurityScopeProcessor("JWT"));
                document.OperationProcessors.Add(new DefaultDescriptionOperationProcessor());
                document.OperationProcessors.Add(new ByteDataRequestOperationProcessor());
            });
        }
    }
}