11using System . Net ;
22using System . Reflection ;
3- using System . Text . Json . Serialization ;
43using System . Threading . RateLimiting ;
54using Intersect . Core ;
65using Intersect . Enums ;
76using Intersect . Framework . Reflection ;
87using Intersect . Logging ;
9- using Intersect . Models ;
108using Intersect . Server . Core ;
11- using Intersect . Server . Localization ;
129using Intersect . Server . Web . Authentication ;
1310using Intersect . Server . Web . Configuration ;
1411using Intersect . Server . Web . Constraints ;
3330using Microsoft . Extensions . Hosting ;
3431using Microsoft . IdentityModel . Logging ;
3532using Microsoft . IdentityModel . Tokens ;
36- using Microsoft . OpenApi . Any ;
3733using Microsoft . OpenApi . Models ;
3834using Newtonsoft . Json . Converters ;
35+ #pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
3936
4037namespace Intersect . Server . Web ;
4138
@@ -44,6 +41,7 @@ internal partial class ApiService : ApplicationService<ServerContext, IApiServic
4441 private WebApplication ? _app ;
4542 private static readonly Assembly Assembly = typeof ( ApiService ) . Assembly ;
4643
44+ // ReSharper disable once MemberCanBeMadeStatic.Local
4745 private WebApplication ? Configure ( )
4846 {
4947 UnpackAppSettings ( ) ;
@@ -59,7 +57,7 @@ internal partial class ApiService : ApplicationService<ServerContext, IApiServic
5957 // I can't get System.Text.Json to deserialize an array as non-null, and it totally ignores
6058 // the JsonConverter attribute I tried putting on it, so I am just giving up and doing this
6159 // to make sure the array is not null in the event that it is empty.
62- configuration . StaticFilePaths ??= new List < StaticFilePathOptions > ( ) ;
60+ configuration . StaticFilePaths ??= [ ] ;
6361
6462 if ( ! configuration . Enabled )
6563 {
@@ -99,40 +97,32 @@ internal partial class ApiService : ApplicationService<ServerContext, IApiServic
9997 "client_per_second" ,
10098 context => RateLimitPartition . GetSlidingWindowLimiter (
10199 partitionKey : context . User . Identity ? . Name ?? "__no_api_key__" ,
102- factory : partition => new SlidingWindowRateLimiterOptions
100+ factory : _ => new SlidingWindowRateLimiterOptions
103101 {
104102 AutoReplenishment = true ,
105103 PermitLimit = 5 ,
106104 QueueLimit = 0 ,
107- Window = TimeSpan . FromMinutes ( 1 )
105+ Window = TimeSpan . FromMinutes ( 1 ) ,
108106 }
109107 )
110108 ) ;
111109 rateLimiterOptions . AddPolicy (
112110 "client_per_minute" ,
113111 context => RateLimitPartition . GetSlidingWindowLimiter (
114112 partitionKey : context . User . Identity ? . Name ?? "__no_api_key__" ,
115- factory : partition => new SlidingWindowRateLimiterOptions
113+ factory : _ => new SlidingWindowRateLimiterOptions
116114 {
117115 AutoReplenishment = true ,
118116 PermitLimit = 1 ,
119117 QueueLimit = 0 ,
120- Window = TimeSpan . FromSeconds ( 1 )
118+ Window = TimeSpan . FromSeconds ( 1 ) ,
121119 }
122120 )
123121 ) ;
124122 }
125123 ) ;
126124
127- builder . Services . AddControllers (
128- mvcOptions =>
129- {
130- mvcOptions . FormatterMappings . ClearMediaTypeMappingForFormat ( "application/xml" ) ;
131- mvcOptions . FormatterMappings . ClearMediaTypeMappingForFormat ( "text/xml" ) ;
132- mvcOptions . FormatterMappings . ClearMediaTypeMappingForFormat ( "text/json" ) ;
133- mvcOptions . FormatterMappings . ClearMediaTypeMappingForFormat ( "application/xml" ) ;
134- }
135- )
125+ builder . Services . AddControllers ( )
136126 . AddNewtonsoftJson (
137127 newtonsoftOptions =>
138128 {
@@ -141,14 +131,12 @@ internal partial class ApiService : ApplicationService<ServerContext, IApiServic
141131 newtonsoftOptions . SerializerSettings . Converters . Add ( new StringEnumConverter ( ) ) ;
142132 }
143133 )
144- . AddOData (
145- options =>
134+ . AddFormatterMappings (
135+ formatterMappings =>
146136 {
147- options . Count ( ) . Select ( ) . OrderBy ( ) ;
148- options . RouteOptions . EnableKeyInParenthesis = false ;
149- options . RouteOptions . EnableNonParenthesisForEmptyParameterFunction = true ;
150- options . RouteOptions . EnableQualifiedOperationCall = false ;
151- options . RouteOptions . EnableUnqualifiedOperationCall = true ;
137+ formatterMappings . ClearMediaTypeMappingForFormat ( "application/xml" ) ;
138+ formatterMappings . ClearMediaTypeMappingForFormat ( "text/xml" ) ;
139+ formatterMappings . ClearMediaTypeMappingForFormat ( "text/json" ) ;
152140 }
153141 ) ;
154142
@@ -263,10 +251,10 @@ internal partial class ApiService : ApplicationService<ServerContext, IApiServic
263251 options . TokenValidationParameters . ValidIssuer ??= tokenGenerationOptions . Issuer ;
264252 options . Events = new JwtBearerEvents
265253 {
266- OnAuthenticationFailed = async context => { } ,
267- OnChallenge = async context => { } ,
268- OnMessageReceived = async context => { } ,
269- OnTokenValidated = async context => { } ,
254+ OnAuthenticationFailed = async _ => { } ,
255+ OnChallenge = async _ => { } ,
256+ OnMessageReceived = async _ => { } ,
257+ OnTokenValidated = async _ => { } ,
270258 } ;
271259 SymmetricSecurityKey issuerKey = new ( tokenGenerationOptions . SecretData ) ;
272260 options . TokenValidationParameters . IssuerSigningKey = issuerKey ;
0 commit comments