|
6 | 6 | using Swashbuckle.AspNetCore.SwaggerGen; |
7 | 7 |
|
8 | 8 | // ReSharper disable once CheckNamespace |
9 | | -namespace Swashbuckle.Servers.Extension |
| 9 | +#pragma warning disable IDE0130 // Namespace does not match folder structure |
| 10 | +namespace Swashbuckle.Servers.Extension; |
| 11 | +#pragma warning restore IDE0130 // Namespace does not match folder structure |
| 12 | + |
| 13 | +public static class SwaggerGenOptionsExtensions |
10 | 14 | { |
11 | | - public static class SwaggerGenOptionsExtensions |
| 15 | + public static SwaggerGenOptions WithServers(this SwaggerGenOptions swaggerGenOptions, Action<ServersOptions> setupAction) |
12 | 16 | { |
13 | | - public static SwaggerGenOptions WithServers(this SwaggerGenOptions swaggerGenOptions, Action<ServersOptions> setupAction) |
14 | | - { |
15 | | - var options = new ServersOptions(); |
| 17 | + var options = new ServersOptions(); |
16 | 18 |
|
17 | | - setupAction.Invoke(options); |
| 19 | + setupAction.Invoke(options); |
18 | 20 |
|
19 | | - swaggerGenOptions.AddOrUpdate(options); |
| 21 | + swaggerGenOptions.AddOrUpdate(options); |
20 | 22 |
|
21 | | - return swaggerGenOptions; |
22 | | - } |
| 23 | + return swaggerGenOptions; |
| 24 | + } |
23 | 25 |
|
24 | | - public static SwaggerGenOptions WithServers(this SwaggerGenOptions swaggerGenOptions, IEnumerable<OpenApiServer> servers) |
25 | | - { |
26 | | - var options = new ServersOptions { Servers = servers }; |
| 26 | + public static SwaggerGenOptions WithServers(this SwaggerGenOptions swaggerGenOptions, IEnumerable<OpenApiServer> servers) |
| 27 | + { |
| 28 | + var options = new ServersOptions { Servers = servers }; |
27 | 29 |
|
28 | | - swaggerGenOptions.AddOrUpdate(options); |
| 30 | + swaggerGenOptions.AddOrUpdate(options); |
29 | 31 |
|
30 | | - return swaggerGenOptions; |
31 | | - } |
| 32 | + return swaggerGenOptions; |
| 33 | + } |
| 34 | + |
| 35 | + private static void AddOrUpdate(this SwaggerGenOptions swaggerGenOptions, ServersOptions options) |
| 36 | + { |
| 37 | + var filter = swaggerGenOptions |
| 38 | + .DocumentFilterDescriptors |
| 39 | + .Find(x => x.Type == typeof(ServersDocumentFilter)); |
32 | 40 |
|
33 | | - private static void AddOrUpdate(this SwaggerGenOptions swaggerGenOptions, ServersOptions options) |
| 41 | + if (filter != null) |
| 42 | + { |
| 43 | + var existingOptions = (ServersOptions) filter.Arguments[0]; |
| 44 | + |
| 45 | + existingOptions.Servers = existingOptions.Servers.Concat(options.Servers); |
| 46 | + } |
| 47 | + else |
34 | 48 | { |
35 | | - var filter = swaggerGenOptions |
36 | | - .DocumentFilterDescriptors |
37 | | - .Find(x => x.Type == typeof(ServersDocumentFilter)); |
38 | | - |
39 | | - if (filter != null) |
40 | | - { |
41 | | - var existingOptions = (ServersOptions) filter.Arguments[0]; |
42 | | - |
43 | | - existingOptions.Servers = existingOptions.Servers.Concat(options.Servers); |
44 | | - } |
45 | | - else |
46 | | - { |
47 | | - swaggerGenOptions.DocumentFilter<ServersDocumentFilter>(options); |
48 | | - } |
| 49 | + swaggerGenOptions.DocumentFilter<ServersDocumentFilter>(options); |
49 | 50 | } |
50 | 51 | } |
51 | 52 | } |
0 commit comments