mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2026-02-10 17:50:58 +00:00
Compare commits
11 Commits
revert-217
...
python-ser
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2199534829 | ||
|
|
ea4d07da11 | ||
|
|
dbba72842f | ||
|
|
73a486a726 | ||
|
|
ad948aa093 | ||
|
|
047ea41087 | ||
|
|
39a3bfa181 | ||
|
|
8cd3ea2457 | ||
|
|
a4985cad28 | ||
|
|
422e30a3d9 | ||
|
|
67cbfb3cad |
@@ -21,7 +21,7 @@ jobs:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: '3.9'
|
||||
python-version: '3.10'
|
||||
- name: Install dependencies
|
||||
working-directory: ${{ matrix.sample }}
|
||||
run: |
|
||||
|
||||
2
.github/workflows/samples-python-server.yaml
vendored
2
.github/workflows/samples-python-server.yaml
vendored
@@ -21,7 +21,7 @@ jobs:
|
||||
- uses: actions/checkout@v5
|
||||
- uses: actions/setup-python@v6
|
||||
with:
|
||||
python-version: '3.9'
|
||||
python-version: '3.10'
|
||||
- name: Test
|
||||
working-directory: ${{ matrix.sample }}
|
||||
run: make test-all
|
||||
|
||||
@@ -488,7 +488,7 @@
|
||||
<dependency>
|
||||
<groupId>org.assertj</groupId>
|
||||
<artifactId>assertj-core</artifactId>
|
||||
<version>3.23.1</version>
|
||||
<version>3.27.7</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
|
||||
@@ -98,7 +98,7 @@ namespace {{packageName}}.{{clientPackage}}
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
{{#apiInfo}}{{#apis}}builders.Add(_services.AddHttpClient<{{interfacePrefix}}{{classname}}, {{classname}}>(client));
|
||||
{{#apiInfo}}{{#apis}}builders.Add(_services.AddHttpClient<{{interfacePrefix}}{{classname}}, {{classname}}>("{{packageName}}.{{apiPackage}}.{{interfacePrefix}}{{classname}}", client));
|
||||
{{/apis}}{{/apiInfo}}
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -16,7 +16,11 @@ namespace {{packageName}}.{{clientPackage}}
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
{{>visibility}} class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new{{^net70OrLater}} Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>{{/net70OrLater}}();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new{{^net70OrLater}} Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>{{/net70OrLater}}();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -85,7 +89,7 @@ namespace {{packageName}}.{{clientPackage}}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}})
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}})
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>{{nrt?}} tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -19,7 +19,16 @@ namespace {{packageName}}.{{clientPackage}}
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler{{nrt?}} TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -16,6 +16,12 @@ namespace {{packageName}}
|
||||
/// </summary>
|
||||
{{>visibility}} abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}});
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}});
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ orjson==3.9.15
|
||||
promise==2.3
|
||||
pydantic>=2
|
||||
python-dotenv==0.17.1
|
||||
python-multipart==0.0.18
|
||||
python-multipart==0.0.22
|
||||
PyYAML>=5.4.1,<6.1.0
|
||||
requests==2.32.4
|
||||
Rx==1.6.1
|
||||
|
||||
@@ -66,22 +66,22 @@ secrecy = "0.8.0"
|
||||
{{/withAWSV4Signature}}
|
||||
{{#reqwest}}
|
||||
{{^supportAsync}}
|
||||
reqwest = { version = "^0.12", default-features = false, features = ["json", "blocking", "multipart"] }
|
||||
reqwest = { version = "^0.13", default-features = false, features = ["json", "blocking", "multipart", "query", "form"] }
|
||||
{{#supportMiddleware}}
|
||||
reqwest-middleware = { version = "^0.4", features = ["json", "blocking", "multipart"] }
|
||||
reqwest-middleware = { version = "^0.5", features = ["json", "multipart", "query", "form"] }
|
||||
{{/supportMiddleware}}
|
||||
{{/supportAsync}}
|
||||
{{#supportAsync}}
|
||||
{{#useAsyncFileStream}}
|
||||
tokio = { version = "^1.46.0", features = ["fs"] }
|
||||
tokio-util = { version = "^0.7", features = ["codec"] }
|
||||
reqwest = { version = "^0.12", default-features = false, features = ["json", "multipart", "stream"] }
|
||||
reqwest = { version = "^0.13", default-features = false, features = ["json", "multipart", "stream", "query", "form"] }
|
||||
{{/useAsyncFileStream}}
|
||||
{{^useAsyncFileStream}}
|
||||
reqwest = { version = "^0.12", default-features = false, features = ["json", "multipart"] }
|
||||
reqwest = { version = "^0.13", default-features = false, features = ["json", "multipart", "query", "form"] }
|
||||
{{/useAsyncFileStream}}
|
||||
{{#supportMiddleware}}
|
||||
reqwest-middleware = { version = "^0.4", features = ["json", "multipart"] }
|
||||
reqwest-middleware = { version = "^0.5", features = ["json", "multipart", "query", "form"] }
|
||||
{{/supportMiddleware}}
|
||||
{{#supportTokenSource}}
|
||||
async-trait = "^0.1"
|
||||
@@ -93,13 +93,13 @@ google-cloud-token = "^0.1"
|
||||
[features]
|
||||
default = [{{#reqwestDefaultFeatures}}"{{.}}"{{^-last}}, {{/-last}}{{/reqwestDefaultFeatures}}]
|
||||
native-tls = ["reqwest/native-tls"]
|
||||
rustls-tls = ["reqwest/rustls-tls"]
|
||||
rustls = ["reqwest/rustls"]
|
||||
{{/reqwest}}
|
||||
{{#reqwestTrait}}
|
||||
async-trait = "^0.1"
|
||||
reqwest = { version = "^0.12", default-features = false, features = ["json", "multipart", "stream"] }
|
||||
reqwest = { version = "^0.13", default-features = false, features = ["json", "multipart", "stream", "query", "form"] }
|
||||
{{#supportMiddleware}}
|
||||
reqwest-middleware = { version = "^0.4", features = ["json", "multipart"] }
|
||||
reqwest-middleware = { version = "^0.5", features = ["json", "multipart", "query", "form"] }
|
||||
{{/supportMiddleware}}
|
||||
{{#supportTokenSource}}
|
||||
# TODO: propose to Yoshidan to externalize this as non google related crate, so that it can easily be extended for other cloud providers.
|
||||
@@ -114,7 +114,7 @@ bon = { version = "2.3", optional = true }
|
||||
[features]
|
||||
default = [{{#reqwestDefaultFeatures}}"{{.}}"{{^-last}}, {{/-last}}{{/reqwestDefaultFeatures}}]
|
||||
native-tls = ["reqwest/native-tls"]
|
||||
rustls-tls = ["reqwest/rustls-tls"]
|
||||
rustls = ["reqwest/rustls"]
|
||||
{{#mockall}}
|
||||
mockall = ["dep:mockall"]
|
||||
{{/mockall}}
|
||||
|
||||
@@ -42,6 +42,19 @@ export interface {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterIn
|
||||
*/
|
||||
export interface {{classname}}Interface {
|
||||
{{#operation}}
|
||||
/**
|
||||
* Creates request options for {{nickname}} without sending the request
|
||||
{{#allParams}}
|
||||
* @param {{=<% %>=}}{<%&dataType%>}<%={{ }}=%> {{^required}}[{{/required}}{{paramName}}{{^required}}]{{/required}} {{description}}
|
||||
{{/allParams}}
|
||||
{{#isDeprecated}}
|
||||
* @deprecated
|
||||
{{/isDeprecated}}
|
||||
* @throws {RequiredError}
|
||||
* @memberof {{classname}}Interface
|
||||
*/
|
||||
{{nickname}}RequestOpts({{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request{{/allParams.0}}): Promise<runtime.RequestOpts>;
|
||||
|
||||
/**
|
||||
* {{¬es}}
|
||||
{{#summary}}
|
||||
@@ -95,17 +108,12 @@ export class {{classname}} extends runtime.BaseAPI {
|
||||
|
||||
{{#operation}}
|
||||
/**
|
||||
{{#notes}}
|
||||
* {{¬es}}
|
||||
{{/notes}}
|
||||
{{#summary}}
|
||||
* {{&summary}}
|
||||
{{/summary}}
|
||||
* Creates request options for {{nickname}} without sending the request
|
||||
{{#isDeprecated}}
|
||||
* @deprecated
|
||||
{{/isDeprecated}}
|
||||
*/
|
||||
async {{nickname}}Raw({{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request, {{/allParams.0}}initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<{{{returnType}}}{{^returnType}}void{{/returnType}}>> {
|
||||
async {{nickname}}RequestOpts({{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request{{/allParams.0}}): Promise<runtime.RequestOpts> {
|
||||
{{#allParams}}
|
||||
{{#required}}
|
||||
if (requestParameters['{{paramName}}'] == null) {
|
||||
@@ -304,7 +312,7 @@ export class {{classname}} extends runtime.BaseAPI {
|
||||
{{/isDateTimeType}}
|
||||
{{/pathParams}}
|
||||
|
||||
const response = await this.request({
|
||||
return {
|
||||
path: urlPath,
|
||||
method: '{{httpMethod}}',
|
||||
headers: headerParameters,
|
||||
@@ -337,7 +345,23 @@ export class {{classname}} extends runtime.BaseAPI {
|
||||
{{#hasFormParams}}
|
||||
body: formParams,
|
||||
{{/hasFormParams}}
|
||||
}, initOverrides);
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
{{#notes}}
|
||||
* {{¬es}}
|
||||
{{/notes}}
|
||||
{{#summary}}
|
||||
* {{&summary}}
|
||||
{{/summary}}
|
||||
{{#isDeprecated}}
|
||||
* @deprecated
|
||||
{{/isDeprecated}}
|
||||
*/
|
||||
async {{nickname}}Raw({{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request, {{/allParams.0}}initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<{{{returnType}}}{{^returnType}}void{{/returnType}}>> {
|
||||
const requestOptions = await this.{{nickname}}RequestOpts({{#allParams.0}}requestParameters{{/allParams.0}});
|
||||
const response = await this.request(requestOptions, initOverrides);
|
||||
|
||||
{{#returnType}}
|
||||
{{#isResponseFile}}
|
||||
|
||||
@@ -12,9 +12,9 @@ serde = { version = "^1.0", features = ["derive"] }
|
||||
serde_json = "^1.0"
|
||||
serde_repr = "^0.1"
|
||||
url = "^2.5"
|
||||
reqwest = { version = "^0.12", default-features = false, features = ["json", "blocking", "multipart"] }
|
||||
reqwest = { version = "^0.13", default-features = false, features = ["json", "blocking", "multipart", "query", "form"] }
|
||||
|
||||
[features]
|
||||
default = ["native-tls"]
|
||||
native-tls = ["reqwest/native-tls"]
|
||||
rustls-tls = ["reqwest/rustls-tls"]
|
||||
rustls = ["reqwest/rustls"]
|
||||
|
||||
@@ -12,9 +12,9 @@ serde = { version = "^1.0", features = ["derive"] }
|
||||
serde_json = "^1.0"
|
||||
serde_repr = "^0.1"
|
||||
url = "^2.5"
|
||||
reqwest = { version = "^0.12", default-features = false, features = ["json", "multipart"] }
|
||||
reqwest = { version = "^0.13", default-features = false, features = ["json", "multipart", "query", "form"] }
|
||||
|
||||
[features]
|
||||
default = ["native-tls"]
|
||||
native-tls = ["reqwest/native-tls"]
|
||||
rustls-tls = ["reqwest/rustls-tls"]
|
||||
rustls = ["reqwest/rustls"]
|
||||
|
||||
@@ -12,9 +12,9 @@ serde = { version = "^1.0", features = ["derive"] }
|
||||
serde_json = "^1.0"
|
||||
serde_repr = "^0.1"
|
||||
url = "^2.5"
|
||||
reqwest = { version = "^0.12", default-features = false, features = ["json", "blocking", "multipart"] }
|
||||
reqwest = { version = "^0.13", default-features = false, features = ["json", "blocking", "multipart", "query", "form"] }
|
||||
|
||||
[features]
|
||||
default = ["native-tls"]
|
||||
native-tls = ["reqwest/native-tls"]
|
||||
rustls-tls = ["reqwest/rustls-tls"]
|
||||
rustls = ["reqwest/rustls"]
|
||||
|
||||
@@ -12,9 +12,9 @@ serde = { version = "^1.0", features = ["derive"] }
|
||||
serde_json = "^1.0"
|
||||
serde_repr = "^0.1"
|
||||
url = "^2.5"
|
||||
reqwest = { version = "^0.12", default-features = false, features = ["json", "blocking", "multipart"] }
|
||||
reqwest = { version = "^0.13", default-features = false, features = ["json", "blocking", "multipart", "query", "form"] }
|
||||
|
||||
[features]
|
||||
default = ["native-tls"]
|
||||
native-tls = ["reqwest/native-tls"]
|
||||
rustls-tls = ["reqwest/rustls-tls"]
|
||||
rustls = ["reqwest/rustls"]
|
||||
|
||||
@@ -12,7 +12,7 @@ serde = { version = "^1.0", features = ["derive"] }
|
||||
serde_json = "^1.0"
|
||||
serde_repr = "^0.1"
|
||||
url = "^2.5"
|
||||
reqwest = { version = "^0.12", default-features = false, features = ["json", "multipart"] }
|
||||
reqwest = { version = "^0.13", default-features = false, features = ["json", "multipart", "query", "form"] }
|
||||
|
||||
[dev-dependencies]
|
||||
wiremock = "0.6"
|
||||
@@ -21,4 +21,4 @@ tokio = { version = "^1.46.0", features = ["macros", "rt-multi-thread"] }
|
||||
[features]
|
||||
default = ["native-tls"]
|
||||
native-tls = ["reqwest/native-tls"]
|
||||
rustls-tls = ["reqwest/rustls-tls"]
|
||||
rustls = ["reqwest/rustls"]
|
||||
|
||||
@@ -12,9 +12,9 @@ serde = { version = "^1.0", features = ["derive"] }
|
||||
serde_json = "^1.0"
|
||||
serde_repr = "^0.1"
|
||||
url = "^2.5"
|
||||
reqwest = { version = "^0.12", default-features = false, features = ["json", "blocking", "multipart"] }
|
||||
reqwest = { version = "^0.13", default-features = false, features = ["json", "blocking", "multipart", "query", "form"] }
|
||||
|
||||
[features]
|
||||
default = ["native-tls"]
|
||||
native-tls = ["reqwest/native-tls"]
|
||||
rustls-tls = ["reqwest/rustls-tls"]
|
||||
rustls = ["reqwest/rustls"]
|
||||
|
||||
@@ -11,9 +11,9 @@ serde = { version = "^1.0", features = ["derive"] }
|
||||
serde_json = "^1.0"
|
||||
serde_repr = "^0.1"
|
||||
url = "^2.5"
|
||||
reqwest = { version = "^0.12", default-features = false, features = ["json", "blocking", "multipart"] }
|
||||
reqwest = { version = "^0.13", default-features = false, features = ["json", "blocking", "multipart", "query", "form"] }
|
||||
|
||||
[features]
|
||||
default = ["native-tls"]
|
||||
native-tls = ["reqwest/native-tls"]
|
||||
rustls-tls = ["reqwest/rustls-tls"]
|
||||
rustls = ["reqwest/rustls"]
|
||||
|
||||
@@ -12,9 +12,9 @@ serde = { version = "^1.0", features = ["derive"] }
|
||||
serde_json = "^1.0"
|
||||
serde_repr = "^0.1"
|
||||
url = "^2.5"
|
||||
reqwest = { version = "^0.12", default-features = false, features = ["json", "blocking", "multipart"] }
|
||||
reqwest = { version = "^0.13", default-features = false, features = ["json", "blocking", "multipart", "query", "form"] }
|
||||
|
||||
[features]
|
||||
default = ["native-tls"]
|
||||
native-tls = ["reqwest/native-tls"]
|
||||
rustls-tls = ["reqwest/rustls-tls"]
|
||||
rustls = ["reqwest/rustls"]
|
||||
|
||||
@@ -30,7 +30,7 @@ export class TestApi extends runtime.BaseAPI {
|
||||
/**
|
||||
* Creates request options for test without sending the request
|
||||
*/
|
||||
async testRequestOpts(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.RequestOpts> {
|
||||
async testRequestOpts(): Promise<runtime.RequestOpts> {
|
||||
const queryParameters: any = {};
|
||||
|
||||
const headerParameters: runtime.HTTPHeaders = {};
|
||||
@@ -49,8 +49,8 @@ export class TestApi extends runtime.BaseAPI {
|
||||
/**
|
||||
*/
|
||||
async testRaw(initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<runtime.ApiResponse<Array<TestBaseDto>>> {
|
||||
const requestConfig = await this.testRequestConfig(initOverrides);
|
||||
const response = await this.request(requestConfig, initOverrides);
|
||||
const requestOptions = await this.testRequestOpts();
|
||||
const response = await this.request(requestOptions, initOverrides);
|
||||
|
||||
return new runtime.JSONApiResponse(response, (jsonValue) => jsonValue.map(TestBaseDtoFromJSON));
|
||||
}
|
||||
|
||||
@@ -21,7 +21,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -47,7 +51,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -24,7 +24,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -21,6 +21,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -21,7 +21,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -47,7 +51,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -24,7 +24,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -21,6 +21,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -69,7 +69,7 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -21,7 +21,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -47,7 +51,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -24,7 +24,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -21,6 +21,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -66,7 +66,7 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -21,7 +21,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -47,7 +51,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -24,7 +24,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -21,6 +21,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -66,9 +66,9 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IAPIKEYSApi, APIKEYSApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IAPIKeysApi, APIKeysApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IApiKeysApi, ApiKeysApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IAPIKEYSApi, APIKEYSApi>("Org.OpenAPITools.Api.IAPIKEYSApi", client));
|
||||
builders.Add(_services.AddHttpClient<IAPIKeysApi, APIKeysApi>("Org.OpenAPITools.Api.IAPIKeysApi", client));
|
||||
builders.Add(_services.AddHttpClient<IApiKeysApi, ApiKeysApi>("Org.OpenAPITools.Api.IApiKeysApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -22,7 +22,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -74,7 +78,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -25,7 +25,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -22,6 +22,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -21,7 +21,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -47,7 +51,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -24,7 +24,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -21,6 +21,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -21,7 +21,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -47,7 +51,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -24,7 +24,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -21,6 +21,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -67,7 +67,7 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -21,7 +21,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -47,7 +51,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -24,7 +24,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -21,6 +21,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -229,13 +229,13 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IAnotherFakeApi, AnotherFakeApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IFakeApi, FakeApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IFakeClassnameTags123Api, FakeClassnameTags123Api>(client));
|
||||
builders.Add(_services.AddHttpClient<IPetApi, PetApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IStoreApi, StoreApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IUserApi, UserApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IAnotherFakeApi, AnotherFakeApi>("Org.OpenAPITools.Api.IAnotherFakeApi", client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
builders.Add(_services.AddHttpClient<IFakeApi, FakeApi>("Org.OpenAPITools.Api.IFakeApi", client));
|
||||
builders.Add(_services.AddHttpClient<IFakeClassnameTags123Api, FakeClassnameTags123Api>("Org.OpenAPITools.Api.IFakeClassnameTags123Api", client));
|
||||
builders.Add(_services.AddHttpClient<IPetApi, PetApi>("Org.OpenAPITools.Api.IPetApi", client));
|
||||
builders.Add(_services.AddHttpClient<IStoreApi, StoreApi>("Org.OpenAPITools.Api.IStoreApi", client));
|
||||
builders.Add(_services.AddHttpClient<IUserApi, UserApi>("Org.OpenAPITools.Api.IUserApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -19,7 +19,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -71,7 +75,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -22,7 +22,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -19,6 +19,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -181,13 +181,13 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IAnotherFakeApi, AnotherFakeApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IFakeApi, FakeApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IFakeClassnameTags123Api, FakeClassnameTags123Api>(client));
|
||||
builders.Add(_services.AddHttpClient<IPetApi, PetApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IStoreApi, StoreApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IUserApi, UserApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IAnotherFakeApi, AnotherFakeApi>("Org.OpenAPITools.Api.IAnotherFakeApi", client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
builders.Add(_services.AddHttpClient<IFakeApi, FakeApi>("Org.OpenAPITools.Api.IFakeApi", client));
|
||||
builders.Add(_services.AddHttpClient<IFakeClassnameTags123Api, FakeClassnameTags123Api>("Org.OpenAPITools.Api.IFakeClassnameTags123Api", client));
|
||||
builders.Add(_services.AddHttpClient<IPetApi, PetApi>("Org.OpenAPITools.Api.IPetApi", client));
|
||||
builders.Add(_services.AddHttpClient<IStoreApi, StoreApi>("Org.OpenAPITools.Api.IStoreApi", client));
|
||||
builders.Add(_services.AddHttpClient<IUserApi, UserApi>("Org.OpenAPITools.Api.IUserApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -21,7 +21,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -73,7 +77,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -24,7 +24,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -21,6 +21,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -21,7 +21,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -47,7 +51,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -24,7 +24,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -21,6 +21,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -179,13 +179,13 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IAnotherFakeApi, AnotherFakeApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IFakeApi, FakeApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IFakeClassnameTags123Api, FakeClassnameTags123Api>(client));
|
||||
builders.Add(_services.AddHttpClient<IPetApi, PetApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IStoreApi, StoreApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IUserApi, UserApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IAnotherFakeApi, AnotherFakeApi>("Org.OpenAPITools.Api.IAnotherFakeApi", client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
builders.Add(_services.AddHttpClient<IFakeApi, FakeApi>("Org.OpenAPITools.Api.IFakeApi", client));
|
||||
builders.Add(_services.AddHttpClient<IFakeClassnameTags123Api, FakeClassnameTags123Api>("Org.OpenAPITools.Api.IFakeClassnameTags123Api", client));
|
||||
builders.Add(_services.AddHttpClient<IPetApi, PetApi>("Org.OpenAPITools.Api.IPetApi", client));
|
||||
builders.Add(_services.AddHttpClient<IStoreApi, StoreApi>("Org.OpenAPITools.Api.IStoreApi", client));
|
||||
builders.Add(_services.AddHttpClient<IUserApi, UserApi>("Org.OpenAPITools.Api.IUserApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -19,7 +19,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -71,7 +75,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -22,7 +22,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -19,6 +19,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -289,13 +289,13 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IAnotherFakeApi, AnotherFakeApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IFakeApi, FakeApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IFakeClassnameTags123Api, FakeClassnameTags123Api>(client));
|
||||
builders.Add(_services.AddHttpClient<IPetApi, PetApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IStoreApi, StoreApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IUserApi, UserApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IAnotherFakeApi, AnotherFakeApi>("Org.OpenAPITools.Api.IAnotherFakeApi", client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
builders.Add(_services.AddHttpClient<IFakeApi, FakeApi>("Org.OpenAPITools.Api.IFakeApi", client));
|
||||
builders.Add(_services.AddHttpClient<IFakeClassnameTags123Api, FakeClassnameTags123Api>("Org.OpenAPITools.Api.IFakeClassnameTags123Api", client));
|
||||
builders.Add(_services.AddHttpClient<IPetApi, PetApi>("Org.OpenAPITools.Api.IPetApi", client));
|
||||
builders.Add(_services.AddHttpClient<IStoreApi, StoreApi>("Org.OpenAPITools.Api.IStoreApi", client));
|
||||
builders.Add(_services.AddHttpClient<IUserApi, UserApi>("Org.OpenAPITools.Api.IUserApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -21,7 +21,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -73,7 +77,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -24,7 +24,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -21,6 +21,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -21,7 +21,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -47,7 +51,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -24,7 +24,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -21,6 +21,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -19,7 +19,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -45,7 +49,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -22,7 +22,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -19,6 +19,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -19,7 +19,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -45,7 +49,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -22,7 +22,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -19,6 +19,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -19,7 +19,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -45,7 +49,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -22,7 +22,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -19,6 +19,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -227,13 +227,13 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IAnotherFakeApi, AnotherFakeApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IFakeApi, FakeApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IFakeClassnameTags123Api, FakeClassnameTags123Api>(client));
|
||||
builders.Add(_services.AddHttpClient<IPetApi, PetApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IStoreApi, StoreApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IUserApi, UserApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IAnotherFakeApi, AnotherFakeApi>("Org.OpenAPITools.Api.IAnotherFakeApi", client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
builders.Add(_services.AddHttpClient<IFakeApi, FakeApi>("Org.OpenAPITools.Api.IFakeApi", client));
|
||||
builders.Add(_services.AddHttpClient<IFakeClassnameTags123Api, FakeClassnameTags123Api>("Org.OpenAPITools.Api.IFakeClassnameTags123Api", client));
|
||||
builders.Add(_services.AddHttpClient<IPetApi, PetApi>("Org.OpenAPITools.Api.IPetApi", client));
|
||||
builders.Add(_services.AddHttpClient<IStoreApi, StoreApi>("Org.OpenAPITools.Api.IStoreApi", client));
|
||||
builders.Add(_services.AddHttpClient<IUserApi, UserApi>("Org.OpenAPITools.Api.IUserApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -19,7 +19,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -71,7 +75,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -22,7 +22,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -19,6 +19,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -64,7 +64,7 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -19,7 +19,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -45,7 +49,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -22,7 +22,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -19,6 +19,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -177,13 +177,13 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IAnotherFakeApi, AnotherFakeApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IFakeApi, FakeApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IFakeClassnameTags123Api, FakeClassnameTags123Api>(client));
|
||||
builders.Add(_services.AddHttpClient<IPetApi, PetApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IStoreApi, StoreApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IUserApi, UserApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IAnotherFakeApi, AnotherFakeApi>("Org.OpenAPITools.Api.IAnotherFakeApi", client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
builders.Add(_services.AddHttpClient<IFakeApi, FakeApi>("Org.OpenAPITools.Api.IFakeApi", client));
|
||||
builders.Add(_services.AddHttpClient<IFakeClassnameTags123Api, FakeClassnameTags123Api>("Org.OpenAPITools.Api.IFakeClassnameTags123Api", client));
|
||||
builders.Add(_services.AddHttpClient<IPetApi, PetApi>("Org.OpenAPITools.Api.IPetApi", client));
|
||||
builders.Add(_services.AddHttpClient<IStoreApi, StoreApi>("Org.OpenAPITools.Api.IStoreApi", client));
|
||||
builders.Add(_services.AddHttpClient<IUserApi, UserApi>("Org.OpenAPITools.Api.IUserApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -19,7 +19,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -71,7 +75,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -22,7 +22,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -19,6 +19,12 @@ namespace Org.OpenAPITools
|
||||
/// </summary>
|
||||
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
/// <summary>
|
||||
/// Gets a token asynchronously for the specified header.
|
||||
/// </summary>
|
||||
/// <param name="header">The header name to retrieve a token for. Empty string for non-API-key authentication schemes.</param>
|
||||
/// <param name="cancellation">Cancellation token for the asynchronous operation.</param>
|
||||
/// <returns>A task that returns the requested token.</returns>
|
||||
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ namespace Org.OpenAPITools.Client
|
||||
|
||||
List<IHttpClientBuilder> builders = new List<IHttpClientBuilder>();
|
||||
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>(client));
|
||||
builders.Add(_services.AddHttpClient<IDefaultApi, DefaultApi>("Org.OpenAPITools.Api.IDefaultApi", client));
|
||||
|
||||
if (builder != null)
|
||||
foreach (IHttpClientBuilder instance in builders)
|
||||
|
||||
@@ -19,7 +19,11 @@ namespace Org.OpenAPITools.Client
|
||||
/// <typeparam name="TTokenBase"></typeparam>
|
||||
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
|
||||
{
|
||||
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
/// <summary>
|
||||
/// Dictionary mapping header names to channels of available tokens for rate limiting.
|
||||
/// Each channel buffers tokens that have become available and are ready for use.
|
||||
/// </summary>
|
||||
protected internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>>();
|
||||
|
||||
/// <summary>
|
||||
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
|
||||
@@ -45,7 +49,7 @@ namespace Org.OpenAPITools.Client
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
|
||||
{
|
||||
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
|
||||
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
|
||||
|
||||
@@ -22,7 +22,16 @@ namespace Org.OpenAPITools.Client
|
||||
private readonly System.Timers.Timer _timer = new System.Timers.Timer();
|
||||
|
||||
internal TimeSpan? Timeout { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Delegate for token availability notification events.
|
||||
/// </summary>
|
||||
/// <param name="sender">The token that became available.</param>
|
||||
public delegate void TokenBecameAvailableEventHandler(object sender);
|
||||
|
||||
/// <summary>
|
||||
/// Event raised when a rate-limited token becomes available for use.
|
||||
/// </summary>
|
||||
public event TokenBecameAvailableEventHandler TokenBecameAvailable;
|
||||
|
||||
/// <summary>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user