-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathSwaggerRegistration.cs
47 lines (42 loc) · 1.92 KB
/
SwaggerRegistration.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
47
using System.Diagnostics.CodeAnalysis;
using System.IO;
using HappyCode.NetCoreBoilerplate.Api.Infrastructure.Filters;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;
namespace HappyCode.NetCoreBoilerplate.Api.Infrastructure.Registrations
{
[ExcludeFromCodeCoverage]
public static class SwaggerRegistration
{
public static void AddSwagger(this IServiceCollection services, IConfiguration configuration)
{
string secretKey = configuration.GetValue<string>("ApiKey:SecretKey");
services.AddSwaggerGen(swaggerOptions =>
{
swaggerOptions.SwaggerDoc("v1", new OpenApiInfo
{
Title = "Simple Api",
Version = "v1",
Description = $"ApiKey {secretKey}",
Contact = new OpenApiContact
{
Name = "Łukasz Kurzyniec",
Url = new Uri("https://kurzyniec.pl/"),
}
});
swaggerOptions.OrderActionsBy(x => x.RelativePath);
swaggerOptions.IncludeXmlComments(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "HappyCode.NetCoreBoilerplate.Api.xml"));
swaggerOptions.AddSecurityDefinition("ApiKey", new OpenApiSecurityScheme
{
Description = "ApiKey needed to access the endpoints (eg: `Authorization: ApiKey xxx-xxx`)",
In = ParameterLocation.Header,
Name = "Authorization",
Type = SecuritySchemeType.ApiKey,
});
swaggerOptions.OperationFilter<SecurityRequirementSwaggerOperationFilter>();
swaggerOptions.DocumentFilter<FeatureFlagSwaggerDocumentFilter>();
});
}
}
}