-
Notifications
You must be signed in to change notification settings - Fork 97
/
Copy pathSwaggerConfig.cs
46 lines (41 loc) · 1.71 KB
/
SwaggerConfig.cs
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
using Microsoft.Extensions.DependencyInjection;
using NSwag;
using NSwag.Generation.Processors.Security;
using ZymLabs.NSwag.FluentValidation;
namespace CleanArchitectureCosmosDB.WebAPI.Config
{
/// <summary>
/// Swagger
/// </summary>
public static class SwaggerConfig
{
/// <summary>
/// NSwag for swagger
/// </summary>
/// <param name="services"></param>
public static void SetupNSwag(this IServiceCollection services)
{
// Register the Swagger services
services.AddOpenApiDocument((options, serviceProvider) =>
{
options.DocumentName = "v1";
options.Title = "Clean Architecture Cosmos DB API";
options.Version = "v1";
FluentValidationSchemaProcessor fluentValidationSchemaProcessor = serviceProvider.GetService<FluentValidationSchemaProcessor>();
// Add the fluent validations schema processor
options.SchemaProcessors.Add(fluentValidationSchemaProcessor);
// Add JWT token authorization
options.OperationProcessors.Add(new OperationSecurityScopeProcessor("auth"));
options.DocumentProcessors.Add(new SecurityDefinitionAppender("auth", new OpenApiSecurityScheme
{
Type = OpenApiSecuritySchemeType.Http,
In = OpenApiSecurityApiKeyLocation.Header,
Scheme = "bearer",
BearerFormat = "jwt"
}));
});
// Add the FluentValidationSchemaProcessor as a singleton
services.AddSingleton<FluentValidationSchemaProcessor>();
}
}
}