11using KurrentDB . Client ;
22using Microsoft . Extensions . Logging ;
33using Microsoft . OpenApi ;
4+ using Shared . Extensions ;
5+ using Swashbuckle . AspNetCore . SwaggerGen ;
46
57namespace CallbackHandler . Bootstrapper ;
68
@@ -32,40 +34,10 @@ public MiddlewareRegistry()
3234 String connectionString = Startup . Configuration . GetValue < String > ( "EventStoreSettings:ConnectionString" ) ;
3335 KurrentDBClientSettings eventStoreSettings = KurrentDBClientSettings . Create ( connectionString ) ;
3436
35- this . AddHealthChecks ( ) . AddEventStore ( eventStoreSettings ,
36- userCredentials : eventStoreSettings . DefaultCredentials ,
37- name : "Eventstore" ,
38- failureStatus : HealthStatus . Unhealthy ,
39- tags : new [ ] { "db" , "eventstore" } ) ;
37+ this . AddHealthChecks ( ) . AddEventStore ( eventStoreSettings , userCredentials : eventStoreSettings . DefaultCredentials ,
38+ name : "Eventstore" , failureStatus : HealthStatus . Unhealthy , tags : new [ ] { "db" , "eventstore" } ) ;
4039
41- this . AddSwaggerGen ( c =>
42- {
43- c . SwaggerDoc ( "v1" , new OpenApiInfo
44- {
45- Title = "Callback Handler API" ,
46- Version = "1.0" ,
47- Description = "A REST Api to handle callback requests from external parties API's." ,
48- Contact = new OpenApiContact
49- {
50- Name = "Stuart Ferguson" ,
51- Email = "golfhandicapping@btinternet.com"
52- }
53- } ) ;
54- // add a custom operation filter which sets default values
55- c . OperationFilter < SwaggerDefaultValues > ( ) ;
56- c . ExampleFilters ( ) ;
57-
58- //Locate the XML files being generated by ASP.NET...
59- DirectoryInfo directory = new ( AppContext . BaseDirectory ) ;
60- FileInfo [ ] xmlFiles = directory . GetFiles ( "*.xml" ) ;
61-
62- //... and tell Swagger to use those XML comments.
63- foreach ( FileInfo fileInfo in xmlFiles )
64- {
65- c . IncludeXmlComments ( fileInfo . FullName ) ;
66- }
67-
68- } ) ;
40+ this . AddSwaggerGen ( AddSwaggerAction ) ;
6941 this . AddSwaggerExamples ( ) ;
7042
7143 this . AddControllers ( ) . AddNewtonsoftJson ( options =>
@@ -83,16 +55,28 @@ public MiddlewareRegistry()
8355 bool logRequests = ConfigurationReader . GetValueOrDefault < Boolean > ( "MiddlewareLogging" , "LogRequests" , true ) ;
8456 bool logResponses = ConfigurationReader . GetValueOrDefault < Boolean > ( "MiddlewareLogging" , "LogResponses" , true ) ;
8557 LogLevel middlewareLogLevel = ConfigurationReader . GetValueOrDefault < LogLevel > ( "MiddlewareLogging" , "MiddlewareLogLevel" , LogLevel . Warning ) ;
58+
59+ this . AddSingleton ( new RequestResponseMiddlewareLoggingConfig ( middlewareLogLevel , logRequests , logResponses ) ) ;
8660
87- RequestResponseMiddlewareLoggingConfig config =
88- new ( middlewareLogLevel , logRequests , logResponses ) ;
89-
90- this . AddSingleton ( config ) ;
91-
92- this . ConfigureHttpJsonOptions ( options =>
93- {
61+ this . ConfigureHttpJsonOptions ( options => {
9462 options . SerializerOptions . PropertyNamingPolicy = new SnakeCaseNamingPolicy ( ) ;
9563 options . SerializerOptions . PropertyNameCaseInsensitive = true ; // optional, but safer
9664 } ) ;
9765 }
66+
67+ private void AddSwaggerAction ( SwaggerGenOptions c ) {
68+ c . SwaggerDoc ( "v1" , new OpenApiInfo { Title = "Callback Handler API" , Version = "1.0" , Description = "A REST Api to handle callback requests from external parties API's." , Contact = new OpenApiContact { Name = "Stuart Ferguson" , Email = "golfhandicapping@btinternet.com" } } ) ;
69+ // add a custom operation filter which sets default values
70+ c . OperationFilter < SwaggerDefaultValues > ( ) ;
71+ c . ExampleFilters ( ) ;
72+
73+ //Locate the XML files being generated by ASP.NET...
74+ DirectoryInfo directory = new ( AppContext . BaseDirectory ) ;
75+ FileInfo [ ] xmlFiles = directory . GetFiles ( "*.xml" ) ;
76+
77+ //... and tell Swagger to use those XML comments.
78+ foreach ( FileInfo fileInfo in xmlFiles ) {
79+ c . IncludeXmlComments ( fileInfo . FullName ) ;
80+ }
81+ }
9882}
0 commit comments