Skip to content
Merged
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 @@ -171,7 +171,6 @@ partial void ProcessAccountGetResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ partial void ProcessActionsCreateResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ partial void ProcessActionsDeleteResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ partial void ProcessActionsExecuteResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ partial void ProcessActionsGetResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ partial void ProcessActionsListResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,6 @@ partial void ProcessActionsUpdateResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@ partial void ProcessAuthorDeleteResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ partial void ProcessAuthorOpenCreateResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ partial void ProcessAuthorOpenGetAuthorDetailsResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ partial void ProcessAuthorOpenListAuthorsResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ partial void ProcessAuthorOpenUpdateResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,6 @@ partial void ProcessNewModerateModerateResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
126 changes: 124 additions & 2 deletions src/libs/ModerationAPI/Generated/ModerationAPI.Polyfills.g.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@

#if !NET6_0_OR_GREATER
#nullable enable

namespace ModerationAPI
Expand All @@ -9,6 +8,7 @@ namespace ModerationAPI
/// </summary>
public static partial class AutoSdkPolyfills
{
#if !NET6_0_OR_GREATER
/// <summary>
///
/// </summary>
Expand Down Expand Up @@ -48,6 +48,128 @@ public static partial class AutoSdkPolyfills
content = content ?? throw new global::System.ArgumentNullException(nameof(content));
return content.ReadAsByteArrayAsync();
}
#endif

/// <summary>
/// Creates a JSON request content instance.
/// </summary>
public static global::System.Net.Http.HttpContent CreateJsonContent<T>(
T inputValue,
string mediaType,
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions)
{
if (string.IsNullOrWhiteSpace(mediaType))
{
throw new global::System.ArgumentException("Media type is required.", nameof(mediaType));
}

#if NET5_0_OR_GREATER
return global::System.Net.Http.Json.JsonContent.Create(
inputValue: inputValue,
mediaType: new global::System.Net.Http.Headers.MediaTypeHeaderValue(mediaType),
options: jsonSerializerOptions);
#else
var json = global::System.Text.Json.JsonSerializer.Serialize(inputValue, jsonSerializerOptions);
var stringContent = new global::System.Net.Http.StringContent(
content: json,
encoding: global::System.Text.Encoding.UTF8);
stringContent.Headers.ContentType = new global::System.Net.Http.Headers.MediaTypeHeaderValue(mediaType)
{
CharSet = global::System.Text.Encoding.UTF8.WebName,
};
return stringContent;
#endif
}

/// <summary>
/// Creates a JSON request content instance using a source-generated serializer context.
/// </summary>
public static global::System.Net.Http.HttpContent CreateJsonContent(
object? inputValue,
global::System.Type inputType,
string mediaType,
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext)
{
inputType = inputType ?? throw new global::System.ArgumentNullException(nameof(inputType));
jsonSerializerContext = jsonSerializerContext ?? throw new global::System.ArgumentNullException(nameof(jsonSerializerContext));

if (string.IsNullOrWhiteSpace(mediaType))
{
throw new global::System.ArgumentException("Media type is required.", nameof(mediaType));
}

#if NET5_0_OR_GREATER
var jsonTypeInfo = jsonSerializerContext.GetTypeInfo(inputType) ??
throw new global::System.InvalidOperationException($"No JsonTypeInfo registered for '{inputType}'.");
return global::System.Net.Http.Json.JsonContent.Create(
inputValue: inputValue,
jsonTypeInfo: jsonTypeInfo,
mediaType: new global::System.Net.Http.Headers.MediaTypeHeaderValue(mediaType));
#else
var json = global::System.Text.Json.JsonSerializer.Serialize(
value: inputValue,
inputType: inputType,
jsonSerializerContext);
var stringContent = new global::System.Net.Http.StringContent(
content: json,
encoding: global::System.Text.Encoding.UTF8);
stringContent.Headers.ContentType = new global::System.Net.Http.Headers.MediaTypeHeaderValue(mediaType)
{
CharSet = global::System.Text.Encoding.UTF8.WebName,
};
return stringContent;
#endif
}

/// <summary>
/// Reads JSON content into the specified type using serializer options.
/// </summary>
public static async global::System.Threading.Tasks.Task<T?> ReadFromJsonAsync<T>(
this global::System.Net.Http.HttpContent content,
global::System.Text.Json.JsonSerializerOptions? jsonSerializerOptions,
global::System.Threading.CancellationToken cancellationToken)
{
content = content ?? throw new global::System.ArgumentNullException(nameof(content));

#if NET5_0_OR_GREATER
return await global::System.Net.Http.Json.HttpContentJsonExtensions.ReadFromJsonAsync<T>(
content,
jsonSerializerOptions,
cancellationToken).ConfigureAwait(false);
#else
using var stream = await AutoSdkPolyfills.ReadAsStreamAsync(content, cancellationToken).ConfigureAwait(false);
return await global::System.Text.Json.JsonSerializer.DeserializeAsync<T>(
utf8Json: stream,
options: jsonSerializerOptions,
cancellationToken: cancellationToken).ConfigureAwait(false);
#endif
}

/// <summary>
/// Reads JSON content into the specified type using a source-generated serializer context.
/// </summary>
public static async global::System.Threading.Tasks.Task<T?> ReadFromJsonAsync<T>(
this global::System.Net.Http.HttpContent content,
global::System.Text.Json.Serialization.JsonSerializerContext jsonSerializerContext,
global::System.Threading.CancellationToken cancellationToken)
{
content = content ?? throw new global::System.ArgumentNullException(nameof(content));
jsonSerializerContext = jsonSerializerContext ?? throw new global::System.ArgumentNullException(nameof(jsonSerializerContext));

#if NET5_0_OR_GREATER
return (T?)await global::System.Net.Http.Json.HttpContentJsonExtensions.ReadFromJsonAsync(
content,
typeof(T),
jsonSerializerContext,
cancellationToken).ConfigureAwait(false);
#else
using var stream = await AutoSdkPolyfills.ReadAsStreamAsync(content, cancellationToken).ConfigureAwait(false);
return (T?)await global::System.Text.Json.JsonSerializer.DeserializeAsync(
utf8Json: stream,
returnType: typeof(T),
jsonSerializerContext,
cancellationToken: cancellationToken).ConfigureAwait(false);
#endif
}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@ partial void ProcessQueueViewOpenGetItemsResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ partial void ProcessQueueViewOpenGetQueueResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ partial void ProcessQueueViewOpenGetStatsResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ partial void ProcessQueueViewOpenResolveItemResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,6 @@ partial void ProcessQueueViewOpenUnresolveItemResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ partial void ProcessWordlistAddWordsResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ partial void ProcessWordlistGetWordlistPublicResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ partial void ProcessWordlistListResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ partial void ProcessWordlistRemoveWordsResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,6 @@ partial void ProcessWordlistUpdateResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ partial void ProcessWordlistWordlistEmbeddingStatusResponseContent(
try
{
__response.EnsureSuccessStatusCode();

using var __content = await __response.Content.ReadAsStreamAsync(
#if NET5_0_OR_GREATER
cancellationToken
Expand Down