diff --git a/src/libs/Anam/Generated/Anam.AnamClient.Authorizations.Bearer.g.cs b/src/libs/Anam/Generated/Anam.AnamClient.Authorizations.Bearer.g.cs index 12d3a87..cc8b7ce 100644 --- a/src/libs/Anam/Generated/Anam.AnamClient.Authorizations.Bearer.g.cs +++ b/src/libs/Anam/Generated/Anam.AnamClient.Authorizations.Bearer.g.cs @@ -25,6 +25,7 @@ public void AuthorizeUsingBearer( Authorizations.Add(new global::Anam.EndPointAuthorization { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", Value = apiKey, diff --git a/src/libs/Anam/Generated/Anam.AnamClient.g.cs b/src/libs/Anam/Generated/Anam.AnamClient.g.cs index 20962d3..6b59c11 100644 --- a/src/libs/Anam/Generated/Anam.AnamClient.g.cs +++ b/src/libs/Anam/Generated/Anam.AnamClient.g.cs @@ -31,6 +31,9 @@ public sealed partial class AnamClient : global::Anam.IAnamClient, global::Syste #if DEBUG = true; #endif + + /// + public global::Anam.AutoSDKClientOptions Options { get; } /// /// /// @@ -40,7 +43,7 @@ public sealed partial class AnamClient : global::Anam.IAnamClient, global::Syste /// /// /// - public AuthClient Auth => new AuthClient(HttpClient, authorizations: Authorizations) + public AuthClient Auth => new AuthClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -49,7 +52,7 @@ public sealed partial class AnamClient : global::Anam.IAnamClient, global::Syste /// /// /// - public AvatarsClient Avatars => new AvatarsClient(HttpClient, authorizations: Authorizations) + public AvatarsClient Avatars => new AvatarsClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -58,7 +61,7 @@ public sealed partial class AnamClient : global::Anam.IAnamClient, global::Syste /// /// /// - public KnowledgeClient Knowledge => new KnowledgeClient(HttpClient, authorizations: Authorizations) + public KnowledgeClient Knowledge => new KnowledgeClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -67,7 +70,7 @@ public sealed partial class AnamClient : global::Anam.IAnamClient, global::Syste /// /// /// - public LLMsClient LLMs => new LLMsClient(HttpClient, authorizations: Authorizations) + public LLMsClient LLMs => new LLMsClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -76,7 +79,7 @@ public sealed partial class AnamClient : global::Anam.IAnamClient, global::Syste /// /// /// - public PersonasClient Personas => new PersonasClient(HttpClient, authorizations: Authorizations) + public PersonasClient Personas => new PersonasClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -85,7 +88,7 @@ public sealed partial class AnamClient : global::Anam.IAnamClient, global::Syste /// /// /// - public SessionsClient Sessions => new SessionsClient(HttpClient, authorizations: Authorizations) + public SessionsClient Sessions => new SessionsClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -94,7 +97,7 @@ public sealed partial class AnamClient : global::Anam.IAnamClient, global::Syste /// /// /// - public ShareLinksClient ShareLinks => new ShareLinksClient(HttpClient, authorizations: Authorizations) + public ShareLinksClient ShareLinks => new ShareLinksClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -103,7 +106,7 @@ public sealed partial class AnamClient : global::Anam.IAnamClient, global::Syste /// /// /// - public ToolsClient Tools => new ToolsClient(HttpClient, authorizations: Authorizations) + public ToolsClient Tools => new ToolsClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -112,7 +115,7 @@ public sealed partial class AnamClient : global::Anam.IAnamClient, global::Syste /// /// /// - public VoicesClient Voices => new VoicesClient(HttpClient, authorizations: Authorizations) + public VoicesClient Voices => new VoicesClient(HttpClient, authorizations: Authorizations, options: Options) { ReadResponseAsString = ReadResponseAsString, JsonSerializerContext = JsonSerializerContext, @@ -131,11 +134,37 @@ public AnamClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the AnamClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public AnamClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Anam.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Anam.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Anam/Generated/Anam.AuthClient.CreateSessionToken.g.cs b/src/libs/Anam/Generated/Anam.AuthClient.CreateSessionToken.g.cs index f0a6f9d..6256d26 100644 --- a/src/libs/Anam/Generated/Anam.AuthClient.CreateSessionToken.g.cs +++ b/src/libs/Anam/Generated/Anam.AuthClient.CreateSessionToken.g.cs @@ -14,6 +14,7 @@ public partial class AuthClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,11 +46,13 @@ partial void ProcessCreateSessionTokenResponseContent( /// Creates a temporary session token for client-side use. The session token is valid for 1 hour. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task CreateSessionTokenAsync( global::Anam.CreateSessionTokenRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -66,22 +69,43 @@ partial void ProcessCreateSessionTokenResponseContent( securityRequirements: s_CreateSessionTokenSecurityRequirements, operationName: "CreateSessionTokenAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: "/v1/auth/session-token", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: "/v1/auth/session-token", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -91,217 +115,376 @@ partial void ProcessCreateSessionTokenResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareCreateSessionTokenRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareCreateSessionTokenRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - ProcessResponse( - client: HttpClient, - response: __response); - ProcessCreateSessionTokenResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + return __httpRequest; + } + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateSessionToken", + methodName: "CreateSessionTokenAsync", + pathTemplate: "\"/v1/auth/session-token\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateSessionToken", + methodName: "CreateSessionTokenAsync", + pathTemplate: "\"/v1/auth/session-token\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateSessionToken", + methodName: "CreateSessionTokenAsync", + pathTemplate: "\"/v1/auth/session-token\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_401 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessCreateSessionTokenResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateSessionToken", + methodName: "CreateSessionTokenAsync", + pathTemplate: "\"/v1/auth/session-token\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateSessionToken", + methodName: "CreateSessionTokenAsync", + pathTemplate: "\"/v1/auth/session-token\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessCreateSessionTokenResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - try - { - __response.EnsureSuccessStatusCode(); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - global::Anam.CreateSessionTokenResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessCreateSessionTokenResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); - return - await global::Anam.CreateSessionTokenResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.CreateSessionTokenResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.CreateSessionTokenResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Create session token
@@ -314,12 +497,14 @@ partial void ProcessCreateSessionTokenResponseContent( /// Persona configuration. Either provide inline config or a personaId. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task CreateSessionTokenAsync( string? clientLabel = default, global::Anam.CreateSessionTokenRequestPersonaConfig? personaConfig = default, global::Anam.CreateSessionTokenRequestSessionOptions? sessionOptions = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.CreateSessionTokenRequest @@ -331,6 +516,7 @@ partial void ProcessCreateSessionTokenResponseContent( return await CreateSessionTokenAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.AuthClient.g.cs b/src/libs/Anam/Generated/Anam.AuthClient.g.cs index 83254f5..28e95db 100644 --- a/src/libs/Anam/Generated/Anam.AuthClient.g.cs +++ b/src/libs/Anam/Generated/Anam.AuthClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class AuthClient : global::Anam.IAuthClient, global::Syste #if DEBUG = true; #endif + + /// + public global::Anam.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public AuthClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the AuthClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public AuthClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Anam.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Anam.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Anam/Generated/Anam.AvatarsClient.CreateAvatar.g.cs b/src/libs/Anam/Generated/Anam.AvatarsClient.CreateAvatar.g.cs index b46f388..bc85049 100644 --- a/src/libs/Anam/Generated/Anam.AvatarsClient.CreateAvatar.g.cs +++ b/src/libs/Anam/Generated/Anam.AvatarsClient.CreateAvatar.g.cs @@ -14,6 +14,7 @@ public partial class AvatarsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,11 +46,13 @@ partial void ProcessCreateAvatarResponseContent( /// Create a new custom avatar from an image. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task CreateAvatarAsync( global::Anam.CreateAvatarRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -66,22 +69,43 @@ partial void ProcessCreateAvatarResponseContent( securityRequirements: s_CreateAvatarSecurityRequirements, operationName: "CreateAvatarAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: "/v1/avatars", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: "/v1/avatars", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -91,302 +115,461 @@ partial void ProcessCreateAvatarResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.DisplayName}"), - name: "\"displayName\""); - if (request.ImageFile != default) - { + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.DisplayName}"), + name: "\"displayName\""); + if (request.ImageFile != default) + { - var __contentImageFile = new global::System.Net.Http.ByteArrayContent(request.ImageFile ?? global::System.Array.Empty()); - __httpRequestContent.Add( - content: __contentImageFile, - name: "\"imageFile\"", - fileName: request.ImageFilename != null ? $"\"{request.ImageFilename}\"" : string.Empty); - if (__contentImageFile.Headers.ContentDisposition != null) - { - __contentImageFile.Headers.ContentDisposition.FileNameStar = null; - } - } - if (request.ImageUrl != default) - { + var __contentImageFile = new global::System.Net.Http.ByteArrayContent(request.ImageFile ?? global::System.Array.Empty()); + __httpRequestContent.Add( + content: __contentImageFile, + name: "\"imageFile\"", + fileName: request.ImageFilename != null ? $"\"{request.ImageFilename}\"" : string.Empty); + if (__contentImageFile.Headers.ContentDisposition != null) + { + __contentImageFile.Headers.ContentDisposition.FileNameStar = null; + } + } + if (request.ImageUrl != default) + { - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.ImageUrl}"), - name: "\"imageUrl\""); - } - __httpRequest.Content = __httpRequestContent; + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.ImageUrl}"), + name: "\"imageUrl\""); + } + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareCreateAvatarRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareCreateAvatarRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessCreateAvatarResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateAvatar", + methodName: "CreateAvatarAsync", + pathTemplate: "\"/v1/avatars\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateAvatar", + methodName: "CreateAvatarAsync", + pathTemplate: "\"/v1/avatars\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateAvatar", + methodName: "CreateAvatarAsync", + pathTemplate: "\"/v1/avatars\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - throw new global::Anam.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 422) - { - string? __content_422 = null; - global::System.Exception? __exception_422 = null; - try - { - if (ReadResponseAsString) - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_422 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_422 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_422, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_422, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessCreateAvatarResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateAvatar", + methodName: "CreateAvatarAsync", + pathTemplate: "\"/v1/avatars\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateAvatar", + methodName: "CreateAvatarAsync", + pathTemplate: "\"/v1/avatars\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessCreateAvatarResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 422) + { + string? __content_422 = null; + global::System.Exception? __exception_422 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_422 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_422 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_422 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_422, + statusCode: __response.StatusCode) + { + ResponseBody = __content_422, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - return - global::Anam.Avatar.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - await global::Anam.Avatar.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessCreateAvatarResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.Avatar.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.Avatar.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Create avatar
@@ -404,6 +587,7 @@ partial void ProcessCreateAvatarResponseContent( /// /// Image URL (JPEG, PNG, WebP; max 4.5MB). /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task CreateAvatarAsync( @@ -411,6 +595,7 @@ partial void ProcessCreateAvatarResponseContent( byte[]? imageFile = default, string? imageFilename = default, string? imageUrl = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.CreateAvatarRequest @@ -423,6 +608,7 @@ partial void ProcessCreateAvatarResponseContent( return await CreateAvatarAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.AvatarsClient.DeleteAvatar.g.cs b/src/libs/Anam/Generated/Anam.AvatarsClient.DeleteAvatar.g.cs index 481f3d2..699a85a 100644 --- a/src/libs/Anam/Generated/Anam.AvatarsClient.DeleteAvatar.g.cs +++ b/src/libs/Anam/Generated/Anam.AvatarsClient.DeleteAvatar.g.cs @@ -14,6 +14,7 @@ public partial class AvatarsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -40,10 +41,12 @@ partial void ProcessDeleteAvatarResponse( /// Delete an avatar by ID. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task DeleteAvatarAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -58,22 +61,43 @@ partial void ProcessDeleteAvatarResponse( securityRequirements: s_DeleteAvatarSecurityRequirements, operationName: "DeleteAvatarAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/avatars/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Delete, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/avatars/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Delete, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -83,227 +107,386 @@ partial void ProcessDeleteAvatarResponse( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareDeleteAvatarRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareDeleteAvatarRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessDeleteAvatarResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteAvatar", + methodName: "DeleteAvatarAsync", + pathTemplate: "$\"/v1/avatars/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteAvatar", + methodName: "DeleteAvatarAsync", + pathTemplate: "$\"/v1/avatars/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteAvatar", + methodName: "DeleteAvatarAsync", + pathTemplate: "$\"/v1/avatars/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessDeleteAvatarResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteAvatar", + methodName: "DeleteAvatarAsync", + pathTemplate: "$\"/v1/avatars/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteAvatar", + methodName: "DeleteAvatarAsync", + pathTemplate: "$\"/v1/avatars/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Anam/Generated/Anam.AvatarsClient.GetAvatar.g.cs b/src/libs/Anam/Generated/Anam.AvatarsClient.GetAvatar.g.cs index 9692df5..299ab51 100644 --- a/src/libs/Anam/Generated/Anam.AvatarsClient.GetAvatar.g.cs +++ b/src/libs/Anam/Generated/Anam.AvatarsClient.GetAvatar.g.cs @@ -14,6 +14,7 @@ public partial class AvatarsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,10 +46,12 @@ partial void ProcessGetAvatarResponseContent( /// Returns an avatar by ID. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GetAvatarAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -63,22 +66,43 @@ partial void ProcessGetAvatarResponseContent( securityRequirements: s_GetAvatarSecurityRequirements, operationName: "GetAvatarAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/avatars/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/avatars/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -88,244 +112,403 @@ partial void ProcessGetAvatarResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGetAvatarRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGetAvatarRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGetAvatarResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetAvatar", + methodName: "GetAvatarAsync", + pathTemplate: "$\"/v1/avatars/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetAvatar", + methodName: "GetAvatarAsync", + pathTemplate: "$\"/v1/avatars/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetAvatar", + methodName: "GetAvatarAsync", + pathTemplate: "$\"/v1/avatars/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessGetAvatarResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetAvatar", + methodName: "GetAvatarAsync", + pathTemplate: "$\"/v1/avatars/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetAvatar", + methodName: "GetAvatarAsync", + pathTemplate: "$\"/v1/avatars/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessGetAvatarResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - global::Anam.Avatar.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - await global::Anam.Avatar.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGetAvatarResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.Avatar.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.Avatar.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.AvatarsClient.ListAvatars.g.cs b/src/libs/Anam/Generated/Anam.AvatarsClient.ListAvatars.g.cs index e52d638..e081a4e 100644 --- a/src/libs/Anam/Generated/Anam.AvatarsClient.ListAvatars.g.cs +++ b/src/libs/Anam/Generated/Anam.AvatarsClient.ListAvatars.g.cs @@ -14,6 +14,7 @@ public partial class AvatarsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -60,6 +61,7 @@ partial void ProcessListAvatarsResponseContent( /// /// Default Value: false /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ListAvatarsAsync( @@ -67,6 +69,7 @@ partial void ProcessListAvatarsResponseContent( int? perPage = default, string? search = default, bool? onlyOneShot = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -84,28 +87,49 @@ partial void ProcessListAvatarsResponseContent( securityRequirements: s_ListAvatarsSecurityRequirements, operationName: "ListAvatarsAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: "/v1/avatars", - baseUri: HttpClient.BaseAddress); - __pathBuilder - .AddOptionalParameter("page", page?.ToString()) - .AddOptionalParameter("perPage", perPage?.ToString()) - .AddOptionalParameter("search", search) - .AddOptionalParameter("onlyOneShot", onlyOneShot?.ToString().ToLowerInvariant()) - ; - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: "/v1/avatars", + baseUri: HttpClient.BaseAddress); + __pathBuilder + .AddOptionalParameter("page", page?.ToString()) + .AddOptionalParameter("perPage", perPage?.ToString()) + .AddOptionalParameter("search", search) + .AddOptionalParameter("onlyOneShot", onlyOneShot?.ToString().ToLowerInvariant()) + ; + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -115,181 +139,340 @@ partial void ProcessListAvatarsResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareListAvatarsRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - page: page, - perPage: perPage, - search: search, - onlyOneShot: onlyOneShot); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareListAvatarsRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + page: page, + perPage: perPage, + search: search, + onlyOneShot: onlyOneShot); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessListAvatarsResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListAvatars", + methodName: "ListAvatarsAsync", + pathTemplate: "\"/v1/avatars\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListAvatars", + methodName: "ListAvatarsAsync", + pathTemplate: "\"/v1/avatars\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try - { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListAvatars", + methodName: "ListAvatarsAsync", + pathTemplate: "\"/v1/avatars\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_500 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessListAvatarsResponseContent( + response: __response); + ProcessListAvatarsResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - __response.EnsureSuccessStatusCode(); - - return - global::Anam.ListAvatarsResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListAvatars", + methodName: "ListAvatarsAsync", + pathTemplate: "\"/v1/avatars\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListAvatars", + methodName: "ListAvatarsAsync", + pathTemplate: "\"/v1/avatars\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - return - await global::Anam.ListAvatarsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessListAvatarsResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.ListAvatarsResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.ListAvatarsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.AvatarsClient.UpdateAvatar.g.cs b/src/libs/Anam/Generated/Anam.AvatarsClient.UpdateAvatar.g.cs index 83f6e9b..3098003 100644 --- a/src/libs/Anam/Generated/Anam.AvatarsClient.UpdateAvatar.g.cs +++ b/src/libs/Anam/Generated/Anam.AvatarsClient.UpdateAvatar.g.cs @@ -14,6 +14,7 @@ public partial class AvatarsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -48,12 +49,14 @@ partial void ProcessUpdateAvatarResponseContent( /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UpdateAvatarAsync( global::System.Guid id, global::Anam.UpdateAvatarRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -71,22 +74,43 @@ partial void ProcessUpdateAvatarResponseContent( securityRequirements: s_UpdateAvatarSecurityRequirements, operationName: "UpdateAvatarAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/avatars/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Put, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/avatars/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Put, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -96,251 +120,410 @@ partial void ProcessUpdateAvatarResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareUpdateAvatarRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - ProcessResponse( - client: HttpClient, - response: __response); - ProcessUpdateAvatarResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareUpdateAvatarRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id, + request: request); - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // - if ((int)__response.StatusCode == 401) + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateAvatar", + methodName: "UpdateAvatarAsync", + pathTemplate: "$\"/v1/avatars/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateAvatar", + methodName: "UpdateAvatarAsync", + pathTemplate: "$\"/v1/avatars/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateAvatar", + methodName: "UpdateAvatarAsync", + pathTemplate: "$\"/v1/avatars/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessUpdateAvatarResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateAvatar", + methodName: "UpdateAvatarAsync", + pathTemplate: "$\"/v1/avatars/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateAvatar", + methodName: "UpdateAvatarAsync", + pathTemplate: "$\"/v1/avatars/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessUpdateAvatarResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - global::Anam.Avatar.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - await global::Anam.Avatar.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessUpdateAvatarResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.Avatar.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.Avatar.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Update avatar
@@ -350,11 +533,13 @@ partial void ProcessUpdateAvatarResponseContent( /// /// New display name for the avatar. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UpdateAvatarAsync( global::System.Guid id, string displayName, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.UpdateAvatarRequest @@ -365,6 +550,7 @@ partial void ProcessUpdateAvatarResponseContent( return await UpdateAvatarAsync( id: id, request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.AvatarsClient.g.cs b/src/libs/Anam/Generated/Anam.AvatarsClient.g.cs index a1a7b9b..cc18b01 100644 --- a/src/libs/Anam/Generated/Anam.AvatarsClient.g.cs +++ b/src/libs/Anam/Generated/Anam.AvatarsClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class AvatarsClient : global::Anam.IAvatarsClient, global: #if DEBUG = true; #endif + + /// + public global::Anam.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public AvatarsClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the AvatarsClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public AvatarsClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Anam.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Anam.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Anam/Generated/Anam.IAnamClient.g.cs b/src/libs/Anam/Generated/Anam.IAnamClient.g.cs index 4ae52a1..52819fa 100644 --- a/src/libs/Anam/Generated/Anam.IAnamClient.g.cs +++ b/src/libs/Anam/Generated/Anam.IAnamClient.g.cs @@ -34,6 +34,11 @@ public partial interface IAnamClient : global::System.IDisposable ///
public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Anam.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Anam/Generated/Anam.IAuthClient.CreateSessionToken.g.cs b/src/libs/Anam/Generated/Anam.IAuthClient.CreateSessionToken.g.cs index 05087e0..107154c 100644 --- a/src/libs/Anam/Generated/Anam.IAuthClient.CreateSessionToken.g.cs +++ b/src/libs/Anam/Generated/Anam.IAuthClient.CreateSessionToken.g.cs @@ -9,11 +9,13 @@ public partial interface IAuthClient /// Creates a temporary session token for client-side use. The session token is valid for 1 hour. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task CreateSessionTokenAsync( global::Anam.CreateSessionTokenRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Create session token
@@ -26,12 +28,14 @@ public partial interface IAuthClient /// Persona configuration. Either provide inline config or a personaId. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task CreateSessionTokenAsync( string? clientLabel = default, global::Anam.CreateSessionTokenRequestPersonaConfig? personaConfig = default, global::Anam.CreateSessionTokenRequestSessionOptions? sessionOptions = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IAuthClient.g.cs b/src/libs/Anam/Generated/Anam.IAuthClient.g.cs index 4534ea7..23fb05e 100644 --- a/src/libs/Anam/Generated/Anam.IAuthClient.g.cs +++ b/src/libs/Anam/Generated/Anam.IAuthClient.g.cs @@ -33,6 +33,11 @@ public partial interface IAuthClient : global::System.IDisposable ///
public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Anam.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Anam/Generated/Anam.IAvatarsClient.CreateAvatar.g.cs b/src/libs/Anam/Generated/Anam.IAvatarsClient.CreateAvatar.g.cs index 6b6a1d0..b14e14b 100644 --- a/src/libs/Anam/Generated/Anam.IAvatarsClient.CreateAvatar.g.cs +++ b/src/libs/Anam/Generated/Anam.IAvatarsClient.CreateAvatar.g.cs @@ -9,11 +9,13 @@ public partial interface IAvatarsClient /// Create a new custom avatar from an image. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task CreateAvatarAsync( global::Anam.CreateAvatarRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Create avatar
@@ -31,6 +33,7 @@ public partial interface IAvatarsClient /// /// Image URL (JPEG, PNG, WebP; max 4.5MB). /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task CreateAvatarAsync( @@ -38,6 +41,7 @@ public partial interface IAvatarsClient byte[]? imageFile = default, string? imageFilename = default, string? imageUrl = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IAvatarsClient.DeleteAvatar.g.cs b/src/libs/Anam/Generated/Anam.IAvatarsClient.DeleteAvatar.g.cs index e79e84c..d7d4c4a 100644 --- a/src/libs/Anam/Generated/Anam.IAvatarsClient.DeleteAvatar.g.cs +++ b/src/libs/Anam/Generated/Anam.IAvatarsClient.DeleteAvatar.g.cs @@ -9,10 +9,12 @@ public partial interface IAvatarsClient /// Delete an avatar by ID. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task DeleteAvatarAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IAvatarsClient.GetAvatar.g.cs b/src/libs/Anam/Generated/Anam.IAvatarsClient.GetAvatar.g.cs index 22898b4..a73c206 100644 --- a/src/libs/Anam/Generated/Anam.IAvatarsClient.GetAvatar.g.cs +++ b/src/libs/Anam/Generated/Anam.IAvatarsClient.GetAvatar.g.cs @@ -9,10 +9,12 @@ public partial interface IAvatarsClient /// Returns an avatar by ID. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GetAvatarAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IAvatarsClient.ListAvatars.g.cs b/src/libs/Anam/Generated/Anam.IAvatarsClient.ListAvatars.g.cs index 2e86e8e..6daaa28 100644 --- a/src/libs/Anam/Generated/Anam.IAvatarsClient.ListAvatars.g.cs +++ b/src/libs/Anam/Generated/Anam.IAvatarsClient.ListAvatars.g.cs @@ -18,6 +18,7 @@ public partial interface IAvatarsClient /// /// Default Value: false /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ListAvatarsAsync( @@ -25,6 +26,7 @@ public partial interface IAvatarsClient int? perPage = default, string? search = default, bool? onlyOneShot = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IAvatarsClient.UpdateAvatar.g.cs b/src/libs/Anam/Generated/Anam.IAvatarsClient.UpdateAvatar.g.cs index b561083..37ef559 100644 --- a/src/libs/Anam/Generated/Anam.IAvatarsClient.UpdateAvatar.g.cs +++ b/src/libs/Anam/Generated/Anam.IAvatarsClient.UpdateAvatar.g.cs @@ -10,12 +10,14 @@ public partial interface IAvatarsClient /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UpdateAvatarAsync( global::System.Guid id, global::Anam.UpdateAvatarRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Update avatar
@@ -25,11 +27,13 @@ public partial interface IAvatarsClient /// /// New display name for the avatar. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UpdateAvatarAsync( global::System.Guid id, string displayName, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IAvatarsClient.g.cs b/src/libs/Anam/Generated/Anam.IAvatarsClient.g.cs index 9bdd021..9b16794 100644 --- a/src/libs/Anam/Generated/Anam.IAvatarsClient.g.cs +++ b/src/libs/Anam/Generated/Anam.IAvatarsClient.g.cs @@ -33,6 +33,11 @@ public partial interface IAvatarsClient : global::System.IDisposable ///
public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Anam.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Anam/Generated/Anam.IKnowledgeClient.CreateKnowledgeGroup.g.cs b/src/libs/Anam/Generated/Anam.IKnowledgeClient.CreateKnowledgeGroup.g.cs index 0124376..b7b94d4 100644 --- a/src/libs/Anam/Generated/Anam.IKnowledgeClient.CreateKnowledgeGroup.g.cs +++ b/src/libs/Anam/Generated/Anam.IKnowledgeClient.CreateKnowledgeGroup.g.cs @@ -9,11 +9,13 @@ public partial interface IKnowledgeClient /// Create a new knowledge group for RAG. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task CreateKnowledgeGroupAsync( global::Anam.CreateKnowledgeGroupRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Create knowledge group
@@ -21,11 +23,13 @@ public partial interface IKnowledgeClient ///
/// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task CreateKnowledgeGroupAsync( string name, string? description = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IKnowledgeClient.DeleteKnowledgeDocument.g.cs b/src/libs/Anam/Generated/Anam.IKnowledgeClient.DeleteKnowledgeDocument.g.cs index 9ef1f08..064dbbe 100644 --- a/src/libs/Anam/Generated/Anam.IKnowledgeClient.DeleteKnowledgeDocument.g.cs +++ b/src/libs/Anam/Generated/Anam.IKnowledgeClient.DeleteKnowledgeDocument.g.cs @@ -9,10 +9,12 @@ public partial interface IKnowledgeClient /// Delete a document from a knowledge group. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task DeleteKnowledgeDocumentAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IKnowledgeClient.DeleteKnowledgeGroup.g.cs b/src/libs/Anam/Generated/Anam.IKnowledgeClient.DeleteKnowledgeGroup.g.cs index 3b10478..80d8837 100644 --- a/src/libs/Anam/Generated/Anam.IKnowledgeClient.DeleteKnowledgeGroup.g.cs +++ b/src/libs/Anam/Generated/Anam.IKnowledgeClient.DeleteKnowledgeGroup.g.cs @@ -9,10 +9,12 @@ public partial interface IKnowledgeClient /// Delete a knowledge group. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task DeleteKnowledgeGroupAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IKnowledgeClient.GetKnowledgeDocument.g.cs b/src/libs/Anam/Generated/Anam.IKnowledgeClient.GetKnowledgeDocument.g.cs index 1d30f73..66185c8 100644 --- a/src/libs/Anam/Generated/Anam.IKnowledgeClient.GetKnowledgeDocument.g.cs +++ b/src/libs/Anam/Generated/Anam.IKnowledgeClient.GetKnowledgeDocument.g.cs @@ -9,10 +9,12 @@ public partial interface IKnowledgeClient /// Get a single document by ID. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GetKnowledgeDocumentAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IKnowledgeClient.GetKnowledgeDocumentDownload.g.cs b/src/libs/Anam/Generated/Anam.IKnowledgeClient.GetKnowledgeDocumentDownload.g.cs index 162d4d6..f5eed2b 100644 --- a/src/libs/Anam/Generated/Anam.IKnowledgeClient.GetKnowledgeDocumentDownload.g.cs +++ b/src/libs/Anam/Generated/Anam.IKnowledgeClient.GetKnowledgeDocumentDownload.g.cs @@ -9,10 +9,12 @@ public partial interface IKnowledgeClient /// Get a presigned download URL for a knowledge document. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GetKnowledgeDocumentDownloadAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IKnowledgeClient.GetKnowledgeGroup.g.cs b/src/libs/Anam/Generated/Anam.IKnowledgeClient.GetKnowledgeGroup.g.cs index 2830ae4..f70b7dc 100644 --- a/src/libs/Anam/Generated/Anam.IKnowledgeClient.GetKnowledgeGroup.g.cs +++ b/src/libs/Anam/Generated/Anam.IKnowledgeClient.GetKnowledgeGroup.g.cs @@ -9,10 +9,12 @@ public partial interface IKnowledgeClient /// Get a single knowledge group by ID. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GetKnowledgeGroupAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IKnowledgeClient.ListKnowledgeGroupDocuments.g.cs b/src/libs/Anam/Generated/Anam.IKnowledgeClient.ListKnowledgeGroupDocuments.g.cs index f6fe5a8..c443c2c 100644 --- a/src/libs/Anam/Generated/Anam.IKnowledgeClient.ListKnowledgeGroupDocuments.g.cs +++ b/src/libs/Anam/Generated/Anam.IKnowledgeClient.ListKnowledgeGroupDocuments.g.cs @@ -9,10 +9,12 @@ public partial interface IKnowledgeClient /// Get all documents in a knowledge group. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ListKnowledgeGroupDocumentsAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IKnowledgeClient.ListKnowledgeGroups.g.cs b/src/libs/Anam/Generated/Anam.IKnowledgeClient.ListKnowledgeGroups.g.cs index 3e71353..8d09473 100644 --- a/src/libs/Anam/Generated/Anam.IKnowledgeClient.ListKnowledgeGroups.g.cs +++ b/src/libs/Anam/Generated/Anam.IKnowledgeClient.ListKnowledgeGroups.g.cs @@ -8,9 +8,11 @@ public partial interface IKnowledgeClient /// List knowledge groups
/// Returns a list of all knowledge groups for the organization. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ListKnowledgeGroupsAsync( + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IKnowledgeClient.SearchKnowledgeGroup.g.cs b/src/libs/Anam/Generated/Anam.IKnowledgeClient.SearchKnowledgeGroup.g.cs index de25396..b6af928 100644 --- a/src/libs/Anam/Generated/Anam.IKnowledgeClient.SearchKnowledgeGroup.g.cs +++ b/src/libs/Anam/Generated/Anam.IKnowledgeClient.SearchKnowledgeGroup.g.cs @@ -10,12 +10,14 @@ public partial interface IKnowledgeClient /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task SearchKnowledgeGroupAsync( string id, global::Anam.SearchKnowledgeGroupRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Search knowledge group
@@ -26,12 +28,14 @@ public partial interface IKnowledgeClient /// /// Default Value: 5 /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task SearchKnowledgeGroupAsync( string id, string query, int? limit = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IKnowledgeClient.UpdateKnowledgeDocument.g.cs b/src/libs/Anam/Generated/Anam.IKnowledgeClient.UpdateKnowledgeDocument.g.cs index c3312c5..b07bd72 100644 --- a/src/libs/Anam/Generated/Anam.IKnowledgeClient.UpdateKnowledgeDocument.g.cs +++ b/src/libs/Anam/Generated/Anam.IKnowledgeClient.UpdateKnowledgeDocument.g.cs @@ -10,12 +10,14 @@ public partial interface IKnowledgeClient ///
/// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UpdateKnowledgeDocumentAsync( string id, global::Anam.UpdateKnowledgeDocumentRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Update knowledge document
@@ -25,11 +27,13 @@ public partial interface IKnowledgeClient /// /// New filename for the document. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UpdateKnowledgeDocumentAsync( string id, string? filename = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IKnowledgeClient.UpdateKnowledgeGroup.g.cs b/src/libs/Anam/Generated/Anam.IKnowledgeClient.UpdateKnowledgeGroup.g.cs index 72b9b13..d933cbc 100644 --- a/src/libs/Anam/Generated/Anam.IKnowledgeClient.UpdateKnowledgeGroup.g.cs +++ b/src/libs/Anam/Generated/Anam.IKnowledgeClient.UpdateKnowledgeGroup.g.cs @@ -10,12 +10,14 @@ public partial interface IKnowledgeClient ///
/// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UpdateKnowledgeGroupAsync( string id, global::Anam.UpdateKnowledgeGroupRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Update knowledge group
@@ -24,12 +26,14 @@ public partial interface IKnowledgeClient /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UpdateKnowledgeGroupAsync( string id, string? name = default, string? description = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IKnowledgeClient.UploadKnowledgeGroupDocument.g.cs b/src/libs/Anam/Generated/Anam.IKnowledgeClient.UploadKnowledgeGroupDocument.g.cs index 34cb7a9..b736860 100644 --- a/src/libs/Anam/Generated/Anam.IKnowledgeClient.UploadKnowledgeGroupDocument.g.cs +++ b/src/libs/Anam/Generated/Anam.IKnowledgeClient.UploadKnowledgeGroupDocument.g.cs @@ -10,12 +10,14 @@ public partial interface IKnowledgeClient ///
/// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UploadKnowledgeGroupDocumentAsync( string id, global::Anam.UploadKnowledgeGroupDocumentRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Upload knowledge group document
@@ -34,6 +36,7 @@ public partial interface IKnowledgeClient /// /// Default Value: 200 /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UploadKnowledgeGroupDocumentAsync( @@ -42,6 +45,7 @@ public partial interface IKnowledgeClient string filename, int? chunkSize = default, int? chunkOverlap = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IKnowledgeClient.g.cs b/src/libs/Anam/Generated/Anam.IKnowledgeClient.g.cs index f9493f7..2bddc37 100644 --- a/src/libs/Anam/Generated/Anam.IKnowledgeClient.g.cs +++ b/src/libs/Anam/Generated/Anam.IKnowledgeClient.g.cs @@ -33,6 +33,11 @@ public partial interface IKnowledgeClient : global::System.IDisposable ///
public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Anam.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Anam/Generated/Anam.ILLMsClient.CreateLlm.g.cs b/src/libs/Anam/Generated/Anam.ILLMsClient.CreateLlm.g.cs index 6763713..5b76653 100644 --- a/src/libs/Anam/Generated/Anam.ILLMsClient.CreateLlm.g.cs +++ b/src/libs/Anam/Generated/Anam.ILLMsClient.CreateLlm.g.cs @@ -9,11 +9,13 @@ public partial interface ILLMsClient /// Create a new LLM configuration. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task CreateLlmAsync( global::Anam.CreateLlmRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Create LLM
@@ -28,6 +30,7 @@ public partial interface ILLMsClient /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task CreateLlmAsync( @@ -40,6 +43,7 @@ public partial interface ILLMsClient object? metadata = default, global::Anam.CreateLlmRequestReasoningEffort? reasoningEffort = default, global::Anam.CreateLlmRequestReasoningFormat? reasoningFormat = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.ILLMsClient.DeleteLlm.g.cs b/src/libs/Anam/Generated/Anam.ILLMsClient.DeleteLlm.g.cs index 0a633b7..97ef889 100644 --- a/src/libs/Anam/Generated/Anam.ILLMsClient.DeleteLlm.g.cs +++ b/src/libs/Anam/Generated/Anam.ILLMsClient.DeleteLlm.g.cs @@ -9,10 +9,12 @@ public partial interface ILLMsClient /// Delete an LLM configuration. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task DeleteLlmAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.ILLMsClient.GetLlm.g.cs b/src/libs/Anam/Generated/Anam.ILLMsClient.GetLlm.g.cs index 633ef97..eeb1888 100644 --- a/src/libs/Anam/Generated/Anam.ILLMsClient.GetLlm.g.cs +++ b/src/libs/Anam/Generated/Anam.ILLMsClient.GetLlm.g.cs @@ -9,10 +9,12 @@ public partial interface ILLMsClient /// Get a specific LLM by ID. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GetLlmAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.ILLMsClient.ListLlms.g.cs b/src/libs/Anam/Generated/Anam.ILLMsClient.ListLlms.g.cs index 0eabba3..05ab5c1 100644 --- a/src/libs/Anam/Generated/Anam.ILLMsClient.ListLlms.g.cs +++ b/src/libs/Anam/Generated/Anam.ILLMsClient.ListLlms.g.cs @@ -12,6 +12,7 @@ public partial interface ILLMsClient /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ListLlmsAsync( @@ -19,6 +20,7 @@ public partial interface ILLMsClient int? perPage = default, string? search = default, bool? includeDefaults = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.ILLMsClient.UpdateLlm.g.cs b/src/libs/Anam/Generated/Anam.ILLMsClient.UpdateLlm.g.cs index 41fb5c4..3a9ec93 100644 --- a/src/libs/Anam/Generated/Anam.ILLMsClient.UpdateLlm.g.cs +++ b/src/libs/Anam/Generated/Anam.ILLMsClient.UpdateLlm.g.cs @@ -10,12 +10,14 @@ public partial interface ILLMsClient /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UpdateLlmAsync( string id, global::Anam.UpdateLlmRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Update LLM
@@ -31,6 +33,7 @@ public partial interface ILLMsClient /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UpdateLlmAsync( @@ -44,6 +47,7 @@ public partial interface ILLMsClient object? metadata = default, global::Anam.UpdateLlmRequestReasoningEffort? reasoningEffort = default, global::Anam.UpdateLlmRequestReasoningFormat? reasoningFormat = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.ILLMsClient.g.cs b/src/libs/Anam/Generated/Anam.ILLMsClient.g.cs index 339f9a4..be8fef2 100644 --- a/src/libs/Anam/Generated/Anam.ILLMsClient.g.cs +++ b/src/libs/Anam/Generated/Anam.ILLMsClient.g.cs @@ -33,6 +33,11 @@ public partial interface ILLMsClient : global::System.IDisposable ///
public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Anam.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Anam/Generated/Anam.IPersonasClient.CreatePersona.g.cs b/src/libs/Anam/Generated/Anam.IPersonasClient.CreatePersona.g.cs index 161469d..dd9d50b 100644 --- a/src/libs/Anam/Generated/Anam.IPersonasClient.CreatePersona.g.cs +++ b/src/libs/Anam/Generated/Anam.IPersonasClient.CreatePersona.g.cs @@ -9,11 +9,13 @@ public partial interface IPersonasClient /// Create a new persona with avatar, voice, LLM, and system prompt configuration. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task CreatePersonaAsync( global::Anam.PersonaConfig request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Create persona
@@ -60,6 +62,7 @@ public partial interface IPersonasClient /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task CreatePersonaAsync( @@ -78,6 +81,7 @@ public partial interface IPersonasClient global::System.Collections.Generic.IList? toolIds = default, global::System.DateTime? createdAt = default, global::System.DateTime? updatedAt = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IPersonasClient.DeletePersona.g.cs b/src/libs/Anam/Generated/Anam.IPersonasClient.DeletePersona.g.cs index 138ed4b..18cba2b 100644 --- a/src/libs/Anam/Generated/Anam.IPersonasClient.DeletePersona.g.cs +++ b/src/libs/Anam/Generated/Anam.IPersonasClient.DeletePersona.g.cs @@ -9,10 +9,12 @@ public partial interface IPersonasClient /// Delete a persona by ID. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task DeletePersonaAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IPersonasClient.GetPersona.g.cs b/src/libs/Anam/Generated/Anam.IPersonasClient.GetPersona.g.cs index 3c95f4e..4ba62d2 100644 --- a/src/libs/Anam/Generated/Anam.IPersonasClient.GetPersona.g.cs +++ b/src/libs/Anam/Generated/Anam.IPersonasClient.GetPersona.g.cs @@ -9,10 +9,12 @@ public partial interface IPersonasClient /// Returns a persona by ID. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GetPersonaAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IPersonasClient.ListPersonas.g.cs b/src/libs/Anam/Generated/Anam.IPersonasClient.ListPersonas.g.cs index 6ef1dae..c48c2cd 100644 --- a/src/libs/Anam/Generated/Anam.IPersonasClient.ListPersonas.g.cs +++ b/src/libs/Anam/Generated/Anam.IPersonasClient.ListPersonas.g.cs @@ -15,12 +15,14 @@ public partial interface IPersonasClient /// Default Value: 10 /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ListPersonasAsync( int? page = default, int? perPage = default, string? search = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IPersonasClient.UpdatePersona.g.cs b/src/libs/Anam/Generated/Anam.IPersonasClient.UpdatePersona.g.cs index 86f8f20..2f494fb 100644 --- a/src/libs/Anam/Generated/Anam.IPersonasClient.UpdatePersona.g.cs +++ b/src/libs/Anam/Generated/Anam.IPersonasClient.UpdatePersona.g.cs @@ -10,12 +10,14 @@ public partial interface IPersonasClient /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UpdatePersonaAsync( string id, global::Anam.PersonaConfig request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Update persona
@@ -63,6 +65,7 @@ public partial interface IPersonasClient /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UpdatePersonaAsync( @@ -82,6 +85,7 @@ public partial interface IPersonasClient global::System.Collections.Generic.IList? toolIds = default, global::System.DateTime? createdAt = default, global::System.DateTime? updatedAt = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IPersonasClient.g.cs b/src/libs/Anam/Generated/Anam.IPersonasClient.g.cs index 3d5909b..d319316 100644 --- a/src/libs/Anam/Generated/Anam.IPersonasClient.g.cs +++ b/src/libs/Anam/Generated/Anam.IPersonasClient.g.cs @@ -33,6 +33,11 @@ public partial interface IPersonasClient : global::System.IDisposable ///
public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Anam.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Anam/Generated/Anam.ISessionsClient.GetSession.g.cs b/src/libs/Anam/Generated/Anam.ISessionsClient.GetSession.g.cs index a4fda2d..27aa044 100644 --- a/src/libs/Anam/Generated/Anam.ISessionsClient.GetSession.g.cs +++ b/src/libs/Anam/Generated/Anam.ISessionsClient.GetSession.g.cs @@ -9,10 +9,12 @@ public partial interface ISessionsClient /// Returns a session by ID. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GetSessionAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.ISessionsClient.GetSessionRecording.g.cs b/src/libs/Anam/Generated/Anam.ISessionsClient.GetSessionRecording.g.cs index 5822bbe..314a104 100644 --- a/src/libs/Anam/Generated/Anam.ISessionsClient.GetSessionRecording.g.cs +++ b/src/libs/Anam/Generated/Anam.ISessionsClient.GetSessionRecording.g.cs @@ -9,10 +9,12 @@ public partial interface ISessionsClient /// Returns a presigned URL to download the session recording. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GetSessionRecordingAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.ISessionsClient.GetSessionTranscript.g.cs b/src/libs/Anam/Generated/Anam.ISessionsClient.GetSessionTranscript.g.cs index 8156fe0..f628981 100644 --- a/src/libs/Anam/Generated/Anam.ISessionsClient.GetSessionTranscript.g.cs +++ b/src/libs/Anam/Generated/Anam.ISessionsClient.GetSessionTranscript.g.cs @@ -9,10 +9,12 @@ public partial interface ISessionsClient /// Returns the conversation transcript for a session. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GetSessionTranscriptAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.ISessionsClient.ListSessions.g.cs b/src/libs/Anam/Generated/Anam.ISessionsClient.ListSessions.g.cs index b2f2c5b..d4e8362 100644 --- a/src/libs/Anam/Generated/Anam.ISessionsClient.ListSessions.g.cs +++ b/src/libs/Anam/Generated/Anam.ISessionsClient.ListSessions.g.cs @@ -17,6 +17,7 @@ public partial interface ISessionsClient /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ListSessionsAsync( @@ -25,6 +26,7 @@ public partial interface ISessionsClient string? search = default, global::System.Guid? apiKeyId = default, global::System.Guid? personaId = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.ISessionsClient.g.cs b/src/libs/Anam/Generated/Anam.ISessionsClient.g.cs index 9228458..0c54422 100644 --- a/src/libs/Anam/Generated/Anam.ISessionsClient.g.cs +++ b/src/libs/Anam/Generated/Anam.ISessionsClient.g.cs @@ -33,6 +33,11 @@ public partial interface ISessionsClient : global::System.IDisposable /// public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Anam.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Anam/Generated/Anam.IShareLinksClient.CreateShareLink.g.cs b/src/libs/Anam/Generated/Anam.IShareLinksClient.CreateShareLink.g.cs index d8c2d8e..daef542 100644 --- a/src/libs/Anam/Generated/Anam.IShareLinksClient.CreateShareLink.g.cs +++ b/src/libs/Anam/Generated/Anam.IShareLinksClient.CreateShareLink.g.cs @@ -9,11 +9,13 @@ public partial interface IShareLinksClient /// Create a new share link. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task CreateShareLinkAsync( global::Anam.CreateShareLinkRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Create share link
@@ -26,12 +28,14 @@ public partial interface IShareLinksClient /// /// Default Value: 10 /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task CreateShareLinkAsync( global::System.Guid personaId, double? expiresInHours = default, double? usageLimit = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IShareLinksClient.DeleteShareLink.g.cs b/src/libs/Anam/Generated/Anam.IShareLinksClient.DeleteShareLink.g.cs index d6c8261..53c1eaa 100644 --- a/src/libs/Anam/Generated/Anam.IShareLinksClient.DeleteShareLink.g.cs +++ b/src/libs/Anam/Generated/Anam.IShareLinksClient.DeleteShareLink.g.cs @@ -9,10 +9,12 @@ public partial interface IShareLinksClient /// Delete a share link by ID. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task DeleteShareLinkAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IShareLinksClient.GetShareLink.g.cs b/src/libs/Anam/Generated/Anam.IShareLinksClient.GetShareLink.g.cs index f8e9a90..05aae0e 100644 --- a/src/libs/Anam/Generated/Anam.IShareLinksClient.GetShareLink.g.cs +++ b/src/libs/Anam/Generated/Anam.IShareLinksClient.GetShareLink.g.cs @@ -9,10 +9,12 @@ public partial interface IShareLinksClient /// Returns a share link by ID. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GetShareLinkAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IShareLinksClient.ListShareLinks.g.cs b/src/libs/Anam/Generated/Anam.IShareLinksClient.ListShareLinks.g.cs index c50173b..f9f42dc 100644 --- a/src/libs/Anam/Generated/Anam.IShareLinksClient.ListShareLinks.g.cs +++ b/src/libs/Anam/Generated/Anam.IShareLinksClient.ListShareLinks.g.cs @@ -16,6 +16,7 @@ public partial interface IShareLinksClient /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ListShareLinksAsync( @@ -23,6 +24,7 @@ public partial interface IShareLinksClient int? perPage = default, string? search = default, global::System.Guid? personaId = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IShareLinksClient.UpdateShareLink.g.cs b/src/libs/Anam/Generated/Anam.IShareLinksClient.UpdateShareLink.g.cs index 65023c3..59ac835 100644 --- a/src/libs/Anam/Generated/Anam.IShareLinksClient.UpdateShareLink.g.cs +++ b/src/libs/Anam/Generated/Anam.IShareLinksClient.UpdateShareLink.g.cs @@ -10,12 +10,14 @@ public partial interface IShareLinksClient /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UpdateShareLinkAsync( global::System.Guid id, global::Anam.UpdateShareLinkRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Update share link
@@ -24,12 +26,14 @@ public partial interface IShareLinksClient /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UpdateShareLinkAsync( global::System.Guid id, double? expiresInHours = default, double? usageLimit = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IShareLinksClient.g.cs b/src/libs/Anam/Generated/Anam.IShareLinksClient.g.cs index 1f883c6..81405cd 100644 --- a/src/libs/Anam/Generated/Anam.IShareLinksClient.g.cs +++ b/src/libs/Anam/Generated/Anam.IShareLinksClient.g.cs @@ -33,6 +33,11 @@ public partial interface IShareLinksClient : global::System.IDisposable ///
public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Anam.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Anam/Generated/Anam.IToolsClient.CreateTool.g.cs b/src/libs/Anam/Generated/Anam.IToolsClient.CreateTool.g.cs index 7e433d9..327d5f1 100644 --- a/src/libs/Anam/Generated/Anam.IToolsClient.CreateTool.g.cs +++ b/src/libs/Anam/Generated/Anam.IToolsClient.CreateTool.g.cs @@ -9,11 +9,13 @@ public partial interface IToolsClient /// Create a new tool for function calling in persona sessions. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task CreateToolAsync( global::Anam.CreateToolRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Create tool
@@ -31,6 +33,7 @@ public partial interface IToolsClient /// /// Type-specific configuration for the tool. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task CreateToolAsync( @@ -38,6 +41,7 @@ public partial interface IToolsClient string description, global::Anam.CreateToolRequestType type, object? config = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IToolsClient.DeleteTool.g.cs b/src/libs/Anam/Generated/Anam.IToolsClient.DeleteTool.g.cs index 3778921..c986ae7 100644 --- a/src/libs/Anam/Generated/Anam.IToolsClient.DeleteTool.g.cs +++ b/src/libs/Anam/Generated/Anam.IToolsClient.DeleteTool.g.cs @@ -9,10 +9,12 @@ public partial interface IToolsClient /// Delete a tool (soft-deleted). ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task DeleteToolAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IToolsClient.GetTool.g.cs b/src/libs/Anam/Generated/Anam.IToolsClient.GetTool.g.cs index 73be854..24b2cb0 100644 --- a/src/libs/Anam/Generated/Anam.IToolsClient.GetTool.g.cs +++ b/src/libs/Anam/Generated/Anam.IToolsClient.GetTool.g.cs @@ -9,10 +9,12 @@ public partial interface IToolsClient /// Get a tool by ID. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GetToolAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IToolsClient.ListTools.g.cs b/src/libs/Anam/Generated/Anam.IToolsClient.ListTools.g.cs index 2040ebe..88c8047 100644 --- a/src/libs/Anam/Generated/Anam.IToolsClient.ListTools.g.cs +++ b/src/libs/Anam/Generated/Anam.IToolsClient.ListTools.g.cs @@ -15,12 +15,14 @@ public partial interface IToolsClient /// Default Value: 10 /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ListToolsAsync( int? page = default, int? perPage = default, string? search = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IToolsClient.UpdateTool.g.cs b/src/libs/Anam/Generated/Anam.IToolsClient.UpdateTool.g.cs index ef2e3ee..3ea703c 100644 --- a/src/libs/Anam/Generated/Anam.IToolsClient.UpdateTool.g.cs +++ b/src/libs/Anam/Generated/Anam.IToolsClient.UpdateTool.g.cs @@ -10,12 +10,14 @@ public partial interface IToolsClient /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UpdateToolAsync( global::System.Guid id, global::Anam.UpdateToolRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Update tool
@@ -32,6 +34,7 @@ public partial interface IToolsClient /// /// Updated type-specific configuration. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UpdateToolAsync( @@ -40,6 +43,7 @@ public partial interface IToolsClient string? description = default, global::Anam.UpdateToolRequestType? type = default, object? config = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IToolsClient.g.cs b/src/libs/Anam/Generated/Anam.IToolsClient.g.cs index 567ffd6..47529cf 100644 --- a/src/libs/Anam/Generated/Anam.IToolsClient.g.cs +++ b/src/libs/Anam/Generated/Anam.IToolsClient.g.cs @@ -33,6 +33,11 @@ public partial interface IToolsClient : global::System.IDisposable ///
public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Anam.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Anam/Generated/Anam.IVoicesClient.CreateVoice.g.cs b/src/libs/Anam/Generated/Anam.IVoicesClient.CreateVoice.g.cs index fe0c528..468e366 100644 --- a/src/libs/Anam/Generated/Anam.IVoicesClient.CreateVoice.g.cs +++ b/src/libs/Anam/Generated/Anam.IVoicesClient.CreateVoice.g.cs @@ -9,11 +9,13 @@ public partial interface IVoicesClient /// Create a new voice by cloning from an audio file. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task CreateVoiceAsync( global::Anam.CreateVoiceRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Create voice
@@ -39,6 +41,7 @@ public partial interface IVoicesClient /// Whether to enhance the voice quality.
/// Default Value: true /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task CreateVoiceAsync( @@ -48,6 +51,7 @@ public partial interface IVoicesClient string? description = default, string? language = default, bool? enhance = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IVoicesClient.DeleteVoice.g.cs b/src/libs/Anam/Generated/Anam.IVoicesClient.DeleteVoice.g.cs index 5bf6573..a688a6b 100644 --- a/src/libs/Anam/Generated/Anam.IVoicesClient.DeleteVoice.g.cs +++ b/src/libs/Anam/Generated/Anam.IVoicesClient.DeleteVoice.g.cs @@ -9,10 +9,12 @@ public partial interface IVoicesClient /// Delete a voice by ID. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task DeleteVoiceAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IVoicesClient.GetVoice.g.cs b/src/libs/Anam/Generated/Anam.IVoicesClient.GetVoice.g.cs index 46ba09c..b281809 100644 --- a/src/libs/Anam/Generated/Anam.IVoicesClient.GetVoice.g.cs +++ b/src/libs/Anam/Generated/Anam.IVoicesClient.GetVoice.g.cs @@ -9,10 +9,12 @@ public partial interface IVoicesClient /// Returns a voice by ID. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task GetVoiceAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IVoicesClient.ListVoices.g.cs b/src/libs/Anam/Generated/Anam.IVoicesClient.ListVoices.g.cs index b05f6da..3c8741a 100644 --- a/src/libs/Anam/Generated/Anam.IVoicesClient.ListVoices.g.cs +++ b/src/libs/Anam/Generated/Anam.IVoicesClient.ListVoices.g.cs @@ -15,12 +15,14 @@ public partial interface IVoicesClient /// Default Value: 10 /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task ListVoicesAsync( int? page = default, int? perPage = default, string? search = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IVoicesClient.UpdateVoice.g.cs b/src/libs/Anam/Generated/Anam.IVoicesClient.UpdateVoice.g.cs index c46ddb4..cc7c124 100644 --- a/src/libs/Anam/Generated/Anam.IVoicesClient.UpdateVoice.g.cs +++ b/src/libs/Anam/Generated/Anam.IVoicesClient.UpdateVoice.g.cs @@ -10,12 +10,14 @@ public partial interface IVoicesClient /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UpdateVoiceAsync( global::System.Guid id, global::Anam.UpdateVoiceRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); /// /// Update voice
@@ -33,6 +35,7 @@ public partial interface IVoicesClient /// ISO 3166-1 alpha-2 country code. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// global::System.Threading.Tasks.Task UpdateVoiceAsync( @@ -42,6 +45,7 @@ public partial interface IVoicesClient global::Anam.UpdateVoiceRequestGender? gender = default, string? country = default, string? description = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default); } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.IVoicesClient.g.cs b/src/libs/Anam/Generated/Anam.IVoicesClient.g.cs index 9dbda44..58a8c7b 100644 --- a/src/libs/Anam/Generated/Anam.IVoicesClient.g.cs +++ b/src/libs/Anam/Generated/Anam.IVoicesClient.g.cs @@ -33,6 +33,11 @@ public partial interface IVoicesClient : global::System.IDisposable ///
public bool ReadResponseAsString { get; set; } + /// + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// + public global::Anam.AutoSDKClientOptions Options { get; } + /// /// /// diff --git a/src/libs/Anam/Generated/Anam.KnowledgeClient.CreateKnowledgeGroup.g.cs b/src/libs/Anam/Generated/Anam.KnowledgeClient.CreateKnowledgeGroup.g.cs index 2aab3d7..ccb6d76 100644 --- a/src/libs/Anam/Generated/Anam.KnowledgeClient.CreateKnowledgeGroup.g.cs +++ b/src/libs/Anam/Generated/Anam.KnowledgeClient.CreateKnowledgeGroup.g.cs @@ -14,6 +14,7 @@ public partial class KnowledgeClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,11 +46,13 @@ partial void ProcessCreateKnowledgeGroupResponseContent( /// Create a new knowledge group for RAG. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task CreateKnowledgeGroupAsync( global::Anam.CreateKnowledgeGroupRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -66,22 +69,43 @@ partial void ProcessCreateKnowledgeGroupResponseContent( securityRequirements: s_CreateKnowledgeGroupSecurityRequirements, operationName: "CreateKnowledgeGroupAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: "/v1/knowledge/groups", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: "/v1/knowledge/groups", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -91,217 +115,376 @@ partial void ProcessCreateKnowledgeGroupResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareCreateKnowledgeGroupRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareCreateKnowledgeGroupRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - ProcessResponse( - client: HttpClient, - response: __response); - ProcessCreateKnowledgeGroupResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + return __httpRequest; + } + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateKnowledgeGroup", + methodName: "CreateKnowledgeGroupAsync", + pathTemplate: "\"/v1/knowledge/groups\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateKnowledgeGroup", + methodName: "CreateKnowledgeGroupAsync", + pathTemplate: "\"/v1/knowledge/groups\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateKnowledgeGroup", + methodName: "CreateKnowledgeGroupAsync", + pathTemplate: "\"/v1/knowledge/groups\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_401 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessCreateKnowledgeGroupResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateKnowledgeGroup", + methodName: "CreateKnowledgeGroupAsync", + pathTemplate: "\"/v1/knowledge/groups\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateKnowledgeGroup", + methodName: "CreateKnowledgeGroupAsync", + pathTemplate: "\"/v1/knowledge/groups\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessCreateKnowledgeGroupResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - try - { - __response.EnsureSuccessStatusCode(); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - global::Anam.KnowledgeGroup.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessCreateKnowledgeGroupResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); - return - await global::Anam.KnowledgeGroup.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.KnowledgeGroup.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.KnowledgeGroup.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Create knowledge group
@@ -309,11 +492,13 @@ partial void ProcessCreateKnowledgeGroupResponseContent( ///
/// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task CreateKnowledgeGroupAsync( string name, string? description = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.CreateKnowledgeGroupRequest @@ -324,6 +509,7 @@ partial void ProcessCreateKnowledgeGroupResponseContent( return await CreateKnowledgeGroupAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.KnowledgeClient.DeleteKnowledgeDocument.g.cs b/src/libs/Anam/Generated/Anam.KnowledgeClient.DeleteKnowledgeDocument.g.cs index 7ccdcd2..4d9f7c7 100644 --- a/src/libs/Anam/Generated/Anam.KnowledgeClient.DeleteKnowledgeDocument.g.cs +++ b/src/libs/Anam/Generated/Anam.KnowledgeClient.DeleteKnowledgeDocument.g.cs @@ -14,6 +14,7 @@ public partial class KnowledgeClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -40,10 +41,12 @@ partial void ProcessDeleteKnowledgeDocumentResponse( /// Delete a document from a knowledge group. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task DeleteKnowledgeDocumentAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -58,22 +61,43 @@ partial void ProcessDeleteKnowledgeDocumentResponse( securityRequirements: s_DeleteKnowledgeDocumentSecurityRequirements, operationName: "DeleteKnowledgeDocumentAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/knowledge/documents/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Delete, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/knowledge/documents/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Delete, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -83,194 +107,353 @@ partial void ProcessDeleteKnowledgeDocumentResponse( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareDeleteKnowledgeDocumentRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareDeleteKnowledgeDocumentRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessDeleteKnowledgeDocumentResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteKnowledgeDocument", + methodName: "DeleteKnowledgeDocumentAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteKnowledgeDocument", + methodName: "DeleteKnowledgeDocumentAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteKnowledgeDocument", + methodName: "DeleteKnowledgeDocumentAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessDeleteKnowledgeDocumentResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteKnowledgeDocument", + methodName: "DeleteKnowledgeDocumentAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteKnowledgeDocument", + methodName: "DeleteKnowledgeDocumentAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - try - { - __response.EnsureSuccessStatusCode(); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Anam/Generated/Anam.KnowledgeClient.DeleteKnowledgeGroup.g.cs b/src/libs/Anam/Generated/Anam.KnowledgeClient.DeleteKnowledgeGroup.g.cs index 9721a3f..0c5180f 100644 --- a/src/libs/Anam/Generated/Anam.KnowledgeClient.DeleteKnowledgeGroup.g.cs +++ b/src/libs/Anam/Generated/Anam.KnowledgeClient.DeleteKnowledgeGroup.g.cs @@ -14,6 +14,7 @@ public partial class KnowledgeClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -40,10 +41,12 @@ partial void ProcessDeleteKnowledgeGroupResponse( /// Delete a knowledge group. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task DeleteKnowledgeGroupAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -58,22 +61,43 @@ partial void ProcessDeleteKnowledgeGroupResponse( securityRequirements: s_DeleteKnowledgeGroupSecurityRequirements, operationName: "DeleteKnowledgeGroupAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/knowledge/groups/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Delete, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/knowledge/groups/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Delete, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -83,194 +107,353 @@ partial void ProcessDeleteKnowledgeGroupResponse( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareDeleteKnowledgeGroupRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareDeleteKnowledgeGroupRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessDeleteKnowledgeGroupResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteKnowledgeGroup", + methodName: "DeleteKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteKnowledgeGroup", + methodName: "DeleteKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteKnowledgeGroup", + methodName: "DeleteKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessDeleteKnowledgeGroupResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteKnowledgeGroup", + methodName: "DeleteKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteKnowledgeGroup", + methodName: "DeleteKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - try - { - __response.EnsureSuccessStatusCode(); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Anam/Generated/Anam.KnowledgeClient.GetKnowledgeDocument.g.cs b/src/libs/Anam/Generated/Anam.KnowledgeClient.GetKnowledgeDocument.g.cs index c442cfb..75131a4 100644 --- a/src/libs/Anam/Generated/Anam.KnowledgeClient.GetKnowledgeDocument.g.cs +++ b/src/libs/Anam/Generated/Anam.KnowledgeClient.GetKnowledgeDocument.g.cs @@ -14,6 +14,7 @@ public partial class KnowledgeClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,10 +46,12 @@ partial void ProcessGetKnowledgeDocumentResponseContent( /// Get a single document by ID. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GetKnowledgeDocumentAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -63,22 +66,43 @@ partial void ProcessGetKnowledgeDocumentResponseContent( securityRequirements: s_GetKnowledgeDocumentSecurityRequirements, operationName: "GetKnowledgeDocumentAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/knowledge/documents/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/knowledge/documents/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -88,211 +112,370 @@ partial void ProcessGetKnowledgeDocumentResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGetKnowledgeDocumentRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGetKnowledgeDocumentRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGetKnowledgeDocumentResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetKnowledgeDocument", + methodName: "GetKnowledgeDocumentAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetKnowledgeDocument", + methodName: "GetKnowledgeDocumentAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetKnowledgeDocument", + methodName: "GetKnowledgeDocumentAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessGetKnowledgeDocumentResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetKnowledgeDocument", + methodName: "GetKnowledgeDocumentAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetKnowledgeDocument", + methodName: "GetKnowledgeDocumentAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessGetKnowledgeDocumentResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - try - { - __response.EnsureSuccessStatusCode(); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - global::Anam.KnowledgeDocument.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGetKnowledgeDocumentResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); - return - await global::Anam.KnowledgeDocument.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.KnowledgeDocument.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.KnowledgeDocument.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.KnowledgeClient.GetKnowledgeDocumentDownload.g.cs b/src/libs/Anam/Generated/Anam.KnowledgeClient.GetKnowledgeDocumentDownload.g.cs index 11a9df0..2f332b5 100644 --- a/src/libs/Anam/Generated/Anam.KnowledgeClient.GetKnowledgeDocumentDownload.g.cs +++ b/src/libs/Anam/Generated/Anam.KnowledgeClient.GetKnowledgeDocumentDownload.g.cs @@ -14,6 +14,7 @@ public partial class KnowledgeClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,10 +46,12 @@ partial void ProcessGetKnowledgeDocumentDownloadResponseContent( /// Get a presigned download URL for a knowledge document. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GetKnowledgeDocumentDownloadAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -63,22 +66,43 @@ partial void ProcessGetKnowledgeDocumentDownloadResponseContent( securityRequirements: s_GetKnowledgeDocumentDownloadSecurityRequirements, operationName: "GetKnowledgeDocumentDownloadAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/knowledge/documents/{id}/download", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/knowledge/documents/{id}/download", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -88,211 +112,370 @@ partial void ProcessGetKnowledgeDocumentDownloadResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGetKnowledgeDocumentDownloadRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGetKnowledgeDocumentDownloadRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGetKnowledgeDocumentDownloadResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetKnowledgeDocumentDownload", + methodName: "GetKnowledgeDocumentDownloadAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}/download\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetKnowledgeDocumentDownload", + methodName: "GetKnowledgeDocumentDownloadAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}/download\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetKnowledgeDocumentDownload", + methodName: "GetKnowledgeDocumentDownloadAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}/download\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessGetKnowledgeDocumentDownloadResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetKnowledgeDocumentDownload", + methodName: "GetKnowledgeDocumentDownloadAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}/download\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetKnowledgeDocumentDownload", + methodName: "GetKnowledgeDocumentDownloadAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}/download\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessGetKnowledgeDocumentDownloadResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - try - { - __response.EnsureSuccessStatusCode(); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - global::Anam.GetKnowledgeDocumentDownloadResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGetKnowledgeDocumentDownloadResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); - return - await global::Anam.GetKnowledgeDocumentDownloadResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.GetKnowledgeDocumentDownloadResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.GetKnowledgeDocumentDownloadResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.KnowledgeClient.GetKnowledgeGroup.g.cs b/src/libs/Anam/Generated/Anam.KnowledgeClient.GetKnowledgeGroup.g.cs index 3c12c5a..3947672 100644 --- a/src/libs/Anam/Generated/Anam.KnowledgeClient.GetKnowledgeGroup.g.cs +++ b/src/libs/Anam/Generated/Anam.KnowledgeClient.GetKnowledgeGroup.g.cs @@ -14,6 +14,7 @@ public partial class KnowledgeClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,10 +46,12 @@ partial void ProcessGetKnowledgeGroupResponseContent( /// Get a single knowledge group by ID. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GetKnowledgeGroupAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -63,22 +66,43 @@ partial void ProcessGetKnowledgeGroupResponseContent( securityRequirements: s_GetKnowledgeGroupSecurityRequirements, operationName: "GetKnowledgeGroupAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/knowledge/groups/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/knowledge/groups/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -88,211 +112,370 @@ partial void ProcessGetKnowledgeGroupResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGetKnowledgeGroupRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGetKnowledgeGroupRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGetKnowledgeGroupResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetKnowledgeGroup", + methodName: "GetKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetKnowledgeGroup", + methodName: "GetKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetKnowledgeGroup", + methodName: "GetKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessGetKnowledgeGroupResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetKnowledgeGroup", + methodName: "GetKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetKnowledgeGroup", + methodName: "GetKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessGetKnowledgeGroupResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - try - { - __response.EnsureSuccessStatusCode(); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - global::Anam.KnowledgeGroup.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGetKnowledgeGroupResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); - return - await global::Anam.KnowledgeGroup.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.KnowledgeGroup.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.KnowledgeGroup.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.KnowledgeClient.ListKnowledgeGroupDocuments.g.cs b/src/libs/Anam/Generated/Anam.KnowledgeClient.ListKnowledgeGroupDocuments.g.cs index bac34db..46ec132 100644 --- a/src/libs/Anam/Generated/Anam.KnowledgeClient.ListKnowledgeGroupDocuments.g.cs +++ b/src/libs/Anam/Generated/Anam.KnowledgeClient.ListKnowledgeGroupDocuments.g.cs @@ -14,6 +14,7 @@ public partial class KnowledgeClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,10 +46,12 @@ partial void ProcessListKnowledgeGroupDocumentsResponseContent( /// Get all documents in a knowledge group. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ListKnowledgeGroupDocumentsAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -63,22 +66,43 @@ partial void ProcessListKnowledgeGroupDocumentsResponseContent( securityRequirements: s_ListKnowledgeGroupDocumentsSecurityRequirements, operationName: "ListKnowledgeGroupDocumentsAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/knowledge/groups/{id}/documents", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/knowledge/groups/{id}/documents", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -88,211 +112,370 @@ partial void ProcessListKnowledgeGroupDocumentsResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareListKnowledgeGroupDocumentsRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareListKnowledgeGroupDocumentsRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessListKnowledgeGroupDocumentsResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListKnowledgeGroupDocuments", + methodName: "ListKnowledgeGroupDocumentsAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}/documents\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListKnowledgeGroupDocuments", + methodName: "ListKnowledgeGroupDocumentsAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}/documents\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListKnowledgeGroupDocuments", + methodName: "ListKnowledgeGroupDocumentsAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}/documents\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessListKnowledgeGroupDocumentsResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListKnowledgeGroupDocuments", + methodName: "ListKnowledgeGroupDocumentsAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}/documents\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListKnowledgeGroupDocuments", + methodName: "ListKnowledgeGroupDocumentsAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}/documents\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessListKnowledgeGroupDocumentsResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - try - { - __response.EnsureSuccessStatusCode(); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - global::Anam.ListKnowledgeGroupDocumentsResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessListKnowledgeGroupDocumentsResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); - return - await global::Anam.ListKnowledgeGroupDocumentsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.ListKnowledgeGroupDocumentsResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.ListKnowledgeGroupDocumentsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.KnowledgeClient.ListKnowledgeGroups.g.cs b/src/libs/Anam/Generated/Anam.KnowledgeClient.ListKnowledgeGroups.g.cs index 8864dca..000973a 100644 --- a/src/libs/Anam/Generated/Anam.KnowledgeClient.ListKnowledgeGroups.g.cs +++ b/src/libs/Anam/Generated/Anam.KnowledgeClient.ListKnowledgeGroups.g.cs @@ -14,6 +14,7 @@ public partial class KnowledgeClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -42,9 +43,11 @@ partial void ProcessListKnowledgeGroupsResponseContent( /// List knowledge groups
/// Returns a list of all knowledge groups for the organization. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ListKnowledgeGroupsAsync( + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -58,22 +61,43 @@ partial void ProcessListKnowledgeGroupsResponseContent( securityRequirements: s_ListKnowledgeGroupsSecurityRequirements, operationName: "ListKnowledgeGroupsAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: "/v1/knowledge/groups", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: "/v1/knowledge/groups", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -83,177 +107,336 @@ partial void ProcessListKnowledgeGroupsResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareListKnowledgeGroupsRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareListKnowledgeGroupsRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessListKnowledgeGroupsResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListKnowledgeGroups", + methodName: "ListKnowledgeGroupsAsync", + pathTemplate: "\"/v1/knowledge/groups\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListKnowledgeGroups", + methodName: "ListKnowledgeGroupsAsync", + pathTemplate: "\"/v1/knowledge/groups\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try - { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListKnowledgeGroups", + methodName: "ListKnowledgeGroupsAsync", + pathTemplate: "\"/v1/knowledge/groups\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_500 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessListKnowledgeGroupsResponseContent( + response: __response); + ProcessListKnowledgeGroupsResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - __response.EnsureSuccessStatusCode(); - - return - global::Anam.ListKnowledgeGroupsResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListKnowledgeGroups", + methodName: "ListKnowledgeGroupsAsync", + pathTemplate: "\"/v1/knowledge/groups\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListKnowledgeGroups", + methodName: "ListKnowledgeGroupsAsync", + pathTemplate: "\"/v1/knowledge/groups\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - return - await global::Anam.ListKnowledgeGroupsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessListKnowledgeGroupsResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.ListKnowledgeGroupsResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.ListKnowledgeGroupsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.KnowledgeClient.SearchKnowledgeGroup.g.cs b/src/libs/Anam/Generated/Anam.KnowledgeClient.SearchKnowledgeGroup.g.cs index 89aa461..34d984b 100644 --- a/src/libs/Anam/Generated/Anam.KnowledgeClient.SearchKnowledgeGroup.g.cs +++ b/src/libs/Anam/Generated/Anam.KnowledgeClient.SearchKnowledgeGroup.g.cs @@ -14,6 +14,7 @@ public partial class KnowledgeClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -48,12 +49,14 @@ partial void ProcessSearchKnowledgeGroupResponseContent( /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task SearchKnowledgeGroupAsync( string id, global::Anam.SearchKnowledgeGroupRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -71,22 +74,43 @@ partial void ProcessSearchKnowledgeGroupResponseContent( securityRequirements: s_SearchKnowledgeGroupSecurityRequirements, operationName: "SearchKnowledgeGroupAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/knowledge/groups/{id}/search", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/knowledge/groups/{id}/search", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -96,251 +120,410 @@ partial void ProcessSearchKnowledgeGroupResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareSearchKnowledgeGroupRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - ProcessResponse( - client: HttpClient, - response: __response); - ProcessSearchKnowledgeGroupResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareSearchKnowledgeGroupRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id, + request: request); - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // - if ((int)__response.StatusCode == 401) + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SearchKnowledgeGroup", + methodName: "SearchKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}/search\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SearchKnowledgeGroup", + methodName: "SearchKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}/search\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SearchKnowledgeGroup", + methodName: "SearchKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}/search\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessSearchKnowledgeGroupResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SearchKnowledgeGroup", + methodName: "SearchKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}/search\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "SearchKnowledgeGroup", + methodName: "SearchKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}/search\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessSearchKnowledgeGroupResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - global::Anam.SearchKnowledgeGroupResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - await global::Anam.SearchKnowledgeGroupResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessSearchKnowledgeGroupResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.SearchKnowledgeGroupResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.SearchKnowledgeGroupResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Search knowledge group
@@ -351,12 +534,14 @@ partial void ProcessSearchKnowledgeGroupResponseContent( /// /// Default Value: 5 /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task SearchKnowledgeGroupAsync( string id, string query, int? limit = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.SearchKnowledgeGroupRequest @@ -368,6 +553,7 @@ partial void ProcessSearchKnowledgeGroupResponseContent( return await SearchKnowledgeGroupAsync( id: id, request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.KnowledgeClient.UpdateKnowledgeDocument.g.cs b/src/libs/Anam/Generated/Anam.KnowledgeClient.UpdateKnowledgeDocument.g.cs index e4d6eac..74d8746 100644 --- a/src/libs/Anam/Generated/Anam.KnowledgeClient.UpdateKnowledgeDocument.g.cs +++ b/src/libs/Anam/Generated/Anam.KnowledgeClient.UpdateKnowledgeDocument.g.cs @@ -14,6 +14,7 @@ public partial class KnowledgeClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -48,12 +49,14 @@ partial void ProcessUpdateKnowledgeDocumentResponseContent( ///
/// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UpdateKnowledgeDocumentAsync( string id, global::Anam.UpdateKnowledgeDocumentRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -71,22 +74,43 @@ partial void ProcessUpdateKnowledgeDocumentResponseContent( securityRequirements: s_UpdateKnowledgeDocumentSecurityRequirements, operationName: "UpdateKnowledgeDocumentAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/knowledge/documents/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Put, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/knowledge/documents/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Put, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -96,251 +120,410 @@ partial void ProcessUpdateKnowledgeDocumentResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareUpdateKnowledgeDocumentRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - ProcessResponse( - client: HttpClient, - response: __response); - ProcessUpdateKnowledgeDocumentResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareUpdateKnowledgeDocumentRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id, + request: request); - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // - if ((int)__response.StatusCode == 401) + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateKnowledgeDocument", + methodName: "UpdateKnowledgeDocumentAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateKnowledgeDocument", + methodName: "UpdateKnowledgeDocumentAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateKnowledgeDocument", + methodName: "UpdateKnowledgeDocumentAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessUpdateKnowledgeDocumentResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateKnowledgeDocument", + methodName: "UpdateKnowledgeDocumentAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateKnowledgeDocument", + methodName: "UpdateKnowledgeDocumentAsync", + pathTemplate: "$\"/v1/knowledge/documents/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessUpdateKnowledgeDocumentResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - global::Anam.KnowledgeDocument.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - await global::Anam.KnowledgeDocument.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessUpdateKnowledgeDocumentResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.KnowledgeDocument.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.KnowledgeDocument.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Update knowledge document
@@ -350,11 +533,13 @@ partial void ProcessUpdateKnowledgeDocumentResponseContent( /// /// New filename for the document. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UpdateKnowledgeDocumentAsync( string id, string? filename = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.UpdateKnowledgeDocumentRequest @@ -365,6 +550,7 @@ partial void ProcessUpdateKnowledgeDocumentResponseContent( return await UpdateKnowledgeDocumentAsync( id: id, request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.KnowledgeClient.UpdateKnowledgeGroup.g.cs b/src/libs/Anam/Generated/Anam.KnowledgeClient.UpdateKnowledgeGroup.g.cs index 5914ff5..9ce94ad 100644 --- a/src/libs/Anam/Generated/Anam.KnowledgeClient.UpdateKnowledgeGroup.g.cs +++ b/src/libs/Anam/Generated/Anam.KnowledgeClient.UpdateKnowledgeGroup.g.cs @@ -14,6 +14,7 @@ public partial class KnowledgeClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -48,12 +49,14 @@ partial void ProcessUpdateKnowledgeGroupResponseContent( ///
/// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UpdateKnowledgeGroupAsync( string id, global::Anam.UpdateKnowledgeGroupRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -71,22 +74,43 @@ partial void ProcessUpdateKnowledgeGroupResponseContent( securityRequirements: s_UpdateKnowledgeGroupSecurityRequirements, operationName: "UpdateKnowledgeGroupAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/knowledge/groups/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Put, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/knowledge/groups/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Put, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -96,251 +120,410 @@ partial void ProcessUpdateKnowledgeGroupResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareUpdateKnowledgeGroupRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - ProcessResponse( - client: HttpClient, - response: __response); - ProcessUpdateKnowledgeGroupResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareUpdateKnowledgeGroupRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id, + request: request); - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // - if ((int)__response.StatusCode == 401) + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateKnowledgeGroup", + methodName: "UpdateKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateKnowledgeGroup", + methodName: "UpdateKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateKnowledgeGroup", + methodName: "UpdateKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessUpdateKnowledgeGroupResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateKnowledgeGroup", + methodName: "UpdateKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateKnowledgeGroup", + methodName: "UpdateKnowledgeGroupAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessUpdateKnowledgeGroupResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - global::Anam.KnowledgeGroup.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - await global::Anam.KnowledgeGroup.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessUpdateKnowledgeGroupResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.KnowledgeGroup.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.KnowledgeGroup.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Update knowledge group
@@ -349,12 +532,14 @@ partial void ProcessUpdateKnowledgeGroupResponseContent( /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UpdateKnowledgeGroupAsync( string id, string? name = default, string? description = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.UpdateKnowledgeGroupRequest @@ -366,6 +551,7 @@ partial void ProcessUpdateKnowledgeGroupResponseContent( return await UpdateKnowledgeGroupAsync( id: id, request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.KnowledgeClient.UploadKnowledgeGroupDocument.g.cs b/src/libs/Anam/Generated/Anam.KnowledgeClient.UploadKnowledgeGroupDocument.g.cs index edb021e..ca52d62 100644 --- a/src/libs/Anam/Generated/Anam.KnowledgeClient.UploadKnowledgeGroupDocument.g.cs +++ b/src/libs/Anam/Generated/Anam.KnowledgeClient.UploadKnowledgeGroupDocument.g.cs @@ -14,6 +14,7 @@ public partial class KnowledgeClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -48,12 +49,14 @@ partial void ProcessUploadKnowledgeGroupDocumentResponseContent( ///
/// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UploadKnowledgeGroupDocumentAsync( string id, global::Anam.UploadKnowledgeGroupDocumentRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -71,22 +74,43 @@ partial void ProcessUploadKnowledgeGroupDocumentResponseContent( securityRequirements: s_UploadKnowledgeGroupDocumentSecurityRequirements, operationName: "UploadKnowledgeGroupDocumentAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/knowledge/groups/{id}/documents", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/knowledge/groups/{id}/documents", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -96,273 +120,432 @@ partial void ProcessUploadKnowledgeGroupDocumentResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{id}"), - name: "\"id\""); - var __contentFile = new global::System.Net.Http.ByteArrayContent(request.File ?? global::System.Array.Empty()); - __httpRequestContent.Add( - content: __contentFile, - name: "\"file\"", - fileName: request.Filename != null ? $"\"{request.Filename}\"" : string.Empty); - if (__contentFile.Headers.ContentDisposition != null) - { - __contentFile.Headers.ContentDisposition.FileNameStar = null; - } - if (request.ChunkSize != default) - { + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{id}"), + name: "\"id\""); + var __contentFile = new global::System.Net.Http.ByteArrayContent(request.File ?? global::System.Array.Empty()); + __httpRequestContent.Add( + content: __contentFile, + name: "\"file\"", + fileName: request.Filename != null ? $"\"{request.Filename}\"" : string.Empty); + if (__contentFile.Headers.ContentDisposition != null) + { + __contentFile.Headers.ContentDisposition.FileNameStar = null; + } + if (request.ChunkSize != default) + { - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.ChunkSize}"), - name: "\"chunkSize\""); - } - if (request.ChunkOverlap != default) - { + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.ChunkSize}"), + name: "\"chunkSize\""); + } + if (request.ChunkOverlap != default) + { - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.ChunkOverlap}"), - name: "\"chunkOverlap\""); - } - __httpRequest.Content = __httpRequestContent; + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.ChunkOverlap}"), + name: "\"chunkOverlap\""); + } + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareUploadKnowledgeGroupDocumentRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id, - request: request); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareUploadKnowledgeGroupDocumentRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id, + request: request); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessUploadKnowledgeGroupDocumentResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UploadKnowledgeGroupDocument", + methodName: "UploadKnowledgeGroupDocumentAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}/documents\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UploadKnowledgeGroupDocument", + methodName: "UploadKnowledgeGroupDocumentAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}/documents\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UploadKnowledgeGroupDocument", + methodName: "UploadKnowledgeGroupDocumentAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}/documents\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessUploadKnowledgeGroupDocumentResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UploadKnowledgeGroupDocument", + methodName: "UploadKnowledgeGroupDocumentAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}/documents\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UploadKnowledgeGroupDocument", + methodName: "UploadKnowledgeGroupDocumentAsync", + pathTemplate: "$\"/v1/knowledge/groups/{id}/documents\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessUploadKnowledgeGroupDocumentResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - global::Anam.KnowledgeDocument.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - await global::Anam.KnowledgeDocument.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessUploadKnowledgeGroupDocumentResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.KnowledgeDocument.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.KnowledgeDocument.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Upload knowledge group document
@@ -381,6 +564,7 @@ partial void ProcessUploadKnowledgeGroupDocumentResponseContent( /// /// Default Value: 200 /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UploadKnowledgeGroupDocumentAsync( @@ -389,6 +573,7 @@ partial void ProcessUploadKnowledgeGroupDocumentResponseContent( string filename, int? chunkSize = default, int? chunkOverlap = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.UploadKnowledgeGroupDocumentRequest @@ -402,6 +587,7 @@ partial void ProcessUploadKnowledgeGroupDocumentResponseContent( return await UploadKnowledgeGroupDocumentAsync( id: id, request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.KnowledgeClient.g.cs b/src/libs/Anam/Generated/Anam.KnowledgeClient.g.cs index c1cd85e..651d46b 100644 --- a/src/libs/Anam/Generated/Anam.KnowledgeClient.g.cs +++ b/src/libs/Anam/Generated/Anam.KnowledgeClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class KnowledgeClient : global::Anam.IKnowledgeClient, glo #if DEBUG = true; #endif + + /// + public global::Anam.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public KnowledgeClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the KnowledgeClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public KnowledgeClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Anam.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Anam.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Anam/Generated/Anam.LLMsClient.CreateLlm.g.cs b/src/libs/Anam/Generated/Anam.LLMsClient.CreateLlm.g.cs index 3411237..010c44b 100644 --- a/src/libs/Anam/Generated/Anam.LLMsClient.CreateLlm.g.cs +++ b/src/libs/Anam/Generated/Anam.LLMsClient.CreateLlm.g.cs @@ -14,6 +14,7 @@ public partial class LLMsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,11 +46,13 @@ partial void ProcessCreateLlmResponseContent( /// Create a new LLM configuration. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task CreateLlmAsync( global::Anam.CreateLlmRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -66,22 +69,43 @@ partial void ProcessCreateLlmResponseContent( securityRequirements: s_CreateLlmSecurityRequirements, operationName: "CreateLlmAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: "/v1/llms", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: "/v1/llms", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -91,217 +115,376 @@ partial void ProcessCreateLlmResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareCreateLlmRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareCreateLlmRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - ProcessResponse( - client: HttpClient, - response: __response); - ProcessCreateLlmResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + return __httpRequest; + } + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateLlm", + methodName: "CreateLlmAsync", + pathTemplate: "\"/v1/llms\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateLlm", + methodName: "CreateLlmAsync", + pathTemplate: "\"/v1/llms\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateLlm", + methodName: "CreateLlmAsync", + pathTemplate: "\"/v1/llms\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_401 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessCreateLlmResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateLlm", + methodName: "CreateLlmAsync", + pathTemplate: "\"/v1/llms\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateLlm", + methodName: "CreateLlmAsync", + pathTemplate: "\"/v1/llms\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessCreateLlmResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - try - { - __response.EnsureSuccessStatusCode(); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - global::Anam.Llm.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessCreateLlmResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); - return - await global::Anam.Llm.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.Llm.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.Llm.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Create LLM
@@ -316,6 +499,7 @@ partial void ProcessCreateLlmResponseContent( /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task CreateLlmAsync( @@ -328,6 +512,7 @@ partial void ProcessCreateLlmResponseContent( object? metadata = default, global::Anam.CreateLlmRequestReasoningEffort? reasoningEffort = default, global::Anam.CreateLlmRequestReasoningFormat? reasoningFormat = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.CreateLlmRequest @@ -345,6 +530,7 @@ partial void ProcessCreateLlmResponseContent( return await CreateLlmAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.LLMsClient.DeleteLlm.g.cs b/src/libs/Anam/Generated/Anam.LLMsClient.DeleteLlm.g.cs index e1686bf..711d043 100644 --- a/src/libs/Anam/Generated/Anam.LLMsClient.DeleteLlm.g.cs +++ b/src/libs/Anam/Generated/Anam.LLMsClient.DeleteLlm.g.cs @@ -14,6 +14,7 @@ public partial class LLMsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -40,10 +41,12 @@ partial void ProcessDeleteLlmResponse( /// Delete an LLM configuration. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task DeleteLlmAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -58,22 +61,43 @@ partial void ProcessDeleteLlmResponse( securityRequirements: s_DeleteLlmSecurityRequirements, operationName: "DeleteLlmAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/llms/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Delete, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/llms/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Delete, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -83,227 +107,386 @@ partial void ProcessDeleteLlmResponse( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareDeleteLlmRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareDeleteLlmRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessDeleteLlmResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteLlm", + methodName: "DeleteLlmAsync", + pathTemplate: "$\"/v1/llms/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteLlm", + methodName: "DeleteLlmAsync", + pathTemplate: "$\"/v1/llms/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - throw new global::Anam.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteLlm", + methodName: "DeleteLlmAsync", + pathTemplate: "$\"/v1/llms/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessDeleteLlmResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteLlm", + methodName: "DeleteLlmAsync", + pathTemplate: "$\"/v1/llms/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteLlm", + methodName: "DeleteLlmAsync", + pathTemplate: "$\"/v1/llms/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Anam/Generated/Anam.LLMsClient.GetLlm.g.cs b/src/libs/Anam/Generated/Anam.LLMsClient.GetLlm.g.cs index 9a017a4..81fb47c 100644 --- a/src/libs/Anam/Generated/Anam.LLMsClient.GetLlm.g.cs +++ b/src/libs/Anam/Generated/Anam.LLMsClient.GetLlm.g.cs @@ -14,6 +14,7 @@ public partial class LLMsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,10 +46,12 @@ partial void ProcessGetLlmResponseContent( /// Get a specific LLM by ID. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GetLlmAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -63,22 +66,43 @@ partial void ProcessGetLlmResponseContent( securityRequirements: s_GetLlmSecurityRequirements, operationName: "GetLlmAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/llms/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/llms/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -88,211 +112,370 @@ partial void ProcessGetLlmResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGetLlmRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGetLlmRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGetLlmResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetLlm", + methodName: "GetLlmAsync", + pathTemplate: "$\"/v1/llms/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetLlm", + methodName: "GetLlmAsync", + pathTemplate: "$\"/v1/llms/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetLlm", + methodName: "GetLlmAsync", + pathTemplate: "$\"/v1/llms/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessGetLlmResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetLlm", + methodName: "GetLlmAsync", + pathTemplate: "$\"/v1/llms/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetLlm", + methodName: "GetLlmAsync", + pathTemplate: "$\"/v1/llms/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessGetLlmResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - try - { - __response.EnsureSuccessStatusCode(); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - global::Anam.Llm.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGetLlmResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); - return - await global::Anam.Llm.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.Llm.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.Llm.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.LLMsClient.ListLlms.g.cs b/src/libs/Anam/Generated/Anam.LLMsClient.ListLlms.g.cs index 9cbd4ce..a899832 100644 --- a/src/libs/Anam/Generated/Anam.LLMsClient.ListLlms.g.cs +++ b/src/libs/Anam/Generated/Anam.LLMsClient.ListLlms.g.cs @@ -14,6 +14,7 @@ public partial class LLMsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -54,6 +55,7 @@ partial void ProcessListLlmsResponseContent( /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ListLlmsAsync( @@ -61,6 +63,7 @@ partial void ProcessListLlmsResponseContent( int? perPage = default, string? search = default, bool? includeDefaults = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -78,28 +81,49 @@ partial void ProcessListLlmsResponseContent( securityRequirements: s_ListLlmsSecurityRequirements, operationName: "ListLlmsAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: "/v1/llms", - baseUri: HttpClient.BaseAddress); - __pathBuilder - .AddOptionalParameter("page", page?.ToString()) - .AddOptionalParameter("perPage", perPage?.ToString()) - .AddOptionalParameter("search", search) - .AddOptionalParameter("includeDefaults", includeDefaults?.ToString().ToLowerInvariant()) - ; - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: "/v1/llms", + baseUri: HttpClient.BaseAddress); + __pathBuilder + .AddOptionalParameter("page", page?.ToString()) + .AddOptionalParameter("perPage", perPage?.ToString()) + .AddOptionalParameter("search", search) + .AddOptionalParameter("includeDefaults", includeDefaults?.ToString().ToLowerInvariant()) + ; + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -109,181 +133,340 @@ partial void ProcessListLlmsResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareListLlmsRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - page: page, - perPage: perPage, - search: search, - includeDefaults: includeDefaults); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareListLlmsRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + page: page, + perPage: perPage, + search: search, + includeDefaults: includeDefaults); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessListLlmsResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListLlms", + methodName: "ListLlmsAsync", + pathTemplate: "\"/v1/llms\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListLlms", + methodName: "ListLlmsAsync", + pathTemplate: "\"/v1/llms\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try - { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListLlms", + methodName: "ListLlmsAsync", + pathTemplate: "\"/v1/llms\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_500 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessListLlmsResponseContent( + response: __response); + ProcessListLlmsResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - __response.EnsureSuccessStatusCode(); - - return - global::Anam.ListLlmsResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListLlms", + methodName: "ListLlmsAsync", + pathTemplate: "\"/v1/llms\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListLlms", + methodName: "ListLlmsAsync", + pathTemplate: "\"/v1/llms\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - return - await global::Anam.ListLlmsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessListLlmsResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.ListLlmsResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.ListLlmsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.LLMsClient.UpdateLlm.g.cs b/src/libs/Anam/Generated/Anam.LLMsClient.UpdateLlm.g.cs index e01dd33..1784228 100644 --- a/src/libs/Anam/Generated/Anam.LLMsClient.UpdateLlm.g.cs +++ b/src/libs/Anam/Generated/Anam.LLMsClient.UpdateLlm.g.cs @@ -14,6 +14,7 @@ public partial class LLMsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -48,12 +49,14 @@ partial void ProcessUpdateLlmResponseContent( /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UpdateLlmAsync( string id, global::Anam.UpdateLlmRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -71,22 +74,43 @@ partial void ProcessUpdateLlmResponseContent( securityRequirements: s_UpdateLlmSecurityRequirements, operationName: "UpdateLlmAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/llms/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Put, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/llms/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Put, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -96,284 +120,443 @@ partial void ProcessUpdateLlmResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareUpdateLlmRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id, - request: request); + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessUpdateLlmResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareUpdateLlmRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id, + request: request); - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 403) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateLlm", + methodName: "UpdateLlmAsync", + pathTemplate: "$\"/v1/llms/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateLlm", + methodName: "UpdateLlmAsync", + pathTemplate: "$\"/v1/llms/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateLlm", + methodName: "UpdateLlmAsync", + pathTemplate: "$\"/v1/llms/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessUpdateLlmResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateLlm", + methodName: "UpdateLlmAsync", + pathTemplate: "$\"/v1/llms/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateLlm", + methodName: "UpdateLlmAsync", + pathTemplate: "$\"/v1/llms/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessUpdateLlmResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - return - global::Anam.Llm.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - await global::Anam.Llm.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessUpdateLlmResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.Llm.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.Llm.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Update LLM
@@ -389,6 +572,7 @@ partial void ProcessUpdateLlmResponseContent( /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UpdateLlmAsync( @@ -402,6 +586,7 @@ partial void ProcessUpdateLlmResponseContent( object? metadata = default, global::Anam.UpdateLlmRequestReasoningEffort? reasoningEffort = default, global::Anam.UpdateLlmRequestReasoningFormat? reasoningFormat = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.UpdateLlmRequest @@ -420,6 +605,7 @@ partial void ProcessUpdateLlmResponseContent( return await UpdateLlmAsync( id: id, request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.LLMsClient.g.cs b/src/libs/Anam/Generated/Anam.LLMsClient.g.cs index a9a0920..277ac06 100644 --- a/src/libs/Anam/Generated/Anam.LLMsClient.g.cs +++ b/src/libs/Anam/Generated/Anam.LLMsClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class LLMsClient : global::Anam.ILLMsClient, global::Syste #if DEBUG = true; #endif + + /// + public global::Anam.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public LLMsClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the LLMsClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public LLMsClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Anam.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Anam.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Anam/Generated/Anam.OptionsSupport.g.cs b/src/libs/Anam/Generated/Anam.OptionsSupport.g.cs new file mode 100644 index 0000000..a794a1e --- /dev/null +++ b/src/libs/Anam/Generated/Anam.OptionsSupport.g.cs @@ -0,0 +1,460 @@ + +#nullable enable + +namespace Anam +{ + /// + /// Global defaults applied to generated SDK requests. + /// + public sealed class AutoSDKClientOptions + { + /// + /// Additional headers applied to every request after generated headers are set. + /// Entries with the same key overwrite earlier header values. + /// + public global::System.Collections.Generic.Dictionary Headers { get; } = + new global::System.Collections.Generic.Dictionary(global::System.StringComparer.OrdinalIgnoreCase); + + /// + /// Additional query parameters appended to every request. + /// Request-level entries with the same key are appended after client defaults. + /// + public global::System.Collections.Generic.Dictionary QueryParameters { get; } = + new global::System.Collections.Generic.Dictionary(global::System.StringComparer.Ordinal); + + /// + /// Optional timeout applied to the full request execution. + /// + public global::System.TimeSpan? Timeout { get; set; } + + /// + /// Default retry behavior for generated HTTP requests. + /// + public global::Anam.AutoSDKRetryOptions Retry { get; set; } = new global::Anam.AutoSDKRetryOptions(); + + /// + /// Overrides the client-wide response buffering mode when set. + /// + public bool? ReadResponseAsString { get; set; } + + /// + /// Reusable hooks invoked for every generated SDK request. + /// + public global::System.Collections.Generic.List Hooks { get; } = + new global::System.Collections.Generic.List(); + + /// + /// Registers a hook for all requests issued by this client. + /// + /// + /// The current options instance. + public global::Anam.AutoSDKClientOptions AddHook( + global::Anam.IAutoSDKHook hook) + { + Hooks.Add(hook ?? throw new global::System.ArgumentNullException(nameof(hook))); + return this; + } + } + + /// + /// Per-request overrides applied on top of . + /// + public sealed class AutoSDKRequestOptions + { + /// + /// Additional headers applied after generated and client-level headers. + /// + public global::System.Collections.Generic.Dictionary Headers { get; } = + new global::System.Collections.Generic.Dictionary(global::System.StringComparer.OrdinalIgnoreCase); + + /// + /// Additional query parameters appended after generated and client-level query parameters. + /// + public global::System.Collections.Generic.Dictionary QueryParameters { get; } = + new global::System.Collections.Generic.Dictionary(global::System.StringComparer.Ordinal); + + /// + /// Optional timeout override for this request. + /// + public global::System.TimeSpan? Timeout { get; set; } + + /// + /// Optional retry override for this request. + /// + public global::Anam.AutoSDKRetryOptions? Retry { get; set; } + + /// + /// Overrides response buffering for this request when set. + /// + public bool? ReadResponseAsString { get; set; } + } + + /// + /// Retry settings for generated HTTP requests. + /// + public sealed class AutoSDKRetryOptions + { + /// + /// Total number of attempts, including the initial request. + /// Values less than 1 are normalized to 1. + /// + public int MaxAttempts { get; set; } = 1; + + /// + /// Optional fixed delay between retry attempts. + /// + public global::System.TimeSpan? Delay { get; set; } + } + + /// + /// Runtime hook interface for generated SDK lifecycle events. + /// + public interface IAutoSDKHook + { + /// + /// Runs before a request is sent. + /// + /// + global::System.Threading.Tasks.Task OnBeforeRequestAsync( + global::Anam.AutoSDKHookContext context); + + /// + /// Runs after a successful HTTP response is received. + /// + /// + global::System.Threading.Tasks.Task OnAfterSuccessAsync( + global::Anam.AutoSDKHookContext context); + + /// + /// Runs after an error response or transport failure is observed. + /// + /// + global::System.Threading.Tasks.Task OnAfterErrorAsync( + global::Anam.AutoSDKHookContext context); + } + + /// + /// Convenience base type for request hooks with no-op defaults. + /// + public abstract class AutoSDKHook : global::Anam.IAutoSDKHook + { + /// + public virtual global::System.Threading.Tasks.Task OnBeforeRequestAsync( + global::Anam.AutoSDKHookContext context) + { + return global::System.Threading.Tasks.Task.CompletedTask; + } + + /// + public virtual global::System.Threading.Tasks.Task OnAfterSuccessAsync( + global::Anam.AutoSDKHookContext context) + { + return global::System.Threading.Tasks.Task.CompletedTask; + } + + /// + public virtual global::System.Threading.Tasks.Task OnAfterErrorAsync( + global::Anam.AutoSDKHookContext context) + { + return global::System.Threading.Tasks.Task.CompletedTask; + } + } + + /// + /// Runtime metadata passed to generated SDK hooks. + /// + public sealed class AutoSDKHookContext + { + /// + /// The source OpenAPI operation id or generated fallback id. + /// + public string OperationId { get; set; } = string.Empty; + + /// + /// The generated C# method name. + /// + public string MethodName { get; set; } = string.Empty; + + /// + /// The OpenAPI path template for the operation. + /// + public string PathTemplate { get; set; } = string.Empty; + + /// + /// The HTTP method used for the request. + /// + public string HttpMethod { get; set; } = string.Empty; + + /// + /// The client's resolved base URI. + /// + public global::System.Uri? BaseUri { get; set; } + + /// + /// The outgoing HTTP request for the current attempt. + /// + public global::System.Net.Http.HttpRequestMessage Request { get; set; } = null!; + + /// + /// The HTTP response when one was received. + /// + public global::System.Net.Http.HttpResponseMessage? Response { get; set; } + + /// + /// The transport or processing exception when one was observed. + /// + public global::System.Exception? Exception { get; set; } + + /// + /// The client-wide runtime options. + /// + public global::Anam.AutoSDKClientOptions ClientOptions { get; set; } = null!; + + /// + /// The per-request runtime options. + /// + public global::Anam.AutoSDKRequestOptions? RequestOptions { get; set; } + + /// + /// The current attempt number, starting at 1. + /// + public int Attempt { get; set; } + + /// + /// The total number of attempts allowed for this request. + /// + public int MaxAttempts { get; set; } + + /// + /// Indicates whether the generated client will retry after this hook invocation. + /// + public bool WillRetry { get; set; } + + /// + /// The effective cancellation token for the current request attempt. + /// + public global::System.Threading.CancellationToken CancellationToken { get; set; } + } + + internal static class AutoSDKRequestOptionsSupport + { + internal static global::Anam.AutoSDKHookContext CreateHookContext( + string operationId, + string methodName, + string pathTemplate, + string httpMethod, + global::System.Uri? baseUri, + global::System.Net.Http.HttpRequestMessage request, + global::System.Net.Http.HttpResponseMessage? response, + global::System.Exception? exception, + global::Anam.AutoSDKClientOptions clientOptions, + global::Anam.AutoSDKRequestOptions? requestOptions, + int attempt, + int maxAttempts, + bool willRetry, + global::System.Threading.CancellationToken cancellationToken) + { + return new global::Anam.AutoSDKHookContext + { + OperationId = operationId ?? string.Empty, + MethodName = methodName ?? string.Empty, + PathTemplate = pathTemplate ?? string.Empty, + HttpMethod = httpMethod ?? string.Empty, + BaseUri = baseUri, + Request = request, + Response = response, + Exception = exception, + ClientOptions = clientOptions, + RequestOptions = requestOptions, + Attempt = attempt, + MaxAttempts = maxAttempts, + WillRetry = willRetry, + CancellationToken = cancellationToken, + }; + } + + internal static global::System.Threading.Tasks.Task OnBeforeRequestAsync( + global::Anam.AutoSDKClientOptions clientOptions, + global::Anam.AutoSDKHookContext context) + { + return InvokeHooksAsync(clientOptions, static (hook, hookContext) => hook.OnBeforeRequestAsync(hookContext), context); + } + + internal static global::System.Threading.Tasks.Task OnAfterSuccessAsync( + global::Anam.AutoSDKClientOptions clientOptions, + global::Anam.AutoSDKHookContext context) + { + return InvokeHooksAsync(clientOptions, static (hook, hookContext) => hook.OnAfterSuccessAsync(hookContext), context); + } + + internal static global::System.Threading.Tasks.Task OnAfterErrorAsync( + global::Anam.AutoSDKClientOptions clientOptions, + global::Anam.AutoSDKHookContext context) + { + return InvokeHooksAsync(clientOptions, static (hook, hookContext) => hook.OnAfterErrorAsync(hookContext), context); + } + + internal static bool GetReadResponseAsString( + global::Anam.AutoSDKClientOptions clientOptions, + global::Anam.AutoSDKRequestOptions? requestOptions, + bool fallbackValue) + { + return requestOptions?.ReadResponseAsString ?? + clientOptions.ReadResponseAsString ?? + fallbackValue; + } + + internal static global::System.Threading.CancellationTokenSource? CreateTimeoutCancellationTokenSource( + global::Anam.AutoSDKClientOptions clientOptions, + global::Anam.AutoSDKRequestOptions? requestOptions, + global::System.Threading.CancellationToken cancellationToken) + { + var timeout = requestOptions?.Timeout ?? clientOptions.Timeout; + if (!timeout.HasValue || timeout.Value <= global::System.TimeSpan.Zero) + { + return null; + } + + var cancellationTokenSource = global::System.Threading.CancellationTokenSource.CreateLinkedTokenSource(cancellationToken); + cancellationTokenSource.CancelAfter(timeout.Value); + return cancellationTokenSource; + } + + internal static int GetMaxAttempts( + global::Anam.AutoSDKClientOptions clientOptions, + global::Anam.AutoSDKRequestOptions? requestOptions, + bool supportsRetry) + { + if (!supportsRetry) + { + return 1; + } + + var maxAttempts = requestOptions?.Retry?.MaxAttempts ?? + clientOptions.Retry?.MaxAttempts ?? + 1; + return maxAttempts < 1 ? 1 : maxAttempts; + } + + internal static async global::System.Threading.Tasks.Task DelayBeforeRetryAsync( + global::Anam.AutoSDKClientOptions clientOptions, + global::Anam.AutoSDKRequestOptions? requestOptions, + global::System.Threading.CancellationToken cancellationToken) + { + var delay = requestOptions?.Retry?.Delay ?? + clientOptions.Retry?.Delay; + if (!delay.HasValue || delay.Value <= global::System.TimeSpan.Zero) + { + return; + } + + await global::System.Threading.Tasks.Task.Delay(delay.Value, cancellationToken).ConfigureAwait(false); + } + + internal static bool ShouldRetryStatusCode( + global::System.Net.HttpStatusCode statusCode) + { + return (int)statusCode switch + { + 408 => true, + 429 => true, + 500 => true, + 502 => true, + 503 => true, + 504 => true, + _ => false, + }; + } + + internal static string AppendQueryParameters( + string path, + global::System.Collections.Generic.Dictionary clientParameters, + global::System.Collections.Generic.Dictionary? requestParameters) + { + var hasClientParameters = clientParameters != null && clientParameters.Count > 0; + var hasRequestParameters = requestParameters != null && requestParameters.Count > 0; + if (!hasClientParameters && !hasRequestParameters) + { + return path; + } + + var builder = new global::System.Text.StringBuilder(path ?? string.Empty); + var hasQuery = builder.ToString().Contains("?", global::System.StringComparison.Ordinal); + AppendParameters(builder, clientParameters, ref hasQuery); + AppendParameters(builder, requestParameters, ref hasQuery); + return builder.ToString(); + } + + internal static void ApplyHeaders( + global::System.Net.Http.HttpRequestMessage request, + global::System.Collections.Generic.Dictionary clientHeaders, + global::System.Collections.Generic.Dictionary? requestHeaders) + { + ApplyHeadersCore(request, clientHeaders); + ApplyHeadersCore(request, requestHeaders); + } + + private static void AppendParameters( + global::System.Text.StringBuilder builder, + global::System.Collections.Generic.Dictionary? parameters, + ref bool hasQuery) + { + if (parameters == null || parameters.Count == 0) + { + return; + } + + foreach (var parameter in parameters) + { + builder.Append(hasQuery ? '&' : '?'); + builder.Append(global::System.Uri.EscapeDataString(parameter.Key)); + builder.Append('='); + builder.Append(global::System.Uri.EscapeDataString(parameter.Value ?? string.Empty)); + hasQuery = true; + } + } + + private static void ApplyHeadersCore( + global::System.Net.Http.HttpRequestMessage request, + global::System.Collections.Generic.Dictionary? headers) + { + if (headers == null || headers.Count == 0) + { + return; + } + + foreach (var header in headers) + { + request.Headers.Remove(header.Key); + request.Content?.Headers.Remove(header.Key); + + if (!request.Headers.TryAddWithoutValidation(header.Key, header.Value ?? string.Empty) && + request.Content != null) + { + request.Content.Headers.TryAddWithoutValidation(header.Key, header.Value ?? string.Empty); + } + } + } + + private static async global::System.Threading.Tasks.Task InvokeHooksAsync( + global::Anam.AutoSDKClientOptions clientOptions, + global::System.Func callback, + global::Anam.AutoSDKHookContext context) + { + if (clientOptions.Hooks == null || clientOptions.Hooks.Count == 0) + { + return; + } + + foreach (var hook in clientOptions.Hooks) + { + if (hook == null) + { + continue; + } + + await callback(hook, context).ConfigureAwait(false); + } + } + } +} \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.PathBuilder.g.cs b/src/libs/Anam/Generated/Anam.PathBuilder.g.cs index 198b234..1692c93 100644 --- a/src/libs/Anam/Generated/Anam.PathBuilder.g.cs +++ b/src/libs/Anam/Generated/Anam.PathBuilder.g.cs @@ -275,6 +275,11 @@ public class EndPointAuthorization ///
public string Type { get; set; } = string.Empty; + /// + /// + /// + public string SchemeId { get; set; } = string.Empty; + /// /// /// diff --git a/src/libs/Anam/Generated/Anam.PersonasClient.CreatePersona.g.cs b/src/libs/Anam/Generated/Anam.PersonasClient.CreatePersona.g.cs index e615b27..7ebc622 100644 --- a/src/libs/Anam/Generated/Anam.PersonasClient.CreatePersona.g.cs +++ b/src/libs/Anam/Generated/Anam.PersonasClient.CreatePersona.g.cs @@ -14,6 +14,7 @@ public partial class PersonasClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,11 +46,13 @@ partial void ProcessCreatePersonaResponseContent( /// Create a new persona with avatar, voice, LLM, and system prompt configuration. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task CreatePersonaAsync( global::Anam.PersonaConfig request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -66,22 +69,43 @@ partial void ProcessCreatePersonaResponseContent( securityRequirements: s_CreatePersonaSecurityRequirements, operationName: "CreatePersonaAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: "/v1/personas", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: "/v1/personas", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -91,217 +115,376 @@ partial void ProcessCreatePersonaResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareCreatePersonaRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareCreatePersonaRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - ProcessResponse( - client: HttpClient, - response: __response); - ProcessCreatePersonaResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + return __httpRequest; + } + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreatePersona", + methodName: "CreatePersonaAsync", + pathTemplate: "\"/v1/personas\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreatePersona", + methodName: "CreatePersonaAsync", + pathTemplate: "\"/v1/personas\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreatePersona", + methodName: "CreatePersonaAsync", + pathTemplate: "\"/v1/personas\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_401 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessCreatePersonaResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreatePersona", + methodName: "CreatePersonaAsync", + pathTemplate: "\"/v1/personas\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreatePersona", + methodName: "CreatePersonaAsync", + pathTemplate: "\"/v1/personas\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessCreatePersonaResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - try - { - __response.EnsureSuccessStatusCode(); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - global::Anam.PersonaConfig.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessCreatePersonaResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); - return - await global::Anam.PersonaConfig.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.PersonaConfig.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.PersonaConfig.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Create persona
@@ -348,6 +531,7 @@ partial void ProcessCreatePersonaResponseContent( /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task CreatePersonaAsync( @@ -366,6 +550,7 @@ partial void ProcessCreatePersonaResponseContent( global::System.Collections.Generic.IList? toolIds = default, global::System.DateTime? createdAt = default, global::System.DateTime? updatedAt = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.PersonaConfig @@ -389,6 +574,7 @@ partial void ProcessCreatePersonaResponseContent( return await CreatePersonaAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.PersonasClient.DeletePersona.g.cs b/src/libs/Anam/Generated/Anam.PersonasClient.DeletePersona.g.cs index e906880..63948d8 100644 --- a/src/libs/Anam/Generated/Anam.PersonasClient.DeletePersona.g.cs +++ b/src/libs/Anam/Generated/Anam.PersonasClient.DeletePersona.g.cs @@ -14,6 +14,7 @@ public partial class PersonasClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -40,10 +41,12 @@ partial void ProcessDeletePersonaResponse( /// Delete a persona by ID. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task DeletePersonaAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -58,22 +61,43 @@ partial void ProcessDeletePersonaResponse( securityRequirements: s_DeletePersonaSecurityRequirements, operationName: "DeletePersonaAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/personas/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Delete, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/personas/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Delete, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -83,194 +107,353 @@ partial void ProcessDeletePersonaResponse( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareDeletePersonaRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareDeletePersonaRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessDeletePersonaResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeletePersona", + methodName: "DeletePersonaAsync", + pathTemplate: "$\"/v1/personas/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeletePersona", + methodName: "DeletePersonaAsync", + pathTemplate: "$\"/v1/personas/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeletePersona", + methodName: "DeletePersonaAsync", + pathTemplate: "$\"/v1/personas/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessDeletePersonaResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeletePersona", + methodName: "DeletePersonaAsync", + pathTemplate: "$\"/v1/personas/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeletePersona", + methodName: "DeletePersonaAsync", + pathTemplate: "$\"/v1/personas/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - try - { - __response.EnsureSuccessStatusCode(); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Anam/Generated/Anam.PersonasClient.GetPersona.g.cs b/src/libs/Anam/Generated/Anam.PersonasClient.GetPersona.g.cs index c616622..f601ccd 100644 --- a/src/libs/Anam/Generated/Anam.PersonasClient.GetPersona.g.cs +++ b/src/libs/Anam/Generated/Anam.PersonasClient.GetPersona.g.cs @@ -14,6 +14,7 @@ public partial class PersonasClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,10 +46,12 @@ partial void ProcessGetPersonaResponseContent( /// Returns a persona by ID. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GetPersonaAsync( string id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -63,22 +66,43 @@ partial void ProcessGetPersonaResponseContent( securityRequirements: s_GetPersonaSecurityRequirements, operationName: "GetPersonaAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/personas/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/personas/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -88,211 +112,370 @@ partial void ProcessGetPersonaResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGetPersonaRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGetPersonaRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGetPersonaResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetPersona", + methodName: "GetPersonaAsync", + pathTemplate: "$\"/v1/personas/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetPersona", + methodName: "GetPersonaAsync", + pathTemplate: "$\"/v1/personas/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetPersona", + methodName: "GetPersonaAsync", + pathTemplate: "$\"/v1/personas/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessGetPersonaResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetPersona", + methodName: "GetPersonaAsync", + pathTemplate: "$\"/v1/personas/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetPersona", + methodName: "GetPersonaAsync", + pathTemplate: "$\"/v1/personas/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessGetPersonaResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - try - { - __response.EnsureSuccessStatusCode(); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - global::Anam.PersonaConfig.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGetPersonaResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); - return - await global::Anam.PersonaConfig.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.PersonaConfig.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.PersonaConfig.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.PersonasClient.ListPersonas.g.cs b/src/libs/Anam/Generated/Anam.PersonasClient.ListPersonas.g.cs index e9c028c..1fa87c6 100644 --- a/src/libs/Anam/Generated/Anam.PersonasClient.ListPersonas.g.cs +++ b/src/libs/Anam/Generated/Anam.PersonasClient.ListPersonas.g.cs @@ -14,6 +14,7 @@ public partial class PersonasClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -55,12 +56,14 @@ partial void ProcessListPersonasResponseContent( /// Default Value: 10 /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ListPersonasAsync( int? page = default, int? perPage = default, string? search = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -77,27 +80,48 @@ partial void ProcessListPersonasResponseContent( securityRequirements: s_ListPersonasSecurityRequirements, operationName: "ListPersonasAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: "/v1/personas", - baseUri: HttpClient.BaseAddress); - __pathBuilder - .AddOptionalParameter("page", page?.ToString()) - .AddOptionalParameter("perPage", perPage?.ToString()) - .AddOptionalParameter("search", search) - ; - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: "/v1/personas", + baseUri: HttpClient.BaseAddress); + __pathBuilder + .AddOptionalParameter("page", page?.ToString()) + .AddOptionalParameter("perPage", perPage?.ToString()) + .AddOptionalParameter("search", search) + ; + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -107,180 +131,339 @@ partial void ProcessListPersonasResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareListPersonasRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - page: page, - perPage: perPage, - search: search); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareListPersonasRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + page: page, + perPage: perPage, + search: search); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessListPersonasResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListPersonas", + methodName: "ListPersonasAsync", + pathTemplate: "\"/v1/personas\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListPersonas", + methodName: "ListPersonasAsync", + pathTemplate: "\"/v1/personas\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try - { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListPersonas", + methodName: "ListPersonasAsync", + pathTemplate: "\"/v1/personas\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_500 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessListPersonasResponseContent( + response: __response); + ProcessListPersonasResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - __response.EnsureSuccessStatusCode(); - - return - global::Anam.ListPersonasResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListPersonas", + methodName: "ListPersonasAsync", + pathTemplate: "\"/v1/personas\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListPersonas", + methodName: "ListPersonasAsync", + pathTemplate: "\"/v1/personas\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - return - await global::Anam.ListPersonasResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessListPersonasResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.ListPersonasResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.ListPersonasResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.PersonasClient.UpdatePersona.g.cs b/src/libs/Anam/Generated/Anam.PersonasClient.UpdatePersona.g.cs index 2438398..a08b30b 100644 --- a/src/libs/Anam/Generated/Anam.PersonasClient.UpdatePersona.g.cs +++ b/src/libs/Anam/Generated/Anam.PersonasClient.UpdatePersona.g.cs @@ -14,6 +14,7 @@ public partial class PersonasClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -48,12 +49,14 @@ partial void ProcessUpdatePersonaResponseContent( /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UpdatePersonaAsync( string id, global::Anam.PersonaConfig request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -71,22 +74,43 @@ partial void ProcessUpdatePersonaResponseContent( securityRequirements: s_UpdatePersonaSecurityRequirements, operationName: "UpdatePersonaAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/personas/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Put, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/personas/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Put, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -96,251 +120,410 @@ partial void ProcessUpdatePersonaResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareUpdatePersonaRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - ProcessResponse( - client: HttpClient, - response: __response); - ProcessUpdatePersonaResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareUpdatePersonaRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id, + request: request); - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // - if ((int)__response.StatusCode == 401) + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdatePersona", + methodName: "UpdatePersonaAsync", + pathTemplate: "$\"/v1/personas/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdatePersona", + methodName: "UpdatePersonaAsync", + pathTemplate: "$\"/v1/personas/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdatePersona", + methodName: "UpdatePersonaAsync", + pathTemplate: "$\"/v1/personas/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessUpdatePersonaResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdatePersona", + methodName: "UpdatePersonaAsync", + pathTemplate: "$\"/v1/personas/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdatePersona", + methodName: "UpdatePersonaAsync", + pathTemplate: "$\"/v1/personas/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessUpdatePersonaResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - global::Anam.PersonaConfig.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - await global::Anam.PersonaConfig.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessUpdatePersonaResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.PersonaConfig.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.PersonaConfig.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Update persona
@@ -388,6 +571,7 @@ partial void ProcessUpdatePersonaResponseContent( /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UpdatePersonaAsync( @@ -407,6 +591,7 @@ partial void ProcessUpdatePersonaResponseContent( global::System.Collections.Generic.IList? toolIds = default, global::System.DateTime? createdAt = default, global::System.DateTime? updatedAt = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.PersonaConfig @@ -431,6 +616,7 @@ partial void ProcessUpdatePersonaResponseContent( return await UpdatePersonaAsync( id: id, request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.PersonasClient.g.cs b/src/libs/Anam/Generated/Anam.PersonasClient.g.cs index ae17b31..1b12dad 100644 --- a/src/libs/Anam/Generated/Anam.PersonasClient.g.cs +++ b/src/libs/Anam/Generated/Anam.PersonasClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class PersonasClient : global::Anam.IPersonasClient, globa #if DEBUG = true; #endif + + /// + public global::Anam.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public PersonasClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the PersonasClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public PersonasClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Anam.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Anam.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Anam/Generated/Anam.Security.g.cs b/src/libs/Anam/Generated/Anam.Security.g.cs index 45ae136..84cfab0 100644 --- a/src/libs/Anam/Generated/Anam.Security.g.cs +++ b/src/libs/Anam/Generated/Anam.Security.g.cs @@ -6,6 +6,8 @@ internal sealed class EndPointAuthorizationRequirement { internal string Type { get; set; } = string.Empty; + internal string SchemeId { get; set; } = string.Empty; + internal string Location { get; set; } = string.Empty; internal string Name { get; set; } = string.Empty; @@ -97,7 +99,18 @@ private static bool Matches( return requiredAuthorization.Type switch { - "OAuth2" => true, + "OAuth2" => string.Equals( + availableAuthorization.SchemeId, + requiredAuthorization.SchemeId, + global::System.StringComparison.Ordinal), + "OpenIdConnect" => string.Equals( + availableAuthorization.SchemeId, + requiredAuthorization.SchemeId, + global::System.StringComparison.Ordinal), + "MutualTLS" => string.Equals( + availableAuthorization.SchemeId, + requiredAuthorization.SchemeId, + global::System.StringComparison.Ordinal), "Http" => string.Equals( availableAuthorization.Name, requiredAuthorization.Name, diff --git a/src/libs/Anam/Generated/Anam.SessionsClient.GetSession.g.cs b/src/libs/Anam/Generated/Anam.SessionsClient.GetSession.g.cs index 311cbd8..2c40d3f 100644 --- a/src/libs/Anam/Generated/Anam.SessionsClient.GetSession.g.cs +++ b/src/libs/Anam/Generated/Anam.SessionsClient.GetSession.g.cs @@ -14,6 +14,7 @@ public partial class SessionsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,10 +46,12 @@ partial void ProcessGetSessionResponseContent( /// Returns a session by ID. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GetSessionAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -63,22 +66,43 @@ partial void ProcessGetSessionResponseContent( securityRequirements: s_GetSessionSecurityRequirements, operationName: "GetSessionAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/sessions/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/sessions/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -88,244 +112,403 @@ partial void ProcessGetSessionResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGetSessionRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGetSessionRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGetSessionResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetSession", + methodName: "GetSessionAsync", + pathTemplate: "$\"/v1/sessions/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetSession", + methodName: "GetSessionAsync", + pathTemplate: "$\"/v1/sessions/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetSession", + methodName: "GetSessionAsync", + pathTemplate: "$\"/v1/sessions/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessGetSessionResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetSession", + methodName: "GetSessionAsync", + pathTemplate: "$\"/v1/sessions/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetSession", + methodName: "GetSessionAsync", + pathTemplate: "$\"/v1/sessions/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessGetSessionResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - global::Anam.Session.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - await global::Anam.Session.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGetSessionResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.Session.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.Session.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.SessionsClient.GetSessionRecording.g.cs b/src/libs/Anam/Generated/Anam.SessionsClient.GetSessionRecording.g.cs index cc7280d..bd8972d 100644 --- a/src/libs/Anam/Generated/Anam.SessionsClient.GetSessionRecording.g.cs +++ b/src/libs/Anam/Generated/Anam.SessionsClient.GetSessionRecording.g.cs @@ -14,6 +14,7 @@ public partial class SessionsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,10 +46,12 @@ partial void ProcessGetSessionRecordingResponseContent( /// Returns a presigned URL to download the session recording. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GetSessionRecordingAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -63,22 +66,43 @@ partial void ProcessGetSessionRecordingResponseContent( securityRequirements: s_GetSessionRecordingSecurityRequirements, operationName: "GetSessionRecordingAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/sessions/{id}/recording", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/sessions/{id}/recording", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -88,244 +112,403 @@ partial void ProcessGetSessionRecordingResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGetSessionRecordingRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGetSessionRecordingRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGetSessionRecordingResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetSessionRecording", + methodName: "GetSessionRecordingAsync", + pathTemplate: "$\"/v1/sessions/{id}/recording\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetSessionRecording", + methodName: "GetSessionRecordingAsync", + pathTemplate: "$\"/v1/sessions/{id}/recording\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetSessionRecording", + methodName: "GetSessionRecordingAsync", + pathTemplate: "$\"/v1/sessions/{id}/recording\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessGetSessionRecordingResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetSessionRecording", + methodName: "GetSessionRecordingAsync", + pathTemplate: "$\"/v1/sessions/{id}/recording\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetSessionRecording", + methodName: "GetSessionRecordingAsync", + pathTemplate: "$\"/v1/sessions/{id}/recording\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessGetSessionRecordingResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - global::Anam.GetSessionRecordingResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - await global::Anam.GetSessionRecordingResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGetSessionRecordingResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.GetSessionRecordingResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.GetSessionRecordingResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.SessionsClient.GetSessionTranscript.g.cs b/src/libs/Anam/Generated/Anam.SessionsClient.GetSessionTranscript.g.cs index 46d1496..b742bee 100644 --- a/src/libs/Anam/Generated/Anam.SessionsClient.GetSessionTranscript.g.cs +++ b/src/libs/Anam/Generated/Anam.SessionsClient.GetSessionTranscript.g.cs @@ -14,6 +14,7 @@ public partial class SessionsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,10 +46,12 @@ partial void ProcessGetSessionTranscriptResponseContent( /// Returns the conversation transcript for a session. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GetSessionTranscriptAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -63,22 +66,43 @@ partial void ProcessGetSessionTranscriptResponseContent( securityRequirements: s_GetSessionTranscriptSecurityRequirements, operationName: "GetSessionTranscriptAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/sessions/{id}/transcript", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/sessions/{id}/transcript", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -88,244 +112,403 @@ partial void ProcessGetSessionTranscriptResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGetSessionTranscriptRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGetSessionTranscriptRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGetSessionTranscriptResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetSessionTranscript", + methodName: "GetSessionTranscriptAsync", + pathTemplate: "$\"/v1/sessions/{id}/transcript\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetSessionTranscript", + methodName: "GetSessionTranscriptAsync", + pathTemplate: "$\"/v1/sessions/{id}/transcript\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetSessionTranscript", + methodName: "GetSessionTranscriptAsync", + pathTemplate: "$\"/v1/sessions/{id}/transcript\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessGetSessionTranscriptResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetSessionTranscript", + methodName: "GetSessionTranscriptAsync", + pathTemplate: "$\"/v1/sessions/{id}/transcript\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetSessionTranscript", + methodName: "GetSessionTranscriptAsync", + pathTemplate: "$\"/v1/sessions/{id}/transcript\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessGetSessionTranscriptResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - global::Anam.SessionTranscript.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - await global::Anam.SessionTranscript.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGetSessionTranscriptResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.SessionTranscript.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.SessionTranscript.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.SessionsClient.ListSessions.g.cs b/src/libs/Anam/Generated/Anam.SessionsClient.ListSessions.g.cs index eb255c0..e3e1ee4 100644 --- a/src/libs/Anam/Generated/Anam.SessionsClient.ListSessions.g.cs +++ b/src/libs/Anam/Generated/Anam.SessionsClient.ListSessions.g.cs @@ -14,6 +14,7 @@ public partial class SessionsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -61,6 +62,7 @@ partial void ProcessListSessionsResponseContent( /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ListSessionsAsync( @@ -69,6 +71,7 @@ partial void ProcessListSessionsResponseContent( string? search = default, global::System.Guid? apiKeyId = default, global::System.Guid? personaId = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -87,29 +90,50 @@ partial void ProcessListSessionsResponseContent( securityRequirements: s_ListSessionsSecurityRequirements, operationName: "ListSessionsAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: "/v1/sessions", - baseUri: HttpClient.BaseAddress); - __pathBuilder - .AddOptionalParameter("page", page?.ToString()) - .AddOptionalParameter("perPage", perPage?.ToString()) - .AddOptionalParameter("search", search) - .AddOptionalParameter("apiKeyId", apiKeyId?.ToString()) - .AddOptionalParameter("personaId", personaId?.ToString()) - ; - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: "/v1/sessions", + baseUri: HttpClient.BaseAddress); + __pathBuilder + .AddOptionalParameter("page", page?.ToString()) + .AddOptionalParameter("perPage", perPage?.ToString()) + .AddOptionalParameter("search", search) + .AddOptionalParameter("apiKeyId", apiKeyId?.ToString()) + .AddOptionalParameter("personaId", personaId?.ToString()) + ; + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -119,215 +143,374 @@ partial void ProcessListSessionsResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareListSessionsRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - page: page, - perPage: perPage, - search: search, - apiKeyId: apiKeyId, - personaId: personaId); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareListSessionsRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + page: page, + perPage: perPage, + search: search, + apiKeyId: apiKeyId, + personaId: personaId); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessListSessionsResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListSessions", + methodName: "ListSessionsAsync", + pathTemplate: "\"/v1/sessions\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListSessions", + methodName: "ListSessionsAsync", + pathTemplate: "\"/v1/sessions\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListSessions", + methodName: "ListSessionsAsync", + pathTemplate: "\"/v1/sessions\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_401 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessListSessionsResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListSessions", + methodName: "ListSessionsAsync", + pathTemplate: "\"/v1/sessions\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListSessions", + methodName: "ListSessionsAsync", + pathTemplate: "\"/v1/sessions\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessListSessionsResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - try - { - __response.EnsureSuccessStatusCode(); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - global::Anam.ListSessionsResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessListSessionsResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); - return - await global::Anam.ListSessionsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.ListSessionsResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.ListSessionsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.SessionsClient.g.cs b/src/libs/Anam/Generated/Anam.SessionsClient.g.cs index fbcacdf..313f0f3 100644 --- a/src/libs/Anam/Generated/Anam.SessionsClient.g.cs +++ b/src/libs/Anam/Generated/Anam.SessionsClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class SessionsClient : global::Anam.ISessionsClient, globa #if DEBUG = true; #endif + + /// + public global::Anam.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public SessionsClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the SessionsClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public SessionsClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Anam.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Anam.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Anam/Generated/Anam.ShareLinksClient.CreateShareLink.g.cs b/src/libs/Anam/Generated/Anam.ShareLinksClient.CreateShareLink.g.cs index 422a656..4cff2d0 100644 --- a/src/libs/Anam/Generated/Anam.ShareLinksClient.CreateShareLink.g.cs +++ b/src/libs/Anam/Generated/Anam.ShareLinksClient.CreateShareLink.g.cs @@ -14,6 +14,7 @@ public partial class ShareLinksClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,11 +46,13 @@ partial void ProcessCreateShareLinkResponseContent( /// Create a new share link. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task CreateShareLinkAsync( global::Anam.CreateShareLinkRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -66,22 +69,43 @@ partial void ProcessCreateShareLinkResponseContent( securityRequirements: s_CreateShareLinkSecurityRequirements, operationName: "CreateShareLinkAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: "/v1/share-links", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: "/v1/share-links", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -91,250 +115,409 @@ partial void ProcessCreateShareLinkResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareCreateShareLinkRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessCreateShareLinkResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareCreateShareLinkRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // - if ((int)__response.StatusCode == 401) + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateShareLink", + methodName: "CreateShareLinkAsync", + pathTemplate: "\"/v1/share-links\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateShareLink", + methodName: "CreateShareLinkAsync", + pathTemplate: "\"/v1/share-links\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateShareLink", + methodName: "CreateShareLinkAsync", + pathTemplate: "\"/v1/share-links\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessCreateShareLinkResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateShareLink", + methodName: "CreateShareLinkAsync", + pathTemplate: "\"/v1/share-links\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateShareLink", + methodName: "CreateShareLinkAsync", + pathTemplate: "\"/v1/share-links\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessCreateShareLinkResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - global::Anam.ShareLink.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - await global::Anam.ShareLink.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessCreateShareLinkResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.ShareLink.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.ShareLink.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Create share link
@@ -347,12 +530,14 @@ partial void ProcessCreateShareLinkResponseContent( /// /// Default Value: 10 /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task CreateShareLinkAsync( global::System.Guid personaId, double? expiresInHours = default, double? usageLimit = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.CreateShareLinkRequest @@ -364,6 +549,7 @@ partial void ProcessCreateShareLinkResponseContent( return await CreateShareLinkAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.ShareLinksClient.DeleteShareLink.g.cs b/src/libs/Anam/Generated/Anam.ShareLinksClient.DeleteShareLink.g.cs index 6c77d17..65007f9 100644 --- a/src/libs/Anam/Generated/Anam.ShareLinksClient.DeleteShareLink.g.cs +++ b/src/libs/Anam/Generated/Anam.ShareLinksClient.DeleteShareLink.g.cs @@ -14,6 +14,7 @@ public partial class ShareLinksClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -40,10 +41,12 @@ partial void ProcessDeleteShareLinkResponse( /// Delete a share link by ID. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task DeleteShareLinkAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -58,22 +61,43 @@ partial void ProcessDeleteShareLinkResponse( securityRequirements: s_DeleteShareLinkSecurityRequirements, operationName: "DeleteShareLinkAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/share-links/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Delete, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/share-links/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Delete, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -83,227 +107,386 @@ partial void ProcessDeleteShareLinkResponse( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareDeleteShareLinkRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareDeleteShareLinkRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessDeleteShareLinkResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteShareLink", + methodName: "DeleteShareLinkAsync", + pathTemplate: "$\"/v1/share-links/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteShareLink", + methodName: "DeleteShareLinkAsync", + pathTemplate: "$\"/v1/share-links/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteShareLink", + methodName: "DeleteShareLinkAsync", + pathTemplate: "$\"/v1/share-links/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessDeleteShareLinkResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteShareLink", + methodName: "DeleteShareLinkAsync", + pathTemplate: "$\"/v1/share-links/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteShareLink", + methodName: "DeleteShareLinkAsync", + pathTemplate: "$\"/v1/share-links/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Anam/Generated/Anam.ShareLinksClient.GetShareLink.g.cs b/src/libs/Anam/Generated/Anam.ShareLinksClient.GetShareLink.g.cs index a7c036e..5ea672d 100644 --- a/src/libs/Anam/Generated/Anam.ShareLinksClient.GetShareLink.g.cs +++ b/src/libs/Anam/Generated/Anam.ShareLinksClient.GetShareLink.g.cs @@ -14,6 +14,7 @@ public partial class ShareLinksClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,10 +46,12 @@ partial void ProcessGetShareLinkResponseContent( /// Returns a share link by ID. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GetShareLinkAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -63,22 +66,43 @@ partial void ProcessGetShareLinkResponseContent( securityRequirements: s_GetShareLinkSecurityRequirements, operationName: "GetShareLinkAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/share-links/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/share-links/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -88,244 +112,403 @@ partial void ProcessGetShareLinkResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGetShareLinkRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGetShareLinkRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGetShareLinkResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetShareLink", + methodName: "GetShareLinkAsync", + pathTemplate: "$\"/v1/share-links/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetShareLink", + methodName: "GetShareLinkAsync", + pathTemplate: "$\"/v1/share-links/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetShareLink", + methodName: "GetShareLinkAsync", + pathTemplate: "$\"/v1/share-links/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessGetShareLinkResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetShareLink", + methodName: "GetShareLinkAsync", + pathTemplate: "$\"/v1/share-links/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetShareLink", + methodName: "GetShareLinkAsync", + pathTemplate: "$\"/v1/share-links/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessGetShareLinkResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - global::Anam.ShareLink.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - await global::Anam.ShareLink.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGetShareLinkResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.ShareLink.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.ShareLink.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.ShareLinksClient.ListShareLinks.g.cs b/src/libs/Anam/Generated/Anam.ShareLinksClient.ListShareLinks.g.cs index e621789..16bbbe5 100644 --- a/src/libs/Anam/Generated/Anam.ShareLinksClient.ListShareLinks.g.cs +++ b/src/libs/Anam/Generated/Anam.ShareLinksClient.ListShareLinks.g.cs @@ -14,6 +14,7 @@ public partial class ShareLinksClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -58,6 +59,7 @@ partial void ProcessListShareLinksResponseContent( /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ListShareLinksAsync( @@ -65,6 +67,7 @@ partial void ProcessListShareLinksResponseContent( int? perPage = default, string? search = default, global::System.Guid? personaId = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -82,28 +85,49 @@ partial void ProcessListShareLinksResponseContent( securityRequirements: s_ListShareLinksSecurityRequirements, operationName: "ListShareLinksAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: "/v1/share-links", - baseUri: HttpClient.BaseAddress); - __pathBuilder - .AddOptionalParameter("page", page?.ToString()) - .AddOptionalParameter("perPage", perPage?.ToString()) - .AddOptionalParameter("search", search) - .AddOptionalParameter("personaId", personaId?.ToString()) - ; - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: "/v1/share-links", + baseUri: HttpClient.BaseAddress); + __pathBuilder + .AddOptionalParameter("page", page?.ToString()) + .AddOptionalParameter("perPage", perPage?.ToString()) + .AddOptionalParameter("search", search) + .AddOptionalParameter("personaId", personaId?.ToString()) + ; + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -113,214 +137,373 @@ partial void ProcessListShareLinksResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareListShareLinksRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - page: page, - perPage: perPage, - search: search, - personaId: personaId); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareListShareLinksRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + page: page, + perPage: perPage, + search: search, + personaId: personaId); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessListShareLinksResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListShareLinks", + methodName: "ListShareLinksAsync", + pathTemplate: "\"/v1/share-links\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListShareLinks", + methodName: "ListShareLinksAsync", + pathTemplate: "\"/v1/share-links\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListShareLinks", + methodName: "ListShareLinksAsync", + pathTemplate: "\"/v1/share-links\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_401 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessListShareLinksResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListShareLinks", + methodName: "ListShareLinksAsync", + pathTemplate: "\"/v1/share-links\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListShareLinks", + methodName: "ListShareLinksAsync", + pathTemplate: "\"/v1/share-links\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessListShareLinksResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - try - { - __response.EnsureSuccessStatusCode(); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - global::Anam.ListShareLinksResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessListShareLinksResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); - return - await global::Anam.ListShareLinksResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.ListShareLinksResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.ListShareLinksResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.ShareLinksClient.UpdateShareLink.g.cs b/src/libs/Anam/Generated/Anam.ShareLinksClient.UpdateShareLink.g.cs index 4305061..c6ae507 100644 --- a/src/libs/Anam/Generated/Anam.ShareLinksClient.UpdateShareLink.g.cs +++ b/src/libs/Anam/Generated/Anam.ShareLinksClient.UpdateShareLink.g.cs @@ -14,6 +14,7 @@ public partial class ShareLinksClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -48,12 +49,14 @@ partial void ProcessUpdateShareLinkResponseContent( /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UpdateShareLinkAsync( global::System.Guid id, global::Anam.UpdateShareLinkRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -71,22 +74,43 @@ partial void ProcessUpdateShareLinkResponseContent( securityRequirements: s_UpdateShareLinkSecurityRequirements, operationName: "UpdateShareLinkAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/share-links/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Put, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/share-links/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Put, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -96,251 +120,410 @@ partial void ProcessUpdateShareLinkResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareUpdateShareLinkRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - ProcessResponse( - client: HttpClient, - response: __response); - ProcessUpdateShareLinkResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareUpdateShareLinkRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id, + request: request); - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // - if ((int)__response.StatusCode == 401) + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateShareLink", + methodName: "UpdateShareLinkAsync", + pathTemplate: "$\"/v1/share-links/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateShareLink", + methodName: "UpdateShareLinkAsync", + pathTemplate: "$\"/v1/share-links/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateShareLink", + methodName: "UpdateShareLinkAsync", + pathTemplate: "$\"/v1/share-links/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessUpdateShareLinkResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateShareLink", + methodName: "UpdateShareLinkAsync", + pathTemplate: "$\"/v1/share-links/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateShareLink", + methodName: "UpdateShareLinkAsync", + pathTemplate: "$\"/v1/share-links/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessUpdateShareLinkResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - global::Anam.ShareLink.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - await global::Anam.ShareLink.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessUpdateShareLinkResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.ShareLink.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.ShareLink.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Update share link
@@ -349,12 +532,14 @@ partial void ProcessUpdateShareLinkResponseContent( /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UpdateShareLinkAsync( global::System.Guid id, double? expiresInHours = default, double? usageLimit = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.UpdateShareLinkRequest @@ -366,6 +551,7 @@ partial void ProcessUpdateShareLinkResponseContent( return await UpdateShareLinkAsync( id: id, request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.ShareLinksClient.g.cs b/src/libs/Anam/Generated/Anam.ShareLinksClient.g.cs index 35fd875..2737b7b 100644 --- a/src/libs/Anam/Generated/Anam.ShareLinksClient.g.cs +++ b/src/libs/Anam/Generated/Anam.ShareLinksClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class ShareLinksClient : global::Anam.IShareLinksClient, g #if DEBUG = true; #endif + + /// + public global::Anam.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public ShareLinksClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the ShareLinksClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public ShareLinksClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Anam.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Anam.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Anam/Generated/Anam.ToolsClient.CreateTool.g.cs b/src/libs/Anam/Generated/Anam.ToolsClient.CreateTool.g.cs index 14e3aed..3dd591c 100644 --- a/src/libs/Anam/Generated/Anam.ToolsClient.CreateTool.g.cs +++ b/src/libs/Anam/Generated/Anam.ToolsClient.CreateTool.g.cs @@ -14,6 +14,7 @@ public partial class ToolsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,11 +46,13 @@ partial void ProcessCreateToolResponseContent( /// Create a new tool for function calling in persona sessions. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task CreateToolAsync( global::Anam.CreateToolRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -66,22 +69,43 @@ partial void ProcessCreateToolResponseContent( securityRequirements: s_CreateToolSecurityRequirements, operationName: "CreateToolAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: "/v1/tools", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: "/v1/tools", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -91,217 +115,376 @@ partial void ProcessCreateToolResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareCreateToolRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareCreateToolRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - ProcessResponse( - client: HttpClient, - response: __response); - ProcessCreateToolResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + return __httpRequest; + } + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateTool", + methodName: "CreateToolAsync", + pathTemplate: "\"/v1/tools\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateTool", + methodName: "CreateToolAsync", + pathTemplate: "\"/v1/tools\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateTool", + methodName: "CreateToolAsync", + pathTemplate: "\"/v1/tools\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_401 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessCreateToolResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateTool", + methodName: "CreateToolAsync", + pathTemplate: "\"/v1/tools\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateTool", + methodName: "CreateToolAsync", + pathTemplate: "\"/v1/tools\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessCreateToolResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - try - { - __response.EnsureSuccessStatusCode(); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - global::Anam.Tool.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessCreateToolResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); - return - await global::Anam.Tool.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.Tool.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.Tool.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Create tool
@@ -319,6 +502,7 @@ partial void ProcessCreateToolResponseContent( /// /// Type-specific configuration for the tool. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task CreateToolAsync( @@ -326,6 +510,7 @@ partial void ProcessCreateToolResponseContent( string description, global::Anam.CreateToolRequestType type, object? config = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.CreateToolRequest @@ -338,6 +523,7 @@ partial void ProcessCreateToolResponseContent( return await CreateToolAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.ToolsClient.DeleteTool.g.cs b/src/libs/Anam/Generated/Anam.ToolsClient.DeleteTool.g.cs index e63798e..09630b3 100644 --- a/src/libs/Anam/Generated/Anam.ToolsClient.DeleteTool.g.cs +++ b/src/libs/Anam/Generated/Anam.ToolsClient.DeleteTool.g.cs @@ -14,6 +14,7 @@ public partial class ToolsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -40,10 +41,12 @@ partial void ProcessDeleteToolResponse( /// Delete a tool (soft-deleted). ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task DeleteToolAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -58,22 +61,43 @@ partial void ProcessDeleteToolResponse( securityRequirements: s_DeleteToolSecurityRequirements, operationName: "DeleteToolAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/tools/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Delete, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/tools/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Delete, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -83,227 +107,386 @@ partial void ProcessDeleteToolResponse( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareDeleteToolRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareDeleteToolRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessDeleteToolResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteTool", + methodName: "DeleteToolAsync", + pathTemplate: "$\"/v1/tools/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteTool", + methodName: "DeleteToolAsync", + pathTemplate: "$\"/v1/tools/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - throw new global::Anam.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteTool", + methodName: "DeleteToolAsync", + pathTemplate: "$\"/v1/tools/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessDeleteToolResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteTool", + methodName: "DeleteToolAsync", + pathTemplate: "$\"/v1/tools/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteTool", + methodName: "DeleteToolAsync", + pathTemplate: "$\"/v1/tools/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Anam/Generated/Anam.ToolsClient.GetTool.g.cs b/src/libs/Anam/Generated/Anam.ToolsClient.GetTool.g.cs index a3ce985..2981a85 100644 --- a/src/libs/Anam/Generated/Anam.ToolsClient.GetTool.g.cs +++ b/src/libs/Anam/Generated/Anam.ToolsClient.GetTool.g.cs @@ -14,6 +14,7 @@ public partial class ToolsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,10 +46,12 @@ partial void ProcessGetToolResponseContent( /// Get a tool by ID. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GetToolAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -63,22 +66,43 @@ partial void ProcessGetToolResponseContent( securityRequirements: s_GetToolSecurityRequirements, operationName: "GetToolAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/tools/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/tools/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -88,211 +112,370 @@ partial void ProcessGetToolResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGetToolRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGetToolRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGetToolResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetTool", + methodName: "GetToolAsync", + pathTemplate: "$\"/v1/tools/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetTool", + methodName: "GetToolAsync", + pathTemplate: "$\"/v1/tools/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetTool", + methodName: "GetToolAsync", + pathTemplate: "$\"/v1/tools/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessGetToolResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetTool", + methodName: "GetToolAsync", + pathTemplate: "$\"/v1/tools/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetTool", + methodName: "GetToolAsync", + pathTemplate: "$\"/v1/tools/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessGetToolResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - try - { - __response.EnsureSuccessStatusCode(); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - global::Anam.Tool.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGetToolResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); - return - await global::Anam.Tool.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.Tool.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.Tool.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.ToolsClient.ListTools.g.cs b/src/libs/Anam/Generated/Anam.ToolsClient.ListTools.g.cs index 3116467..5b63313 100644 --- a/src/libs/Anam/Generated/Anam.ToolsClient.ListTools.g.cs +++ b/src/libs/Anam/Generated/Anam.ToolsClient.ListTools.g.cs @@ -14,6 +14,7 @@ public partial class ToolsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -55,12 +56,14 @@ partial void ProcessListToolsResponseContent( /// Default Value: 10 /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ListToolsAsync( int? page = default, int? perPage = default, string? search = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -77,27 +80,48 @@ partial void ProcessListToolsResponseContent( securityRequirements: s_ListToolsSecurityRequirements, operationName: "ListToolsAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: "/v1/tools", - baseUri: HttpClient.BaseAddress); - __pathBuilder - .AddOptionalParameter("page", page?.ToString()) - .AddOptionalParameter("perPage", perPage?.ToString()) - .AddOptionalParameter("search", search) - ; - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: "/v1/tools", + baseUri: HttpClient.BaseAddress); + __pathBuilder + .AddOptionalParameter("page", page?.ToString()) + .AddOptionalParameter("perPage", perPage?.ToString()) + .AddOptionalParameter("search", search) + ; + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -107,180 +131,339 @@ partial void ProcessListToolsResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareListToolsRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - page: page, - perPage: perPage, - search: search); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareListToolsRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + page: page, + perPage: perPage, + search: search); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessListToolsResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListTools", + methodName: "ListToolsAsync", + pathTemplate: "\"/v1/tools\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListTools", + methodName: "ListToolsAsync", + pathTemplate: "\"/v1/tools\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try - { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListTools", + methodName: "ListToolsAsync", + pathTemplate: "\"/v1/tools\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_500 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - ProcessResponseContent( + ProcessResponse( client: HttpClient, - response: __response, - content: ref __content); - ProcessListToolsResponseContent( + response: __response); + ProcessListToolsResponse( httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); - - try + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - __response.EnsureSuccessStatusCode(); - - return - global::Anam.ListToolsResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListTools", + methodName: "ListToolsAsync", + pathTemplate: "\"/v1/tools\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListTools", + methodName: "ListToolsAsync", + pathTemplate: "\"/v1/tools\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - return - await global::Anam.ListToolsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } + + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessListToolsResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.ListToolsResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.ListToolsResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.ToolsClient.UpdateTool.g.cs b/src/libs/Anam/Generated/Anam.ToolsClient.UpdateTool.g.cs index 3f9781e..c2d3d46 100644 --- a/src/libs/Anam/Generated/Anam.ToolsClient.UpdateTool.g.cs +++ b/src/libs/Anam/Generated/Anam.ToolsClient.UpdateTool.g.cs @@ -14,6 +14,7 @@ public partial class ToolsClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -48,12 +49,14 @@ partial void ProcessUpdateToolResponseContent( /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UpdateToolAsync( global::System.Guid id, global::Anam.UpdateToolRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -71,22 +74,43 @@ partial void ProcessUpdateToolResponseContent( securityRequirements: s_UpdateToolSecurityRequirements, operationName: "UpdateToolAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/tools/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Put, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/tools/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Put, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -96,284 +120,443 @@ partial void ProcessUpdateToolResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareUpdateToolRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id, - request: request); + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); - - ProcessResponse( - client: HttpClient, - response: __response); - ProcessUpdateToolResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareUpdateToolRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id, + request: request); - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 403) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateTool", + methodName: "UpdateToolAsync", + pathTemplate: "$\"/v1/tools/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateTool", + methodName: "UpdateToolAsync", + pathTemplate: "$\"/v1/tools/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateTool", + methodName: "UpdateToolAsync", + pathTemplate: "$\"/v1/tools/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessUpdateToolResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateTool", + methodName: "UpdateToolAsync", + pathTemplate: "$\"/v1/tools/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateTool", + methodName: "UpdateToolAsync", + pathTemplate: "$\"/v1/tools/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessUpdateToolResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - return - global::Anam.Tool.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - await global::Anam.Tool.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessUpdateToolResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.Tool.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.Tool.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Update tool
@@ -390,6 +573,7 @@ partial void ProcessUpdateToolResponseContent( /// /// Updated type-specific configuration. /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UpdateToolAsync( @@ -398,6 +582,7 @@ partial void ProcessUpdateToolResponseContent( string? description = default, global::Anam.UpdateToolRequestType? type = default, object? config = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.UpdateToolRequest @@ -411,6 +596,7 @@ partial void ProcessUpdateToolResponseContent( return await UpdateToolAsync( id: id, request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.ToolsClient.g.cs b/src/libs/Anam/Generated/Anam.ToolsClient.g.cs index e1e0188..c8423ec 100644 --- a/src/libs/Anam/Generated/Anam.ToolsClient.g.cs +++ b/src/libs/Anam/Generated/Anam.ToolsClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class ToolsClient : global::Anam.IToolsClient, global::Sys #if DEBUG = true; #endif + + /// + public global::Anam.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public ToolsClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the ToolsClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public ToolsClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Anam.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Anam.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient); diff --git a/src/libs/Anam/Generated/Anam.VoicesClient.CreateVoice.g.cs b/src/libs/Anam/Generated/Anam.VoicesClient.CreateVoice.g.cs index 6ea2943..6746cc9 100644 --- a/src/libs/Anam/Generated/Anam.VoicesClient.CreateVoice.g.cs +++ b/src/libs/Anam/Generated/Anam.VoicesClient.CreateVoice.g.cs @@ -14,6 +14,7 @@ public partial class VoicesClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,11 +46,13 @@ partial void ProcessCreateVoiceResponseContent( /// Create a new voice by cloning from an audio file. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task CreateVoiceAsync( global::Anam.CreateVoiceRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -66,22 +69,43 @@ partial void ProcessCreateVoiceResponseContent( securityRequirements: s_CreateVoiceSecurityRequirements, operationName: "CreateVoiceAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: "/v1/voices", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Post, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: "/v1/voices", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Post, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -91,279 +115,438 @@ partial void ProcessCreateVoiceResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - using var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.Name}"), - name: "\"name\""); - var __contentAudioFile = new global::System.Net.Http.ByteArrayContent(request.AudioFile ?? global::System.Array.Empty()); - __httpRequestContent.Add( - content: __contentAudioFile, - name: "\"audioFile\"", - fileName: request.AudioFilename != null ? $"\"{request.AudioFilename}\"" : string.Empty); - if (__contentAudioFile.Headers.ContentDisposition != null) - { - __contentAudioFile.Headers.ContentDisposition.FileNameStar = null; - } - if (request.Description != default) - { + var __httpRequestContent = new global::System.Net.Http.MultipartFormDataContent(); + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.Name}"), + name: "\"name\""); + var __contentAudioFile = new global::System.Net.Http.ByteArrayContent(request.AudioFile ?? global::System.Array.Empty()); + __httpRequestContent.Add( + content: __contentAudioFile, + name: "\"audioFile\"", + fileName: request.AudioFilename != null ? $"\"{request.AudioFilename}\"" : string.Empty); + if (__contentAudioFile.Headers.ContentDisposition != null) + { + __contentAudioFile.Headers.ContentDisposition.FileNameStar = null; + } + if (request.Description != default) + { - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.Description}"), - name: "\"description\""); - } - if (request.Language != default) - { + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.Description}"), + name: "\"description\""); + } + if (request.Language != default) + { - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.Language}"), - name: "\"language\""); - } - if (request.Enhance != default) - { + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.Language}"), + name: "\"language\""); + } + if (request.Enhance != default) + { - __httpRequestContent.Add( - content: new global::System.Net.Http.StringContent($"{request.Enhance}"), - name: "\"enhance\""); - } - __httpRequest.Content = __httpRequestContent; + __httpRequestContent.Add( + content: new global::System.Net.Http.StringContent($"{request.Enhance}"), + name: "\"enhance\""); + } + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareCreateVoiceRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - request: request); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareCreateVoiceRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + request: request); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessCreateVoiceResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateVoice", + methodName: "CreateVoiceAsync", + pathTemplate: "\"/v1/voices\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateVoice", + methodName: "CreateVoiceAsync", + pathTemplate: "\"/v1/voices\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateVoice", + methodName: "CreateVoiceAsync", + pathTemplate: "\"/v1/voices\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_403 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessCreateVoiceResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateVoice", + methodName: "CreateVoiceAsync", + pathTemplate: "\"/v1/voices\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "CreateVoice", + methodName: "CreateVoiceAsync", + pathTemplate: "\"/v1/voices\"", + httpMethod: "POST", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessCreateVoiceResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - global::Anam.Voice.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - await global::Anam.Voice.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessCreateVoiceResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.Voice.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.Voice.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Create voice
@@ -389,6 +572,7 @@ partial void ProcessCreateVoiceResponseContent( /// Whether to enhance the voice quality.
/// Default Value: true /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task CreateVoiceAsync( @@ -398,6 +582,7 @@ partial void ProcessCreateVoiceResponseContent( string? description = default, string? language = default, bool? enhance = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.CreateVoiceRequest @@ -412,6 +597,7 @@ partial void ProcessCreateVoiceResponseContent( return await CreateVoiceAsync( request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.VoicesClient.DeleteVoice.g.cs b/src/libs/Anam/Generated/Anam.VoicesClient.DeleteVoice.g.cs index afb1cd6..11840fc 100644 --- a/src/libs/Anam/Generated/Anam.VoicesClient.DeleteVoice.g.cs +++ b/src/libs/Anam/Generated/Anam.VoicesClient.DeleteVoice.g.cs @@ -14,6 +14,7 @@ public partial class VoicesClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -40,10 +41,12 @@ partial void ProcessDeleteVoiceResponse( /// Delete a voice by ID. ///
/// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task DeleteVoiceAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -58,22 +61,43 @@ partial void ProcessDeleteVoiceResponse( securityRequirements: s_DeleteVoiceSecurityRequirements, operationName: "DeleteVoiceAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/voices/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Delete, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/voices/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Delete, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -83,227 +107,386 @@ partial void ProcessDeleteVoiceResponse( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareDeleteVoiceRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareDeleteVoiceRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessDeleteVoiceResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteVoice", + methodName: "DeleteVoiceAsync", + pathTemplate: "$\"/v1/voices/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteVoice", + methodName: "DeleteVoiceAsync", + pathTemplate: "$\"/v1/voices/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteVoice", + methodName: "DeleteVoiceAsync", + pathTemplate: "$\"/v1/voices/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessDeleteVoiceResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteVoice", + methodName: "DeleteVoiceAsync", + pathTemplate: "$\"/v1/voices/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "DeleteVoice", + methodName: "DeleteVoiceAsync", + pathTemplate: "$\"/v1/voices/{id}\"", + httpMethod: "DELETE", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } - else + finally { - try - { - __response.EnsureSuccessStatusCode(); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } - - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + __httpRequest?.Dispose(); } } } diff --git a/src/libs/Anam/Generated/Anam.VoicesClient.GetVoice.g.cs b/src/libs/Anam/Generated/Anam.VoicesClient.GetVoice.g.cs index 7668763..e286067 100644 --- a/src/libs/Anam/Generated/Anam.VoicesClient.GetVoice.g.cs +++ b/src/libs/Anam/Generated/Anam.VoicesClient.GetVoice.g.cs @@ -14,6 +14,7 @@ public partial class VoicesClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -45,10 +46,12 @@ partial void ProcessGetVoiceResponseContent( /// Returns a voice by ID. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task GetVoiceAsync( global::System.Guid id, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -63,22 +66,43 @@ partial void ProcessGetVoiceResponseContent( securityRequirements: s_GetVoiceSecurityRequirements, operationName: "GetVoiceAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/voices/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/voices/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -88,244 +112,403 @@ partial void ProcessGetVoiceResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareGetVoiceRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareGetVoiceRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessGetVoiceResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetVoice", + methodName: "GetVoiceAsync", + pathTemplate: "$\"/v1/voices/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetVoice", + methodName: "GetVoiceAsync", + pathTemplate: "$\"/v1/voices/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 401) - { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try - { - if (ReadResponseAsString) - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetVoice", + methodName: "GetVoiceAsync", + pathTemplate: "$\"/v1/voices/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessGetVoiceResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetVoice", + methodName: "GetVoiceAsync", + pathTemplate: "$\"/v1/voices/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "GetVoice", + methodName: "GetVoiceAsync", + pathTemplate: "$\"/v1/voices/{id}\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessGetVoiceResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - global::Anam.Voice.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - await global::Anam.Voice.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessGetVoiceResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.Voice.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.Voice.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.VoicesClient.ListVoices.g.cs b/src/libs/Anam/Generated/Anam.VoicesClient.ListVoices.g.cs index e570ab5..7cf5497 100644 --- a/src/libs/Anam/Generated/Anam.VoicesClient.ListVoices.g.cs +++ b/src/libs/Anam/Generated/Anam.VoicesClient.ListVoices.g.cs @@ -14,6 +14,7 @@ public partial class VoicesClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -55,12 +56,14 @@ partial void ProcessListVoicesResponseContent( /// Default Value: 10 /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task ListVoicesAsync( int? page = default, int? perPage = default, string? search = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { PrepareArguments( @@ -77,27 +80,48 @@ partial void ProcessListVoicesResponseContent( securityRequirements: s_ListVoicesSecurityRequirements, operationName: "ListVoicesAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: "/v1/voices", - baseUri: HttpClient.BaseAddress); - __pathBuilder - .AddOptionalParameter("page", page?.ToString()) - .AddOptionalParameter("perPage", perPage?.ToString()) - .AddOptionalParameter("search", search) - ; - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Get, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: "/v1/voices", + baseUri: HttpClient.BaseAddress); + __pathBuilder + .AddOptionalParameter("page", page?.ToString()) + .AddOptionalParameter("perPage", perPage?.ToString()) + .AddOptionalParameter("search", search) + ; + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Get, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -107,246 +131,405 @@ partial void ProcessListVoicesResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareListVoicesRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - page: page, - perPage: perPage, - search: search); + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareListVoicesRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + page: page, + perPage: perPage, + search: search); - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + return __httpRequest; + } - ProcessResponse( - client: HttpClient, - response: __response); - ProcessListVoicesResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 401) + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListVoices", + methodName: "ListVoicesAsync", + pathTemplate: "\"/v1/voices\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListVoices", + methodName: "ListVoicesAsync", + pathTemplate: "\"/v1/voices\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 403) - { - string? __content_403 = null; - global::System.Exception? __exception_403 = null; - try - { - if (ReadResponseAsString) - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_403 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - } - catch (global::System.Exception __ex) - { - __exception_403 = __ex; - } - throw new global::Anam.ApiException( - message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_403, - statusCode: __response.StatusCode) - { - ResponseBody = __content_403, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListVoices", + methodName: "ListVoicesAsync", + pathTemplate: "\"/v1/voices\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessListVoicesResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListVoices", + methodName: "ListVoicesAsync", + pathTemplate: "\"/v1/voices\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "ListVoices", + methodName: "ListVoicesAsync", + pathTemplate: "\"/v1/voices\"", + httpMethod: "GET", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 403) + { + string? __content_403 = null; + global::System.Exception? __exception_403 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_403 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_403 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_403 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_403, + statusCode: __response.StatusCode) + { + ResponseBody = __content_403, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessListVoicesResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - global::Anam.ListVoicesResponse.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - await global::Anam.ListVoicesResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessListVoicesResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.ListVoicesResponse.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.ListVoicesResponse.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } } } \ No newline at end of file diff --git a/src/libs/Anam/Generated/Anam.VoicesClient.UpdateVoice.g.cs b/src/libs/Anam/Generated/Anam.VoicesClient.UpdateVoice.g.cs index dbad795..523d39c 100644 --- a/src/libs/Anam/Generated/Anam.VoicesClient.UpdateVoice.g.cs +++ b/src/libs/Anam/Generated/Anam.VoicesClient.UpdateVoice.g.cs @@ -14,6 +14,7 @@ public partial class VoicesClient { new global::Anam.EndPointAuthorizationRequirement { Type = "Http", + SchemeId = "HttpBearer", Location = "Header", Name = "Bearer", FriendlyName = "Bearer", @@ -48,12 +49,14 @@ partial void ProcessUpdateVoiceResponseContent( /// /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UpdateVoiceAsync( global::System.Guid id, global::Anam.UpdateVoiceRequest request, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { request = request ?? throw new global::System.ArgumentNullException(nameof(request)); @@ -71,22 +74,43 @@ partial void ProcessUpdateVoiceResponseContent( securityRequirements: s_UpdateVoiceSecurityRequirements, operationName: "UpdateVoiceAsync"); - var __pathBuilder = new global::Anam.PathBuilder( - path: $"/v1/voices/{id}", - baseUri: HttpClient.BaseAddress); - var __path = __pathBuilder.ToString(); - using var __httpRequest = new global::System.Net.Http.HttpRequestMessage( - method: global::System.Net.Http.HttpMethod.Put, - requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); + using var __timeoutCancellationTokenSource = global::Anam.AutoSDKRequestOptionsSupport.CreateTimeoutCancellationTokenSource( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: cancellationToken); + var __effectiveCancellationToken = __timeoutCancellationTokenSource?.Token ?? cancellationToken; + var __effectiveReadResponseAsString = global::Anam.AutoSDKRequestOptionsSupport.GetReadResponseAsString( + clientOptions: Options, + requestOptions: requestOptions, + fallbackValue: ReadResponseAsString); + var __maxAttempts = global::Anam.AutoSDKRequestOptionsSupport.GetMaxAttempts( + clientOptions: Options, + requestOptions: requestOptions, + supportsRetry: true); + + global::System.Net.Http.HttpRequestMessage __CreateHttpRequest() + { + var __pathBuilder = new global::Anam.PathBuilder( + path: $"/v1/voices/{id}", + baseUri: HttpClient.BaseAddress); + var __path = __pathBuilder.ToString(); + __path = global::Anam.AutoSDKRequestOptionsSupport.AppendQueryParameters( + path: __path, + clientParameters: Options.QueryParameters, + requestParameters: requestOptions?.QueryParameters); + var __httpRequest = new global::System.Net.Http.HttpRequestMessage( + method: global::System.Net.Http.HttpMethod.Put, + requestUri: new global::System.Uri(__path, global::System.UriKind.RelativeOrAbsolute)); #if NET6_0_OR_GREATER - __httpRequest.Version = global::System.Net.HttpVersion.Version11; - __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; + __httpRequest.Version = global::System.Net.HttpVersion.Version11; + __httpRequest.VersionPolicy = global::System.Net.Http.HttpVersionPolicy.RequestVersionOrHigher; #endif foreach (var __authorization in __authorizations) { if (__authorization.Type == "Http" || - __authorization.Type == "OAuth2") + __authorization.Type == "OAuth2" || + __authorization.Type == "OpenIdConnect") { __httpRequest.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( scheme: __authorization.Name, @@ -96,251 +120,410 @@ partial void ProcessUpdateVoiceResponseContent( __authorization.Location == "Header") { __httpRequest.Headers.Add(__authorization.Name, __authorization.Value); - } + } } - var __httpRequestContentBody = request.ToJson(JsonSerializerContext); - var __httpRequestContent = new global::System.Net.Http.StringContent( - content: __httpRequestContentBody, - encoding: global::System.Text.Encoding.UTF8, - mediaType: "application/json"); - __httpRequest.Content = __httpRequestContent; - - PrepareRequest( - client: HttpClient, - request: __httpRequest); - PrepareUpdateVoiceRequest( - httpClient: HttpClient, - httpRequestMessage: __httpRequest, - id: id, - request: request); - - using var __response = await HttpClient.SendAsync( - request: __httpRequest, - completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, - cancellationToken: cancellationToken).ConfigureAwait(false); + var __httpRequestContentBody = request.ToJson(JsonSerializerContext); + var __httpRequestContent = new global::System.Net.Http.StringContent( + content: __httpRequestContentBody, + encoding: global::System.Text.Encoding.UTF8, + mediaType: "application/json"); + __httpRequest.Content = __httpRequestContent; + global::Anam.AutoSDKRequestOptionsSupport.ApplyHeaders( + request: __httpRequest, + clientHeaders: Options.Headers, + requestHeaders: requestOptions?.Headers); - ProcessResponse( - client: HttpClient, - response: __response); - ProcessUpdateVoiceResponse( - httpClient: HttpClient, - httpResponseMessage: __response); - // - if ((int)__response.StatusCode == 400) - { - string? __content_400 = null; - global::System.Exception? __exception_400 = null; - try - { - if (ReadResponseAsString) - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_400 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_400 = __ex; - } + PrepareRequest( + client: HttpClient, + request: __httpRequest); + PrepareUpdateVoiceRequest( + httpClient: HttpClient, + httpRequestMessage: __httpRequest, + id: id, + request: request); - throw new global::Anam.ApiException( - message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_400, - statusCode: __response.StatusCode) - { - ResponseBody = __content_400, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; + return __httpRequest; } - // - if ((int)__response.StatusCode == 401) + + global::System.Net.Http.HttpRequestMessage? __httpRequest = null; + global::System.Net.Http.HttpResponseMessage? __response = null; + var __attemptNumber = 0; + try { - string? __content_401 = null; - global::System.Exception? __exception_401 = null; - try + for (var __attempt = 1; __attempt <= __maxAttempts; __attempt++) { - if (ReadResponseAsString) + __attemptNumber = __attempt; + __httpRequest = __CreateHttpRequest(); + await global::Anam.AutoSDKRequestOptionsSupport.OnBeforeRequestAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateVoice", + methodName: "UpdateVoiceAsync", + pathTemplate: "$\"/v1/voices/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + try { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __response = await HttpClient.SendAsync( + request: __httpRequest, + completionOption: global::System.Net.Http.HttpCompletionOption.ResponseContentRead, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); } - else + catch (global::System.Net.Http.HttpRequestException __exception) { - __content_401 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - } - catch (global::System.Exception __ex) - { - __exception_401 = __ex; - } + var __willRetry = __attempt < __maxAttempts && !__effectiveCancellationToken.IsCancellationRequested; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateVoice", + methodName: "UpdateVoiceAsync", + pathTemplate: "$\"/v1/voices/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: null, + exception: __exception, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: __willRetry, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + if (!__willRetry) + { + throw; + } - throw new global::Anam.ApiException( - message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_401, - statusCode: __response.StatusCode) - { - ResponseBody = __content_401, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 404) - { - string? __content_404 = null; - global::System.Exception? __exception_404 = null; - try - { - if (ReadResponseAsString) - { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } - else + + if (__response != null && + __attempt < __maxAttempts && + global::Anam.AutoSDKRequestOptionsSupport.ShouldRetryStatusCode(__response.StatusCode)) { - __content_404 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateVoice", + methodName: "UpdateVoiceAsync", + pathTemplate: "$\"/v1/voices/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attempt, + maxAttempts: __maxAttempts, + willRetry: true, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); + __response.Dispose(); + __response = null; + __httpRequest.Dispose(); + __httpRequest = null; + await global::Anam.AutoSDKRequestOptionsSupport.DelayBeforeRetryAsync( + clientOptions: Options, + requestOptions: requestOptions, + cancellationToken: __effectiveCancellationToken).ConfigureAwait(false); + continue; } + + break; } - catch (global::System.Exception __ex) + + if (__response == null) { - __exception_404 = __ex; + throw new global::System.InvalidOperationException("No response received."); } - throw new global::Anam.ApiException( - message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_404, - statusCode: __response.StatusCode) + using (__response) { - ResponseBody = __content_404, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - // - if ((int)__response.StatusCode == 500) - { - string? __content_500 = null; - global::System.Exception? __exception_500 = null; - try + + ProcessResponse( + client: HttpClient, + response: __response); + ProcessUpdateVoiceResponse( + httpClient: HttpClient, + httpResponseMessage: __response); + if (__response.IsSuccessStatusCode) { - if (ReadResponseAsString) - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } - else - { - __content_500 = await __response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false); - } + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterSuccessAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateVoice", + methodName: "UpdateVoiceAsync", + pathTemplate: "$\"/v1/voices/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } - catch (global::System.Exception __ex) + else { - __exception_500 = __ex; + await global::Anam.AutoSDKRequestOptionsSupport.OnAfterErrorAsync( + clientOptions: Options, + context: global::Anam.AutoSDKRequestOptionsSupport.CreateHookContext( + operationId: "UpdateVoice", + methodName: "UpdateVoiceAsync", + pathTemplate: "$\"/v1/voices/{id}\"", + httpMethod: "PUT", + baseUri: BaseUri, + request: __httpRequest!, + response: __response, + exception: null, + clientOptions: Options, + requestOptions: requestOptions, + attempt: __attemptNumber, + maxAttempts: __maxAttempts, + willRetry: false, + cancellationToken: __effectiveCancellationToken)).ConfigureAwait(false); } + // + if ((int)__response.StatusCode == 400) + { + string? __content_400 = null; + global::System.Exception? __exception_400 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_400 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_400 = __ex; + } - throw new global::Anam.ApiException( - message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, - innerException: __exception_500, - statusCode: __response.StatusCode) - { - ResponseBody = __content_500, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } + throw new global::Anam.ApiException( + message: __content_400 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_400, + statusCode: __response.StatusCode) + { + ResponseBody = __content_400, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 401) + { + string? __content_401 = null; + global::System.Exception? __exception_401 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_401 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_401 = __ex; + } - if (ReadResponseAsString) - { - var __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + throw new global::Anam.ApiException( + message: __content_401 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_401, + statusCode: __response.StatusCode) + { + ResponseBody = __content_401, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 404) + { + string? __content_404 = null; + global::System.Exception? __exception_404 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_404 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_404 = __ex; + } - ProcessResponseContent( - client: HttpClient, - response: __response, - content: ref __content); - ProcessUpdateVoiceResponseContent( - httpClient: HttpClient, - httpResponseMessage: __response, - content: ref __content); + throw new global::Anam.ApiException( + message: __content_404 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_404, + statusCode: __response.StatusCode) + { + ResponseBody = __content_404, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + // + if ((int)__response.StatusCode == 500) + { + string? __content_500 = null; + global::System.Exception? __exception_500 = null; + try + { + if (__effectiveReadResponseAsString) + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + else + { + __content_500 = await __response.Content.ReadAsStringAsync(__effectiveCancellationToken).ConfigureAwait(false); + } + } + catch (global::System.Exception __ex) + { + __exception_500 = __ex; + } - try - { - __response.EnsureSuccessStatusCode(); + throw new global::Anam.ApiException( + message: __content_500 ?? __response.ReasonPhrase ?? string.Empty, + innerException: __exception_500, + statusCode: __response.StatusCode) + { + ResponseBody = __content_500, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } - return - global::Anam.Voice.FromJson(__content, JsonSerializerContext) ?? - throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); - } - catch (global::System.Exception __ex) - { - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; - } - } - else - { - try - { - __response.EnsureSuccessStatusCode(); - using var __content = await __response.Content.ReadAsStreamAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); + if (__effectiveReadResponseAsString) + { + var __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); - return - await global::Anam.Voice.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? - throw new global::System.InvalidOperationException("Response deserialization failed."); - } - catch (global::System.Exception __ex) - { - string? __content = null; - try - { - __content = await __response.Content.ReadAsStringAsync( -#if NET5_0_OR_GREATER - cancellationToken -#endif - ).ConfigureAwait(false); - } - catch (global::System.Exception) - { - } + ProcessResponseContent( + client: HttpClient, + response: __response, + content: ref __content); + ProcessUpdateVoiceResponseContent( + httpClient: HttpClient, + httpResponseMessage: __response, + content: ref __content); + + try + { + __response.EnsureSuccessStatusCode(); + + return + global::Anam.Voice.FromJson(__content, JsonSerializerContext) ?? + throw new global::System.InvalidOperationException($"Response deserialization failed for \"{__content}\" "); + } + catch (global::System.Exception __ex) + { + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } + else + { + try + { + __response.EnsureSuccessStatusCode(); + using var __content = await __response.Content.ReadAsStreamAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + + return + await global::Anam.Voice.FromJsonStreamAsync(__content, JsonSerializerContext).ConfigureAwait(false) ?? + throw new global::System.InvalidOperationException("Response deserialization failed."); + } + catch (global::System.Exception __ex) + { + string? __content = null; + try + { + __content = await __response.Content.ReadAsStringAsync( + #if NET5_0_OR_GREATER + __effectiveCancellationToken + #endif + ).ConfigureAwait(false); + } + catch (global::System.Exception) + { + } + + throw new global::Anam.ApiException( + message: __content ?? __response.ReasonPhrase ?? string.Empty, + innerException: __ex, + statusCode: __response.StatusCode) + { + ResponseBody = __content, + ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( + __response.Headers, + h => h.Key, + h => h.Value), + }; + } + } - throw new global::Anam.ApiException( - message: __content ?? __response.ReasonPhrase ?? string.Empty, - innerException: __ex, - statusCode: __response.StatusCode) - { - ResponseBody = __content, - ResponseHeaders = global::System.Linq.Enumerable.ToDictionary( - __response.Headers, - h => h.Key, - h => h.Value), - }; } } + finally + { + __httpRequest?.Dispose(); + } } /// /// Update voice
@@ -358,6 +541,7 @@ partial void ProcessUpdateVoiceResponseContent( /// ISO 3166-1 alpha-2 country code. /// /// + /// Per-request overrides such as headers, query parameters, timeout, retries, and response buffering. /// The token to cancel the operation with /// public async global::System.Threading.Tasks.Task UpdateVoiceAsync( @@ -367,6 +551,7 @@ partial void ProcessUpdateVoiceResponseContent( global::Anam.UpdateVoiceRequestGender? gender = default, string? country = default, string? description = default, + global::Anam.AutoSDKRequestOptions? requestOptions = default, global::System.Threading.CancellationToken cancellationToken = default) { var __request = new global::Anam.UpdateVoiceRequest @@ -381,6 +566,7 @@ partial void ProcessUpdateVoiceResponseContent( return await UpdateVoiceAsync( id: id, request: __request, + requestOptions: requestOptions, cancellationToken: cancellationToken).ConfigureAwait(false); } } diff --git a/src/libs/Anam/Generated/Anam.VoicesClient.g.cs b/src/libs/Anam/Generated/Anam.VoicesClient.g.cs index 4406cd1..77871b9 100644 --- a/src/libs/Anam/Generated/Anam.VoicesClient.g.cs +++ b/src/libs/Anam/Generated/Anam.VoicesClient.g.cs @@ -30,6 +30,9 @@ public sealed partial class VoicesClient : global::Anam.IVoicesClient, global::S #if DEBUG = true; #endif + + /// + public global::Anam.AutoSDKClientOptions Options { get; } /// /// /// @@ -49,11 +52,37 @@ public VoicesClient( global::System.Net.Http.HttpClient? httpClient = null, global::System.Uri? baseUri = null, global::System.Collections.Generic.List? authorizations = null, + bool disposeHttpClient = true) : this( + httpClient, + baseUri, + authorizations, + options: null, + disposeHttpClient: disposeHttpClient) + { + } + + /// + /// Creates a new instance of the VoicesClient. + /// If no httpClient is provided, a new one will be created. + /// If no baseUri is provided, the default baseUri from OpenAPI spec will be used. + /// + /// The HttpClient instance. If not provided, a new one will be created. + /// The base URL for the API. If not provided, the default baseUri from OpenAPI spec will be used. + /// The authorizations to use for the requests. + /// Client-wide request defaults such as headers, query parameters, retries, and timeout. + /// Dispose the HttpClient when the instance is disposed. True by default. + public VoicesClient( + global::System.Net.Http.HttpClient? httpClient = null, + global::System.Uri? baseUri = null, + global::System.Collections.Generic.List? authorizations = null, + global::Anam.AutoSDKClientOptions? options = null, bool disposeHttpClient = true) { + HttpClient = httpClient ?? new global::System.Net.Http.HttpClient(); HttpClient.BaseAddress ??= baseUri ?? new global::System.Uri(DefaultBaseUrl); Authorizations = authorizations ?? new global::System.Collections.Generic.List(); + Options = options ?? new global::Anam.AutoSDKClientOptions(); _disposeHttpClient = disposeHttpClient; Initialized(HttpClient);