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}};
1818{ {/-first} }
1919{ {/models} }
2020using System.Runtime.CompilerServices;
21+ using System.Net.Http.Headers;
2122
2223{ {> Assembly} }namespace { {packageName} }.{ {clientPackage} }
2324{
@@ -311,6 +312,26 @@ using System.Runtime.CompilerServices;
311312 return string.Join(" ," , accepts);
312313 }
313314
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+
314335 /// <summary >
315336 /// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
316337 /// </summary >
Original file line number Diff line number Diff line change 88{ {/nrt} }
99using System;
1010using System.Collections.Generic;
11+ using System.Collections.ObjectModel;
1112{ {#net80OrLater} }
1213{ {#lambda.uniqueLines} }
1314{ {#operations} }
@@ -20,6 +21,7 @@ using System.Linq;
2021{ {/lambda.uniqueLines} }
2122{ {/net80OrLater} }
2223using System.Net;
24+ using System.IO;
2325using System.Threading.Tasks;
2426using Microsoft.Extensions.Logging;
2527using System.Net.Http;
@@ -605,10 +607,10 @@ namespace {{packageName}}.{{apiPackage}}
605607 { {#produces} }
606608 { {#-first} }
607609
608- string { {nrt? } } acceptLocalVar = ClientUtils.SelectHeaderAccept (acceptLocalVars);
610+ IEnumerable< MediaTypeWithQualityHeaderValue > acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray (acceptLocalVars);
609611
610- if ( acceptLocalVar != null )
611- httpRequestMessageLocalVar.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue( acceptLocalVar) );
612+ foreach (var acceptLocalVar in acceptHeaderValuesLocalVar )
613+ httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar);
612614 { {/-first} }
613615 { {/produces} }
614616 { {#net60OrLater} }
You can’t perform that action at this time.
0 commit comments