@@ -285,6 +285,265 @@ private string ConvertToString(object? value, System.Globalization.CultureInfo c
285
285
}
286
286
}
287
287
288
+ [ System . CodeDom . Compiler . GeneratedCode ( "NSwag" , "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))" ) ]
289
+ public partial class GetProjectClient : IGetProjectClient
290
+ {
291
+ #pragma warning disable 8618
292
+ private string _baseUrl ;
293
+ #pragma warning restore 8618
294
+
295
+ private System . Net . Http . HttpClient _httpClient ;
296
+ private static System . Lazy < Newtonsoft . Json . JsonSerializerSettings > _settings = new System . Lazy < Newtonsoft . Json . JsonSerializerSettings > ( CreateSerializerSettings , true ) ;
297
+ private Newtonsoft . Json . JsonSerializerSettings _instanceSettings ;
298
+
299
+ #pragma warning disable CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
300
+ public GetProjectClient ( string baseUrl , System . Net . Http . HttpClient httpClient )
301
+ #pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.
302
+ {
303
+ BaseUrl = baseUrl ;
304
+ _httpClient = httpClient ;
305
+ Initialize ( ) ;
306
+ }
307
+
308
+ private static Newtonsoft . Json . JsonSerializerSettings CreateSerializerSettings ( )
309
+ {
310
+ var settings = new Newtonsoft . Json . JsonSerializerSettings ( ) ;
311
+ UpdateJsonSerializerSettings ( settings ) ;
312
+ return settings ;
313
+ }
314
+
315
+ public string BaseUrl
316
+ {
317
+ get { return _baseUrl ; }
318
+ set
319
+ {
320
+ _baseUrl = value ;
321
+ if ( ! string . IsNullOrEmpty ( _baseUrl ) && ! _baseUrl . EndsWith ( "/" ) )
322
+ _baseUrl += '/' ;
323
+ }
324
+ }
325
+
326
+ protected Newtonsoft . Json . JsonSerializerSettings JsonSerializerSettings { get { return _instanceSettings ?? _settings . Value ; } }
327
+
328
+ static partial void UpdateJsonSerializerSettings ( Newtonsoft . Json . JsonSerializerSettings settings ) ;
329
+
330
+ partial void Initialize ( ) ;
331
+
332
+ partial void PrepareRequest ( System . Net . Http . HttpClient client , System . Net . Http . HttpRequestMessage request , string url ) ;
333
+ partial void PrepareRequest ( System . Net . Http . HttpClient client , System . Net . Http . HttpRequestMessage request , System . Text . StringBuilder urlBuilder ) ;
334
+ partial void ProcessResponse ( System . Net . Http . HttpClient client , System . Net . Http . HttpResponseMessage response ) ;
335
+
336
+ /// <summary>
337
+ /// Gets a Project
338
+ /// </summary>
339
+ /// <param name="request">The request.</param>
340
+ /// <returns>Project</returns>
341
+ /// <exception cref="PersonsApiException">A server side error occurred.</exception>
342
+ public virtual System . Threading . Tasks . Task < Project > Projects_GetProject_Async ( GetProjectByUrnQuery request )
343
+ {
344
+ return Projects_GetProject_Async ( request , System . Threading . CancellationToken . None ) ;
345
+ }
346
+
347
+ /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
348
+ /// <summary>
349
+ /// Gets a Project
350
+ /// </summary>
351
+ /// <param name="request">The request.</param>
352
+ /// <returns>Project</returns>
353
+ /// <exception cref="PersonsApiException">A server side error occurred.</exception>
354
+ public virtual async System . Threading . Tasks . Task < Project > Projects_GetProject_Async ( GetProjectByUrnQuery request , System . Threading . CancellationToken cancellationToken )
355
+ {
356
+ if ( request == null )
357
+ throw new System . ArgumentNullException ( "request" ) ;
358
+
359
+ var client_ = _httpClient ;
360
+ var disposeClient_ = false ;
361
+ try
362
+ {
363
+ using ( var request_ = new System . Net . Http . HttpRequestMessage ( ) )
364
+ {
365
+ var json_ = Newtonsoft . Json . JsonConvert . SerializeObject ( request , JsonSerializerSettings ) ;
366
+ var content_ = new System . Net . Http . StringContent ( json_ ) ;
367
+ content_ . Headers . ContentType = System . Net . Http . Headers . MediaTypeHeaderValue . Parse ( "application/json" ) ;
368
+ request_ . Content = content_ ;
369
+ request_ . Method = new System . Net . Http . HttpMethod ( "GET" ) ;
370
+ request_ . Headers . Accept . Add ( System . Net . Http . Headers . MediaTypeWithQualityHeaderValue . Parse ( "application/json" ) ) ;
371
+
372
+ var urlBuilder_ = new System . Text . StringBuilder ( ) ;
373
+ if ( ! string . IsNullOrEmpty ( _baseUrl ) ) urlBuilder_ . Append ( _baseUrl ) ;
374
+ // Operation Path: "v1/Projects"
375
+ urlBuilder_ . Append ( "v1/Projects" ) ;
376
+
377
+ PrepareRequest ( client_ , request_ , urlBuilder_ ) ;
378
+
379
+ var url_ = urlBuilder_ . ToString ( ) ;
380
+ request_ . RequestUri = new System . Uri ( url_ , System . UriKind . RelativeOrAbsolute ) ;
381
+
382
+ PrepareRequest ( client_ , request_ , url_ ) ;
383
+
384
+ var response_ = await client_ . SendAsync ( request_ , System . Net . Http . HttpCompletionOption . ResponseHeadersRead , cancellationToken ) . ConfigureAwait ( false ) ;
385
+ var disposeResponse_ = true ;
386
+ try
387
+ {
388
+ var headers_ = new System . Collections . Generic . Dictionary < string , System . Collections . Generic . IEnumerable < string > > ( ) ;
389
+ foreach ( var item_ in response_ . Headers )
390
+ headers_ [ item_ . Key ] = item_ . Value ;
391
+ if ( response_ . Content != null && response_ . Content . Headers != null )
392
+ {
393
+ foreach ( var item_ in response_ . Content . Headers )
394
+ headers_ [ item_ . Key ] = item_ . Value ;
395
+ }
396
+
397
+ ProcessResponse ( client_ , response_ ) ;
398
+
399
+ var status_ = ( int ) response_ . StatusCode ;
400
+ if ( status_ == 200 )
401
+ {
402
+ var objectResponse_ = await ReadObjectResponseAsync < Project > ( response_ , headers_ , cancellationToken ) . ConfigureAwait ( false ) ;
403
+ if ( objectResponse_ . Object == null )
404
+ {
405
+ throw new PersonsApiException ( "Response was null which was not expected." , status_ , objectResponse_ . Text , headers_ , null ) ;
406
+ }
407
+ return objectResponse_ . Object ;
408
+ }
409
+ else
410
+ if ( status_ == 400 )
411
+ {
412
+ string responseText_ = ( response_ . Content == null ) ? string . Empty : await response_ . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
413
+ throw new PersonsApiException ( "Invalid request data." , status_ , responseText_ , headers_ , null ) ;
414
+ }
415
+ else
416
+ {
417
+ var responseData_ = response_ . Content == null ? null : await response_ . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
418
+ throw new PersonsApiException ( "The HTTP status code of the response was not expected (" + status_ + ")." , status_ , responseData_ , headers_ , null ) ;
419
+ }
420
+ }
421
+ finally
422
+ {
423
+ if ( disposeResponse_ )
424
+ response_ . Dispose ( ) ;
425
+ }
426
+ }
427
+ }
428
+ finally
429
+ {
430
+ if ( disposeClient_ )
431
+ client_ . Dispose ( ) ;
432
+ }
433
+ }
434
+
435
+ protected struct ObjectResponseResult < T >
436
+ {
437
+ public ObjectResponseResult ( T responseObject , string responseText )
438
+ {
439
+ this . Object = responseObject ;
440
+ this . Text = responseText ;
441
+ }
442
+
443
+ public T Object { get ; }
444
+
445
+ public string Text { get ; }
446
+ }
447
+
448
+ public bool ReadResponseAsString { get ; set ; }
449
+
450
+ protected virtual async System . Threading . Tasks . Task < ObjectResponseResult < T > > ReadObjectResponseAsync < T > ( System . Net . Http . HttpResponseMessage response , System . Collections . Generic . IReadOnlyDictionary < string , System . Collections . Generic . IEnumerable < string > > headers , System . Threading . CancellationToken cancellationToken )
451
+ {
452
+ if ( response == null || response . Content == null )
453
+ {
454
+ return new ObjectResponseResult < T > ( default ( T ) ! , string . Empty ) ;
455
+ }
456
+
457
+ if ( ReadResponseAsString )
458
+ {
459
+ var responseText = await response . Content . ReadAsStringAsync ( ) . ConfigureAwait ( false ) ;
460
+ try
461
+ {
462
+ var typedBody = Newtonsoft . Json . JsonConvert . DeserializeObject < T > ( responseText , JsonSerializerSettings ) ;
463
+ return new ObjectResponseResult < T > ( typedBody ! , responseText ) ;
464
+ }
465
+ catch ( Newtonsoft . Json . JsonException exception )
466
+ {
467
+ var message = "Could not deserialize the response body string as " + typeof ( T ) . FullName + "." ;
468
+ throw new PersonsApiException ( message , ( int ) response . StatusCode , responseText , headers , exception ) ;
469
+ }
470
+ }
471
+ else
472
+ {
473
+ try
474
+ {
475
+ using ( var responseStream = await response . Content . ReadAsStreamAsync ( ) . ConfigureAwait ( false ) )
476
+ using ( var streamReader = new System . IO . StreamReader ( responseStream ) )
477
+ using ( var jsonTextReader = new Newtonsoft . Json . JsonTextReader ( streamReader ) )
478
+ {
479
+ var serializer = Newtonsoft . Json . JsonSerializer . Create ( JsonSerializerSettings ) ;
480
+ var typedBody = serializer . Deserialize < T > ( jsonTextReader ) ;
481
+ return new ObjectResponseResult < T > ( typedBody ! , string . Empty ) ;
482
+ }
483
+ }
484
+ catch ( Newtonsoft . Json . JsonException exception )
485
+ {
486
+ var message = "Could not deserialize the response body stream as " + typeof ( T ) . FullName + "." ;
487
+ throw new PersonsApiException ( message , ( int ) response . StatusCode , string . Empty , headers , exception ) ;
488
+ }
489
+ }
490
+ }
491
+
492
+ private string ConvertToString ( object ? value , System . Globalization . CultureInfo cultureInfo )
493
+ {
494
+ if ( value == null )
495
+ {
496
+ return "" ;
497
+ }
498
+
499
+ if ( value is System . Enum )
500
+ {
501
+ var name = System . Enum . GetName ( value . GetType ( ) , value ) ;
502
+ if ( name != null )
503
+ {
504
+ var field = System . Reflection . IntrospectionExtensions . GetTypeInfo ( value . GetType ( ) ) . GetDeclaredField ( name ) ;
505
+ if ( field != null )
506
+ {
507
+ var attribute = System . Reflection . CustomAttributeExtensions . GetCustomAttribute ( field , typeof ( System . Runtime . Serialization . EnumMemberAttribute ) )
508
+ as System . Runtime . Serialization . EnumMemberAttribute ;
509
+ if ( attribute != null )
510
+ {
511
+ return attribute . Value != null ? attribute . Value : name ;
512
+ }
513
+ }
514
+
515
+ var converted = System . Convert . ToString ( System . Convert . ChangeType ( value , System . Enum . GetUnderlyingType ( value . GetType ( ) ) , cultureInfo ) ) ;
516
+ return converted == null ? string . Empty : converted ;
517
+ }
518
+ }
519
+ else if ( value is bool )
520
+ {
521
+ return System . Convert . ToString ( ( bool ) value , cultureInfo ) . ToLowerInvariant ( ) ;
522
+ }
523
+ else if ( value is byte [ ] )
524
+ {
525
+ return System . Convert . ToBase64String ( ( byte [ ] ) value ) ;
526
+ }
527
+ else if ( value is string [ ] )
528
+ {
529
+ return string . Join ( "," , ( string [ ] ) value ) ;
530
+ }
531
+ else if ( value . GetType ( ) . IsArray )
532
+ {
533
+ var valueArray = ( System . Array ) value ;
534
+ var valueTextArray = new string [ valueArray . Length ] ;
535
+ for ( var i = 0 ; i < valueArray . Length ; i ++ )
536
+ {
537
+ valueTextArray [ i ] = ConvertToString ( valueArray . GetValue ( i ) , cultureInfo ) ;
538
+ }
539
+ return string . Join ( "," , valueTextArray ) ;
540
+ }
541
+
542
+ var result = System . Convert . ToString ( value , cultureInfo ) ;
543
+ return result == null ? "" : result ;
544
+ }
545
+ }
546
+
288
547
[ System . CodeDom . Compiler . GeneratedCode ( "NSwag" , "14.1.0.0 (NJsonSchema v11.0.2.0 (Newtonsoft.Json v13.0.0.0))" ) ]
289
548
public partial class SchoolsClient : ISchoolsClient
290
549
{
0 commit comments