Skip to content

Commit 9acccba

Browse files
committed
[csharp] public TokenProvider to make it implementable from consumer projects
1 parent 4f9f14a commit 9acccba

File tree

78 files changed

+273
-1014
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+273
-1014
lines changed

modules/openapi-generator/src/main/resources/csharp/libraries/generichost/RateLimitProvider`1.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ namespace {{packageName}}.{{clientPackage}}
2323
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
2424
/// </summary>
2525
/// <param name="container"></param>
26-
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
26+
public RateLimitProvider(TokenContainer<TTokenBase> container)
2727
{
28-
foreach(TTokenBase token in _tokens)
28+
foreach(TTokenBase token in container.Tokens)
2929
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
3030
3131
{{#lambda.copy}}
32-
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
32+
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
3333
{
3434
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
3535
};
@@ -65,7 +65,7 @@ namespace {{packageName}}.{{clientPackage}}
6565
{{/hasApiKeyMethods}}
6666

6767
foreach (var availableToken in AvailableTokens)
68-
foreach(TTokenBase token in _tokens)
68+
foreach(TTokenBase token in container.Tokens)
6969
{
7070
{{#hasApiKeyMethods}}
7171
if (token is ApiKeyToken apiKeyToken)
@@ -85,7 +85,7 @@ namespace {{packageName}}.{{clientPackage}}
8585
}
8686
}
8787

88-
internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}})
88+
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}})
8989
{
9090
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>{{nrt?}} tokens))
9191
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");

modules/openapi-generator/src/main/resources/csharp/libraries/generichost/TokenProvider`1.mustache

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
{{/nrt}}
88
using System;
9-
using System.Linq;
10-
using System.Collections.Generic;
119
using {{packageName}}.{{clientPackage}};
1210

1311
namespace {{packageName}}
@@ -17,23 +15,6 @@ namespace {{packageName}}
1715
/// </summary>
1816
{{>visibility}} abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
1917
{
20-
/// <summary>
21-
/// The array of tokens.
22-
/// </summary>
23-
protected TTokenBase[] _tokens;
24-
25-
internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}});
26-
27-
/// <summary>
28-
/// Instantiates a TokenProvider.
29-
/// </summary>
30-
/// <param name="tokens"></param>
31-
public TokenProvider(IEnumerable<TTokenBase> tokens)
32-
{
33-
_tokens = tokens.ToArray();
34-
35-
if (_tokens.Length == 0)
36-
throw new ArgumentException("You did not provide any tokens.");
37-
}
18+
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}});
3819
}
39-
}
20+
}

samples/client/petstore/csharp/generichost/latest/ComposedEnum/src/Org.OpenAPITools/Client/RateLimitProvider`1.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,26 @@ public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTo
2828
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
2929
/// </summary>
3030
/// <param name="container"></param>
31-
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
31+
public RateLimitProvider(TokenContainer<TTokenBase> container)
3232
{
33-
foreach(TTokenBase token in _tokens)
33+
foreach(TTokenBase token in container.Tokens)
3434
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
3535

36-
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
36+
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
3737
{
3838
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
3939
};
4040

4141
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
4242

4343
foreach (var availableToken in AvailableTokens)
44-
foreach(TTokenBase token in _tokens)
44+
foreach(TTokenBase token in container.Tokens)
4545
{
4646
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
4747
}
4848
}
4949

50-
internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
50+
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
5151
{
5252
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
5353
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");

samples/client/petstore/csharp/generichost/latest/ComposedEnum/src/Org.OpenAPITools/Client/TokenProvider`1.cs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#nullable enable
1212

1313
using System;
14-
using System.Linq;
15-
using System.Collections.Generic;
1614
using Org.OpenAPITools.Client;
1715

1816
namespace Org.OpenAPITools
@@ -22,23 +20,6 @@ namespace Org.OpenAPITools
2220
/// </summary>
2321
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
2422
{
25-
/// <summary>
26-
/// The array of tokens.
27-
/// </summary>
28-
protected TTokenBase[] _tokens;
29-
30-
internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
31-
32-
/// <summary>
33-
/// Instantiates a TokenProvider.
34-
/// </summary>
35-
/// <param name="tokens"></param>
36-
public TokenProvider(IEnumerable<TTokenBase> tokens)
37-
{
38-
_tokens = tokens.ToArray();
39-
40-
if (_tokens.Length == 0)
41-
throw new ArgumentException("You did not provide any tokens.");
42-
}
23+
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
4324
}
44-
}
25+
}

samples/client/petstore/csharp/generichost/latest/HelloWorld/src/Org.OpenAPITools/Client/RateLimitProvider`1.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,26 @@ public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTo
2828
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
2929
/// </summary>
3030
/// <param name="container"></param>
31-
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
31+
public RateLimitProvider(TokenContainer<TTokenBase> container)
3232
{
33-
foreach(TTokenBase token in _tokens)
33+
foreach(TTokenBase token in container.Tokens)
3434
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
3535

36-
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
36+
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
3737
{
3838
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
3939
};
4040

4141
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
4242

4343
foreach (var availableToken in AvailableTokens)
44-
foreach(TTokenBase token in _tokens)
44+
foreach(TTokenBase token in container.Tokens)
4545
{
4646
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
4747
}
4848
}
4949

50-
internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
50+
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
5151
{
5252
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
5353
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");

samples/client/petstore/csharp/generichost/latest/HelloWorld/src/Org.OpenAPITools/Client/TokenProvider`1.cs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#nullable enable
1212

