2
2
using System . Linq ;
3
3
using ArchitectNow . Web . Models ;
4
4
using Microsoft . AspNetCore . Builder ;
5
- using Microsoft . AspNetCore . Hosting ;
6
5
using Microsoft . Extensions . Logging ;
7
6
using NJsonSchema ;
8
7
using NSwag . AspNetCore ;
9
8
using NSwag . SwaggerGeneration . WebApi ;
10
9
11
10
namespace ArchitectNow . Web . Configuration
12
11
{
13
- public class SwaggerStartupFilter : IStartupFilter
12
+ public class SwaggerV2StartupFilter : SwaggerStartupBase < SwaggerOptionsV2 , SwaggerUiSettings < WebApiToSwaggerGeneratorSettings > >
14
13
{
15
- private readonly ILogger < SwaggerStartupFilter > _logger ;
16
- protected SwaggerOptions [ ] Options { get ; }
14
+ private readonly ILogger < SwaggerV2StartupFilter > _logger ;
15
+ protected SwaggerOptionsV2 [ ] Options { get ; }
17
16
18
- public SwaggerStartupFilter ( ILogger < SwaggerStartupFilter > logger , params SwaggerOptions [ ] options )
17
+ public SwaggerV2StartupFilter ( ILogger < SwaggerV2StartupFilter > logger , params SwaggerOptionsV2 [ ] options )
19
18
{
20
19
_logger = logger ;
21
20
Options = options ;
22
21
}
23
22
24
- public Action < IApplicationBuilder > Configure ( Action < IApplicationBuilder > next )
23
+ public override Action < IApplicationBuilder > Configure ( Action < IApplicationBuilder > next )
25
24
{
26
25
return builder =>
27
26
{
28
- _logger . LogInformation ( $ "Configure Start: { nameof ( SwaggerStartupFilter ) } ") ;
27
+ _logger . LogInformation ( $ "Configure Start: { nameof ( SwaggerV2StartupFilter ) } ") ;
29
28
30
29
foreach ( var option in Options )
31
30
{
@@ -44,30 +43,29 @@ public Action<IApplicationBuilder> Configure(Action<IApplicationBuilder> next)
44
43
}
45
44
46
45
next ( builder ) ;
47
- _logger . LogInformation ( $ "Configure End: { nameof ( SwaggerStartupFilter ) } ") ;
46
+ _logger . LogInformation ( $ "Configure End: { nameof ( SwaggerV2StartupFilter ) } ") ;
48
47
} ;
49
48
}
50
49
51
- private void ConfigureSettings ( SwaggerUiSettings < WebApiToSwaggerGeneratorSettings > settings , SwaggerOptions option )
50
+ protected override void ConfigureSettings ( SwaggerUiSettings < WebApiToSwaggerGeneratorSettings > settings , SwaggerOptionsV2 optionV2 )
52
51
{
53
- settings . SwaggerRoute = option . SwaggerRoute ;
54
- settings . SwaggerUiRoute = option . SwaggerUiRoute ;
55
- settings . UseJsonEditor = true ;
52
+ settings . SwaggerRoute = optionV2 . SwaggerRoute ;
53
+ settings . SwaggerUiRoute = optionV2 . SwaggerUiRoute ;
56
54
settings . GeneratorSettings . DefaultPropertyNameHandling = PropertyNameHandling . CamelCase ;
57
- settings . GeneratorSettings . Title = option . Title ;
55
+ settings . GeneratorSettings . Title = optionV2 . Title ;
58
56
settings . GeneratorSettings . FlattenInheritanceHierarchy = true ;
59
57
settings . GeneratorSettings . IsAspNetCore = true ;
60
-
61
- foreach ( var optionDocumentProcessor in option . DocumentProcessors )
58
+
59
+ foreach ( var optionDocumentProcessor in optionV2 . DocumentProcessors )
62
60
{
63
61
settings . GeneratorSettings . DocumentProcessors . Add ( optionDocumentProcessor ) ;
64
62
}
65
63
66
- foreach ( var operationProcessor in option . OperationProcessors )
64
+ foreach ( var operationProcessor in optionV2 . OperationProcessors )
67
65
{
68
66
settings . GeneratorSettings . OperationProcessors . Add ( operationProcessor ) ;
69
67
}
70
- var action = option . Configure ;
68
+ var action = optionV2 . Configure ;
71
69
action ? . Invoke ( settings ) ;
72
70
}
73
71
}
0 commit comments