File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed
modules/openapi-generator/src/main/resources/csharp/libraries/generichost Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -18,6 +18,7 @@ using {{packageName}}.{{modelPackage}};
18
18
{ {/-first} }
19
19
{ {/models} }
20
20
using System.Runtime.CompilerServices;
21
+ using System.Net.Http.Headers;
21
22
22
23
{ {> Assembly} }namespace { {packageName} }.{ {clientPackage} }
23
24
{
@@ -311,6 +312,26 @@ using System.Runtime.CompilerServices;
311
312
return string.Join(" ," , accepts);
312
313
}
313
314
315
+
316
+
317
+ /// <summary >
318
+ /// Select the Accept header's value from the given accepts array:
319
+ /// if JSON exists in the given array, use it;
320
+ /// otherwise use all of them.
321
+ /// </summary >
322
+ /// <param name =" accepts" >The accepts array to select from.</param >
323
+ /// <returns >The Accept header values to use.</returns >
324
+ public static IEnumerable<MediaTypeWithQualityHeaderValue > SelectHeaderAcceptArray(string[] accepts)
325
+ {
326
+ if (accepts.Length == 0)
327
+ return null;
328
+
329
+ if (accepts.Contains(" application/json" , StringComparer.OrdinalIgnoreCase))
330
+ return [MediaTypeWithQualityHeaderValue.Parse(" application/json" )];
331
+
332
+ return accepts.Select(MediaTypeWithQualityHeaderValue.Parse);
333
+ }
334
+
314
335
/// <summary >
315
336
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
316
337
/// </summary >
Original file line number Diff line number Diff line change 8
8
{ {/nrt} }
9
9
using System;
10
10
using System.Collections.Generic;
11
+ using System.Collections.ObjectModel;
11
12
{ {#net80OrLater} }
12
13
{ {#lambda.uniqueLines} }
13
14
{ {#operations} }
@@ -20,6 +21,7 @@ using System.Linq;
20
21
{ {/lambda.uniqueLines} }
21
22
{ {/net80OrLater} }
22
23
using System.Net;
24
+ using System.IO;
23
25
using System.Threading.Tasks;
24
26
using Microsoft.Extensions.Logging;
25
27
using System.Net.Http;
@@ -605,10 +607,10 @@ namespace {{packageName}}.{{apiPackage}}
605
607
{ {#produces} }
606
608
{ {#-first} }
607
609
608
- string { {nrt? } } acceptLocalVar = ClientUtils.SelectHeaderAccept (acceptLocalVars);
610
+ IEnumerable< MediaTypeWithQualityHeaderValue > acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray (acceptLocalVars);
609
611
610
- if ( acceptLocalVar != null )
611
- httpRequestMessageLocalVar.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue( acceptLocalVar) );
612
+ foreach (var acceptLocalVar in acceptHeaderValuesLocalVar )
613
+ httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar);
612
614
{ {/-first} }
613
615
{ {/produces} }
614
616
{ {#net60OrLater} }
You can’t perform that action at this time.
0 commit comments