1313
using System;
14-
using System.Linq;
15-
using System.Collections.Generic;
1614
using Org.OpenAPITools.Client;
1715

1816
namespace Org.OpenAPITools
@@ -22,23 +20,6 @@ namespace Org.OpenAPITools
2220
/// </summary>
2321
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
2422
{
25-
/// <summary>
26-
/// The array of tokens.
27-
/// </summary>
28-
protected TTokenBase[] _tokens;
29-
30-
internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
31-
32-
/// <summary>
33-
/// Instantiates a TokenProvider.
34-
/// </summary>
35-
/// <param name="tokens"></param>
36-
public TokenProvider(IEnumerable<TTokenBase> tokens)
37-
{
38-
_tokens = tokens.ToArray();
39-
40-
if (_tokens.Length == 0)
41-
throw new ArgumentException("You did not provide any tokens.");
42-
}
23+
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
4324
}
44-
}
25+
}

samples/client/petstore/csharp/generichost/latest/InlineEnumAnyOf/src/Org.OpenAPITools/Client/RateLimitProvider`1.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,26 @@ public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTo
2828
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
2929
/// </summary>
3030
/// <param name="container"></param>
31-
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
31+
public RateLimitProvider(TokenContainer<TTokenBase> container)
3232
{
33-
foreach(TTokenBase token in _tokens)
33+
foreach(TTokenBase token in container.Tokens)
3434
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
3535

36-
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
36+
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
3737
{
3838
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
3939
};
4040

4141
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
4242

4343
foreach (var availableToken in AvailableTokens)
44-
foreach(TTokenBase token in _tokens)
44+
foreach(TTokenBase token in container.Tokens)
4545
{
4646
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
4747
}
4848
}
4949

50-
internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
50+
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
5151
{
5252
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
5353
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");

samples/client/petstore/csharp/generichost/latest/InlineEnumAnyOf/src/Org.OpenAPITools/Client/TokenProvider`1.cs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#nullable enable
1212

1313
using System;
14-
using System.Linq;
15-
using System.Collections.Generic;
1614
using Org.OpenAPITools.Client;
1715

1816
namespace Org.OpenAPITools
@@ -22,23 +20,6 @@ namespace Org.OpenAPITools
2220
/// </summary>
2321
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
2422
{
25-
/// <summary>
26-
/// The array of tokens.
27-
/// </summary>
28-
protected TTokenBase[] _tokens;
29-
30-
internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
31-
32-
/// <summary>
33-
/// Instantiates a TokenProvider.
34-
/// </summary>
35-
/// <param name="tokens"></param>
36-
public TokenProvider(IEnumerable<TTokenBase> tokens)
37-
{
38-
_tokens = tokens.ToArray();
39-
40-
if (_tokens.Length == 0)
41-
throw new ArgumentException("You did not provide any tokens.");
42-
}
23+
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
4324
}
44-
}
25+
}

samples/client/petstore/csharp/generichost/latest/OneOfList/src/Org.OpenAPITools/Client/RateLimitProvider`1.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,26 @@ public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTo
2828
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
2929
/// </summary>
3030
/// <param name="container"></param>
31-
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
31+
public RateLimitProvider(TokenContainer<TTokenBase> container)
3232
{
33-
foreach(TTokenBase token in _tokens)
33+
foreach(TTokenBase token in container.Tokens)
3434
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
3535

36-
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
36+
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
3737
{
3838
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
3939
};
4040

4141
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
4242

4343
foreach (var availableToken in AvailableTokens)
44-
foreach(TTokenBase token in _tokens)
44+
foreach(TTokenBase token in container.Tokens)
4545
{
4646
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
4747
}
4848
}
4949

50-
internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
50+
public override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
5151
{
5252
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
5353
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");

samples/client/petstore/csharp/generichost/latest/OneOfList/src/Org.OpenAPITools/Client/TokenProvider`1.cs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
#nullable enable
1212

1313
using System;
14-
using System.Linq;
15-
using System.Collections.Generic;
1614
using Org.OpenAPITools.Client;
1715

1816
namespace Org.OpenAPITools
@@ -22,23 +20,6 @@ namespace Org.OpenAPITools
2220
/// </summary>
2321
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
2422
{
25-
/// <summary>
26-
/// The array of tokens.
27-
/// </summary>
28-
protected TTokenBase[] _tokens;
29-
30-
internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
31-
32-
/// <summary>
33-
/// Instantiates a TokenProvider.
34-
/// </summary>
35-
/// <param name="tokens"></param>
36-
public TokenProvider(IEnumerable<TTokenBase> tokens)
37-
{
38-
_tokens = tokens.ToArray();
39-
40-
if (_tokens.Length == 0)
41-
throw new ArgumentException("You did not provide any tokens.");
42-
}
23+
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
4324
}
44-
}
25+
}

0 commit comments

Comments
 (0)