diff --git a/src/libs/StabilityAI/Generated/StabilityAI.Polyfills.g.cs b/src/libs/StabilityAI/Generated/StabilityAI.Polyfills.g.cs index 76b3bb3..d301122 100644 --- a/src/libs/StabilityAI/Generated/StabilityAI.Polyfills.g.cs +++ b/src/libs/StabilityAI/Generated/StabilityAI.Polyfills.g.cs @@ -1,5 +1,4 @@ -#if !NET6_0_OR_GREATER #nullable enable namespace StabilityAI @@ -9,6 +8,7 @@ namespace StabilityAI /// public static partial class AutoSdkPolyfills { +#if !NET6_0_OR_GREATER /// /// /// @@ -48,6 +48,128 @@ public static partial class AutoSdkPolyfills content = content ?? throw new global::System.ArgumentNullException(nameof(content)); return content.ReadAsByteArrayAsync(); } +#endif + + /// + /// Creates a JSON request content instance. + /// + public static global::System.Net.Http.HttpContent CreateJsonContent( + 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 + } + + /// + /// Creates a JSON request content instance using a source-generated serializer context. + /// + 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 + } + + /// + /// Reads JSON content into the specified type using serializer options. + /// + public static async global::System.Threading.Tasks.Task ReadFromJsonAsync( + 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( + content, + jsonSerializerOptions, + cancellationToken).ConfigureAwait(false); +#else + using var stream = await AutoSdkPolyfills.ReadAsStreamAsync(content, cancellationToken).ConfigureAwait(false); + return await global::System.Text.Json.JsonSerializer.DeserializeAsync( + utf8Json: stream, + options: jsonSerializerOptions, + cancellationToken: cancellationToken).ConfigureAwait(false); +#endif + } + + /// + /// Reads JSON content into the specified type using a source-generated serializer context. + /// + public static async global::System.Threading.Tasks.Task ReadFromJsonAsync( + 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 \ No newline at end of file diff --git a/src/libs/StabilityAI/Generated/StabilityAI.V1EnginesClient.ListEngines.g.cs b/src/libs/StabilityAI/Generated/StabilityAI.V1EnginesClient.ListEngines.g.cs index 3c94c19..2b01cc8 100644 --- a/src/libs/StabilityAI/Generated/StabilityAI.V1EnginesClient.ListEngines.g.cs +++ b/src/libs/StabilityAI/Generated/StabilityAI.V1EnginesClient.ListEngines.g.cs @@ -224,7 +224,6 @@ partial void ProcessListEnginesResponseContent( try { __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( #if NET5_0_OR_GREATER cancellationToken diff --git a/src/libs/StabilityAI/Generated/StabilityAI.V1GenerationClient.ImageToImage.g.cs b/src/libs/StabilityAI/Generated/StabilityAI.V1GenerationClient.ImageToImage.g.cs index 496e7c9..1606158 100644 --- a/src/libs/StabilityAI/Generated/StabilityAI.V1GenerationClient.ImageToImage.g.cs +++ b/src/libs/StabilityAI/Generated/StabilityAI.V1GenerationClient.ImageToImage.g.cs @@ -530,7 +530,6 @@ partial void ProcessImageToImageResponseContent( try { __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( #if NET5_0_OR_GREATER cancellationToken diff --git a/src/libs/StabilityAI/Generated/StabilityAI.V1GenerationClient.Masking.g.cs b/src/libs/StabilityAI/Generated/StabilityAI.V1GenerationClient.Masking.g.cs index d95c417..9cf76e7 100644 --- a/src/libs/StabilityAI/Generated/StabilityAI.V1GenerationClient.Masking.g.cs +++ b/src/libs/StabilityAI/Generated/StabilityAI.V1GenerationClient.Masking.g.cs @@ -522,7 +522,6 @@ partial void ProcessMaskingResponseContent( try { __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( #if NET5_0_OR_GREATER cancellationToken diff --git a/src/libs/StabilityAI/Generated/StabilityAI.V1GenerationClient.TextToImage.g.cs b/src/libs/StabilityAI/Generated/StabilityAI.V1GenerationClient.TextToImage.g.cs index e29b81b..7fce480 100644 --- a/src/libs/StabilityAI/Generated/StabilityAI.V1GenerationClient.TextToImage.g.cs +++ b/src/libs/StabilityAI/Generated/StabilityAI.V1GenerationClient.TextToImage.g.cs @@ -450,7 +450,6 @@ partial void ProcessTextToImageResponseContent( try { __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( #if NET5_0_OR_GREATER cancellationToken diff --git a/src/libs/StabilityAI/Generated/StabilityAI.V1GenerationClient.UpscaleImage.g.cs b/src/libs/StabilityAI/Generated/StabilityAI.V1GenerationClient.UpscaleImage.g.cs index 3ec8f05..7a6c71a 100644 --- a/src/libs/StabilityAI/Generated/StabilityAI.V1GenerationClient.UpscaleImage.g.cs +++ b/src/libs/StabilityAI/Generated/StabilityAI.V1GenerationClient.UpscaleImage.g.cs @@ -466,7 +466,6 @@ partial void ProcessUpscaleImageResponseContent( try { __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( #if NET5_0_OR_GREATER cancellationToken diff --git a/src/libs/StabilityAI/Generated/StabilityAI.V1UserClient.UserAccount.g.cs b/src/libs/StabilityAI/Generated/StabilityAI.V1UserClient.UserAccount.g.cs index afb3ef1..fd0d271 100644 --- a/src/libs/StabilityAI/Generated/StabilityAI.V1UserClient.UserAccount.g.cs +++ b/src/libs/StabilityAI/Generated/StabilityAI.V1UserClient.UserAccount.g.cs @@ -213,7 +213,6 @@ partial void ProcessUserAccountResponseContent( try { __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( #if NET5_0_OR_GREATER cancellationToken diff --git a/src/libs/StabilityAI/Generated/StabilityAI.V1UserClient.UserBalance.g.cs b/src/libs/StabilityAI/Generated/StabilityAI.V1UserClient.UserBalance.g.cs index 6862d1d..9d8d4d0 100644 --- a/src/libs/StabilityAI/Generated/StabilityAI.V1UserClient.UserBalance.g.cs +++ b/src/libs/StabilityAI/Generated/StabilityAI.V1UserClient.UserBalance.g.cs @@ -225,7 +225,6 @@ partial void ProcessUserBalanceResponseContent( try { __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( #if NET5_0_OR_GREATER cancellationToken