From 61753117fbdd18472c7aebfcd105005b7e144897 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Sun, 10 May 2026 18:41:41 +0000 Subject: [PATCH] feat: Updated OpenAPI spec --- .../Generated/ScaleAI.OptionsSupport.g.cs | 150 ++++++++++++++++++ 1 file changed, 150 insertions(+) diff --git a/src/libs/ScaleAI/Generated/ScaleAI.OptionsSupport.g.cs b/src/libs/ScaleAI/Generated/ScaleAI.OptionsSupport.g.cs index 7f6ca22..41a1d9a 100644 --- a/src/libs/ScaleAI/Generated/ScaleAI.OptionsSupport.g.cs +++ b/src/libs/ScaleAI/Generated/ScaleAI.OptionsSupport.g.cs @@ -54,6 +54,156 @@ public sealed class AutoSDKClientOptions Hooks.Add(hook ?? throw new global::System.ArgumentNullException(nameof(hook))); return this; } + + /// + /// Optional per-request authorization provider invoked before each request is sent. + /// Set this when the client is registered as a singleton in DI but each call needs + /// a fresh credential resolved from a provider, secret-store, or session — instead + /// of mutating the shared Authorizations list at construction time. + /// + public global::ScaleAI.IAutoSDKAuthorizationProvider? AuthorizationProvider { get; set; } + + /// + /// Convenience helper that registers + /// using so request-level auth is resolved without + /// touching shared client state. + /// + /// + public global::ScaleAI.AutoSDKClientOptions UseAuthorizationProvider( + global::ScaleAI.IAutoSDKAuthorizationProvider provider) + { + AuthorizationProvider = provider ?? throw new global::System.ArgumentNullException(nameof(provider)); + if (Hooks.Find(static x => x is global::ScaleAI.AutoSDKAuthorizationProviderHook) == null) + { + Hooks.Add(new global::ScaleAI.AutoSDKAuthorizationProviderHook()); + } + + return this; + } + } + + /// + /// A request-level authorization value supplied by . + /// Mirrors the runtime fields the SDK applies for HTTP / OAuth2 / API-key auth without + /// requiring the consumer to construct the generated EndPointAuthorization type. + /// + public readonly struct AutoSDKAuthorizationValue + { + /// + /// Initializes a new . + /// + /// + /// + /// + /// + /// + public AutoSDKAuthorizationValue( + string value, + string scheme = "Bearer", + string? headerName = null, + string location = "Header", + string type = "Http") + { + Value = value ?? string.Empty; + Scheme = string.IsNullOrWhiteSpace(scheme) ? "Bearer" : scheme; + HeaderName = headerName ?? string.Empty; + Location = string.IsNullOrWhiteSpace(location) ? "Header" : location; + Type = string.IsNullOrWhiteSpace(type) ? "Http" : type; + } + + /// The credential value (token, API key, etc.). + public string Value { get; } + + /// The HTTP authorization scheme — typically Bearer, Basic, or Token. + public string Scheme { get; } + + /// The custom header name when is ApiKey; ignored for HTTP/OAuth2 auth. + public string HeaderName { get; } + + /// The credential location — Header, Query, or Cookie. + public string Location { get; } + + /// The auth type — Http, OAuth2, OpenIdConnect, or ApiKey. + public string Type { get; } + + /// Convenience factory for a Bearer token. + public static global::ScaleAI.AutoSDKAuthorizationValue Bearer(string token) => new(value: token, scheme: "Bearer"); + + /// Convenience factory for an API-key header. + public static global::ScaleAI.AutoSDKAuthorizationValue ApiKeyHeader(string name, string value) => + new(value: value, headerName: name, location: "Header", type: "ApiKey"); + } + + /// + /// Resolves request-level authorization values without mutating the shared client + /// authorization list. Implementations should be safe to invoke concurrently — + /// the hook calls them once per outgoing request. + /// + public interface IAutoSDKAuthorizationProvider + { + /// + /// Returns one or more values to apply to + /// the current request, or an empty list / null to leave the request as-is. + /// + /// + global::System.Threading.Tasks.Task?> ResolveAsync( + global::ScaleAI.AutoSDKHookContext context); + } + + /// + /// Built-in that consults + /// before every outgoing + /// request and stamps the resolved values onto the . + /// + public sealed class AutoSDKAuthorizationProviderHook : global::ScaleAI.AutoSDKHook + { + /// + public override async global::System.Threading.Tasks.Task OnBeforeRequestAsync( + global::ScaleAI.AutoSDKHookContext context) + { + context = context ?? throw new global::System.ArgumentNullException(nameof(context)); + + var provider = context.ClientOptions?.AuthorizationProvider; + if (provider == null || context.Request == null) + { + return; + } + + var resolved = await provider.ResolveAsync(context).ConfigureAwait(false); + if (resolved == null || resolved.Count == 0) + { + return; + } + + for (var index = 0; index < resolved.Count; index++) + { + ApplyAuthorization(context.Request, resolved[index]); + } + } + + private static void ApplyAuthorization( + global::System.Net.Http.HttpRequestMessage request, + global::ScaleAI.AutoSDKAuthorizationValue authorization) + { + switch (authorization.Type) + { + case "Http": + case "OAuth2": + case "OpenIdConnect": + request.Headers.Authorization = new global::System.Net.Http.Headers.AuthenticationHeaderValue( + scheme: authorization.Scheme, + parameter: authorization.Value); + break; + case "ApiKey": + if (string.Equals(authorization.Location, "Header", global::System.StringComparison.OrdinalIgnoreCase) && + !string.IsNullOrEmpty(authorization.HeaderName)) + { + request.Headers.Remove(authorization.HeaderName); + request.Headers.TryAddWithoutValidation(authorization.HeaderName, authorization.Value ?? string.Empty); + } + break; + } + } } ///