Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ namespace {{packageName}}.{{clientPackage}}
/// </summary>
System.Net.Http.Headers.HttpResponseHeaders Headers { get; }

/// <summary>
/// The headers contained in the api response related to the content
/// </summary>
System.Net.Http.Headers.HttpContentHeaders ContentHeaders { get; }

/// <summary>
/// The path used when making the request.
/// </summary>
Expand Down Expand Up @@ -106,6 +111,11 @@ namespace {{packageName}}.{{clientPackage}}
/// </summary>
public System.Net.Http.Headers.HttpResponseHeaders Headers { get; }

/// <summary>
/// The headers contained in the api response related to the content
/// </summary>
public System.Net.Http.Headers.HttpContentHeaders ContentHeaders { get; }

/// <summary>
/// The DateTime when the request was retrieved.
/// </summary>
Expand Down Expand Up @@ -144,6 +154,7 @@ namespace {{packageName}}.{{clientPackage}}
{
StatusCode = httpResponseMessage.StatusCode;
Headers = httpResponseMessage.Headers;
ContentHeaders = httpResponseMessage.Content.Headers;
IsSuccessStatusCode = httpResponseMessage.IsSuccessStatusCode;
ReasonPhrase = httpResponseMessage.ReasonPhrase;
RawContent = rawContent;
Expand All @@ -167,6 +178,7 @@ namespace {{packageName}}.{{clientPackage}}
{
StatusCode = httpResponseMessage.StatusCode;
Headers = httpResponseMessage.Headers;
ContentHeaders = httpResponseMessage.Content.Headers;
IsSuccessStatusCode = httpResponseMessage.IsSuccessStatusCode;
ReasonPhrase = httpResponseMessage.ReasonPhrase;
ContentStream = contentStream;
Expand All @@ -178,6 +190,7 @@ namespace {{packageName}}.{{clientPackage}}
OnCreated(httpRequestMessage, httpResponseMessage);
}


partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage);
}
{{#x-http-statuses-with-return}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ using {{packageName}}.{{modelPackage}};
{{/-first}}
{{/models}}
using System.Runtime.CompilerServices;
using System.Net.Http.Headers;

{{>Assembly}}namespace {{packageName}}.{{clientPackage}}
{
Expand Down Expand Up @@ -311,6 +312,36 @@ using System.Runtime.CompilerServices;
return string.Join(",", accepts);
}



/// <summary>
/// Select the Accept header's value from the given accepts array:
/// if JSON exists in the given array, use it;
/// otherwise use all of them.
/// </summary>
/// <param name="accepts">The accepts array to select from.</param>
/// <returns>The Accept header values to use.</returns>
public static IEnumerable<MediaTypeWithQualityHeaderValue> SelectHeaderAcceptArray(string[] accepts)
{
if (accepts.Length == 0)
{{#net80OrLater}}
return [];
{{/net80OrLater}}
{{^net80OrLater}}
return Enumerable.Empty<MediaTypeWithQualityHeaderValue>();
{{/net80OrLater}}

if (accepts.Contains("application/json", StringComparer.OrdinalIgnoreCase))
{{#net80OrLater}}
return [MediaTypeWithQualityHeaderValue.Parse("application/json")];
{{/net80OrLater}}
{{^net80OrLater}}
return new [] { MediaTypeWithQualityHeaderValue.Parse("application/json") };
{{/net80OrLater}}

return accepts.Select(MediaTypeWithQualityHeaderValue.Parse);
}

/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
{{/nrt}}
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
{{#net80OrLater}}
{{#lambda.uniqueLines}}
{{#operations}}
Expand All @@ -20,6 +21,7 @@ using System.Linq;
{{/lambda.uniqueLines}}
{{/net80OrLater}}
using System.Net;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using System.Net.Http;
Expand Down Expand Up @@ -605,10 +607,10 @@ namespace {{packageName}}.{{apiPackage}}
{{#produces}}
{{#-first}}

string{{nrt?}} acceptLocalVar = ClientUtils.SelectHeaderAccept(acceptLocalVars);
IEnumerable<MediaTypeWithQualityHeaderValue> acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars);

if (acceptLocalVar != null)
httpRequestMessageLocalVar.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptLocalVar));
foreach (var acceptLocalVar in acceptHeaderValuesLocalVar)
httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar);
{{/-first}}
{{/produces}}
{{#net60OrLater}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public partial interface IApiResponse
/// </summary>
System.Net.Http.Headers.HttpResponseHeaders Headers { get; }

/// <summary>
/// The headers contained in the api response related to the content
/// </summary>
System.Net.Http.Headers.HttpContentHeaders ContentHeaders { get; }

/// <summary>
/// The path used when making the request.
/// </summary>
Expand Down Expand Up @@ -109,6 +114,11 @@ public partial class ApiResponse : IApiResponse
/// </summary>
public System.Net.Http.Headers.HttpResponseHeaders Headers { get; }

/// <summary>
/// The headers contained in the api response related to the content
/// </summary>
public System.Net.Http.Headers.HttpContentHeaders ContentHeaders { get; }

/// <summary>
/// The DateTime when the request was retrieved.
/// </summary>
Expand Down Expand Up @@ -147,6 +157,7 @@ public ApiResponse(global::System.Net.Http.HttpRequestMessage httpRequestMessage
{
StatusCode = httpResponseMessage.StatusCode;
Headers = httpResponseMessage.Headers;
ContentHeaders = httpResponseMessage.Content.Headers;
IsSuccessStatusCode = httpResponseMessage.IsSuccessStatusCode;
ReasonPhrase = httpResponseMessage.ReasonPhrase;
RawContent = rawContent;
Expand All @@ -170,6 +181,7 @@ public ApiResponse(global::System.Net.Http.HttpRequestMessage httpRequestMessage
{
StatusCode = httpResponseMessage.StatusCode;
Headers = httpResponseMessage.Headers;
ContentHeaders = httpResponseMessage.Content.Headers;
IsSuccessStatusCode = httpResponseMessage.IsSuccessStatusCode;
ReasonPhrase = httpResponseMessage.ReasonPhrase;
ContentStream = contentStream;
Expand All @@ -181,6 +193,7 @@ public ApiResponse(global::System.Net.Http.HttpRequestMessage httpRequestMessage
OnCreated(httpRequestMessage, httpResponseMessage);
}


partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Text.RegularExpressions;
using Org.OpenAPITools.Model;
using System.Runtime.CompilerServices;
using System.Net.Http.Headers;

[assembly: InternalsVisibleTo("Org.OpenAPITools.Test")]

Expand Down Expand Up @@ -226,6 +227,26 @@ public static byte[] ReadAsBytes(Stream inputStream)
return string.Join(",", accepts);
}



/// <summary>
/// Select the Accept header's value from the given accepts array:
/// if JSON exists in the given array, use it;
/// otherwise use all of them.
/// </summary>
/// <param name="accepts">The accepts array to select from.</param>
/// <returns>The Accept header values to use.</returns>
public static IEnumerable<MediaTypeWithQualityHeaderValue> SelectHeaderAcceptArray(string[] accepts)
{
if (accepts.Length == 0)
return [];

if (accepts.Contains("application/json", StringComparer.OrdinalIgnoreCase))
return [MediaTypeWithQualityHeaderValue.Parse("application/json")];

return accepts.Select(MediaTypeWithQualityHeaderValue.Parse);
}

/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using System.Net.Http;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public partial interface IApiResponse
/// </summary>
System.Net.Http.Headers.HttpResponseHeaders Headers { get; }

/// <summary>
/// The headers contained in the api response related to the content
/// </summary>
System.Net.Http.Headers.HttpContentHeaders ContentHeaders { get; }

/// <summary>
/// The path used when making the request.
/// </summary>
Expand Down Expand Up @@ -109,6 +114,11 @@ public partial class ApiResponse : IApiResponse
/// </summary>
public System.Net.Http.Headers.HttpResponseHeaders Headers { get; }

/// <summary>
/// The headers contained in the api response related to the content
/// </summary>
public System.Net.Http.Headers.HttpContentHeaders ContentHeaders { get; }

/// <summary>
/// The DateTime when the request was retrieved.
/// </summary>
Expand Down Expand Up @@ -147,6 +157,7 @@ public ApiResponse(global::System.Net.Http.HttpRequestMessage httpRequestMessage
{
StatusCode = httpResponseMessage.StatusCode;
Headers = httpResponseMessage.Headers;
ContentHeaders = httpResponseMessage.Content.Headers;
IsSuccessStatusCode = httpResponseMessage.IsSuccessStatusCode;
ReasonPhrase = httpResponseMessage.ReasonPhrase;
RawContent = rawContent;
Expand All @@ -170,6 +181,7 @@ public ApiResponse(global::System.Net.Http.HttpRequestMessage httpRequestMessage
{
StatusCode = httpResponseMessage.StatusCode;
Headers = httpResponseMessage.Headers;
ContentHeaders = httpResponseMessage.Content.Headers;
IsSuccessStatusCode = httpResponseMessage.IsSuccessStatusCode;
ReasonPhrase = httpResponseMessage.ReasonPhrase;
ContentStream = contentStream;
Expand All @@ -181,6 +193,7 @@ public ApiResponse(global::System.Net.Http.HttpRequestMessage httpRequestMessage
OnCreated(httpRequestMessage, httpResponseMessage);
}


partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Text.RegularExpressions;
using Org.OpenAPITools.Model;
using System.Runtime.CompilerServices;
using System.Net.Http.Headers;

[assembly: InternalsVisibleTo("Org.OpenAPITools.Test")]

Expand Down Expand Up @@ -220,6 +221,26 @@ public static byte[] ReadAsBytes(Stream inputStream)
return string.Join(",", accepts);
}



/// <summary>
/// Select the Accept header's value from the given accepts array:
/// if JSON exists in the given array, use it;
/// otherwise use all of them.
/// </summary>
/// <param name="accepts">The accepts array to select from.</param>
/// <returns>The Accept header values to use.</returns>
public static IEnumerable<MediaTypeWithQualityHeaderValue> SelectHeaderAcceptArray(string[] accepts)
{
if (accepts.Length == 0)
return [];

if (accepts.Contains("application/json", StringComparer.OrdinalIgnoreCase))
return [MediaTypeWithQualityHeaderValue.Parse("application/json")];

return accepts.Select(MediaTypeWithQualityHeaderValue.Parse);
}

/// <summary>
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Net;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using System.Net.Http;
Expand Down Expand Up @@ -253,10 +255,10 @@ public async Task<IIconsApiResponse> IconsAsync(Option<IconsSizeParameter> size
"application/json"
};

string? acceptLocalVar = ClientUtils.SelectHeaderAccept(acceptLocalVars);
IEnumerable<MediaTypeWithQualityHeaderValue> acceptHeaderValuesLocalVar = ClientUtils.SelectHeaderAcceptArray(acceptLocalVars);

if (acceptLocalVar != null)
httpRequestMessageLocalVar.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptLocalVar));
foreach (var acceptLocalVar in acceptHeaderValuesLocalVar)
httpRequestMessageLocalVar.Headers.Accept.Add(acceptLocalVar);

httpRequestMessageLocalVar.Method = HttpMethod.Get;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public partial interface IApiResponse
/// </summary>
System.Net.Http.Headers.HttpResponseHeaders Headers { get; }

/// <summary>
/// The headers contained in the api response related to the content
/// </summary>
System.Net.Http.Headers.HttpContentHeaders ContentHeaders { get; }

/// <summary>
/// The path used when making the request.
/// </summary>
Expand Down Expand Up @@ -109,6 +114,11 @@ public partial class ApiResponse : IApiResponse
/// </summary>
public System.Net.Http.Headers.HttpResponseHeaders Headers { get; }

/// <summary>
/// The headers contained in the api response related to the content
/// </summary>
public System.Net.Http.Headers.HttpContentHeaders ContentHeaders { get; }

/// <summary>
/// The DateTime when the request was retrieved.
/// </summary>
Expand Down Expand Up @@ -147,6 +157,7 @@ public ApiResponse(global::System.Net.Http.HttpRequestMessage httpRequestMessage
{
StatusCode = httpResponseMessage.StatusCode;
Headers = httpResponseMessage.Headers;
ContentHeaders = httpResponseMessage.Content.Headers;
IsSuccessStatusCode = httpResponseMessage.IsSuccessStatusCode;
ReasonPhrase = httpResponseMessage.ReasonPhrase;
RawContent = rawContent;
Expand All @@ -170,6 +181,7 @@ public ApiResponse(global::System.Net.Http.HttpRequestMessage httpRequestMessage
{
StatusCode = httpResponseMessage.StatusCode;
Headers = httpResponseMessage.Headers;
ContentHeaders = httpResponseMessage.Content.Headers;
IsSuccessStatusCode = httpResponseMessage.IsSuccessStatusCode;
ReasonPhrase = httpResponseMessage.ReasonPhrase;
ContentStream = contentStream;
Expand All @@ -181,6 +193,7 @@ public ApiResponse(global::System.Net.Http.HttpRequestMessage httpRequestMessage
OnCreated(httpRequestMessage, httpResponseMessage);
}


partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage);
}

Expand Down
Loading
Loading