Skip to content

Commit 17f2e46

Browse files
[REQ][CSHARP] Make TokenProvider abstract method GetAsync protected for override (#22615)
* Make GetAsync protected internal so external inheritors can override it * Remove non-zero token length requirement to allow more flexibility for token providers * Update samples
1 parent b3c4c49 commit 17f2e46

File tree

96 files changed

+384
-240
lines changed

Some content is hidden

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

96 files changed

+384
-240
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ 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+
/// <inheritdoc/>
89+
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}})
8990
{
9091
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>{{nrt?}} tokens))
9192
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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ namespace {{packageName}}
2222
/// </summary>
2323
protected TTokenBase[] _tokens;
2424
25-
internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}});
25+
/// <summary>
26+
/// Gets an authentication token to be used in request authorization.
27+
/// </summary>
28+
/// <param name="header"></param>
29+
/// <param name="cancellation"></param>
30+
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default{{^netstandard20OrLater}}(global::System.Threading.CancellationToken){{/netstandard20OrLater}});
2631

2732
/// <summary>
2833
/// Instantiates a TokenProvider.
@@ -31,9 +36,6 @@ namespace {{packageName}}
3136
public TokenProvider(IEnumerable<TTokenBase> tokens)
3237
{
3338
_tokens = tokens.ToArray();
34-
35-
if (_tokens.Length == 0)
36-
throw new ArgumentException("You did not provide any tokens.");
3739
}
3840
}
3941
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.
4747
}
4848
}
4949

50-
internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
50+
/// <inheritdoc/>
51+
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
5152
{
5253
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
5354
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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
2727
/// </summary>
2828
protected TTokenBase[] _tokens;
2929

30-
internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
30+
/// <summary>
31+
/// Gets an authentication token to be used in request authorization.
32+
/// </summary>
33+
/// <param name="header"></param>
34+
/// <param name="cancellation"></param>
35+
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
3136

3237
/// <summary>
3338
/// Instantiates a TokenProvider.
@@ -36,9 +41,6 @@ public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
3641
public TokenProvider(IEnumerable<TTokenBase> tokens)
3742
{
3843
_tokens = tokens.ToArray();
39-
40-
if (_tokens.Length == 0)
41-
throw new ArgumentException("You did not provide any tokens.");
4244
}
4345
}
4446
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.
4747
}
4848
}
4949

50-
internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
50+
/// <inheritdoc/>
51+
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
5152
{
5253
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
5354
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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
2727
/// </summary>
2828
protected TTokenBase[] _tokens;
2929

30-
internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
30+
/// <summary>
31+
/// Gets an authentication token to be used in request authorization.
32+
/// </summary>
33+
/// <param name="header"></param>
34+
/// <param name="cancellation"></param>
35+
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
3136

3237
/// <summary>
3338
/// Instantiates a TokenProvider.
@@ -36,9 +41,6 @@ public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
3641
public TokenProvider(IEnumerable<TTokenBase> tokens)
3742
{
3843
_tokens = tokens.ToArray();
39-
40-
if (_tokens.Length == 0)
41-
throw new ArgumentException("You did not provide any tokens.");
4244
}
4345
}
4446
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.
4747
}
4848
}
4949

50-
internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
50+
/// <inheritdoc/>
51+
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
5152
{
5253
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
5354
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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
2727
/// </summary>
2828
protected TTokenBase[] _tokens;
2929

30-
internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
30+
/// <summary>
31+
/// Gets an authentication token to be used in request authorization.
32+
/// </summary>
33+
/// <param name="header"></param>
34+
/// <param name="cancellation"></param>
35+
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
3136

3237
/// <summary>
3338
/// Instantiates a TokenProvider.
@@ -36,9 +41,6 @@ public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
3641
public TokenProvider(IEnumerable<TTokenBase> tokens)
3742
{
3843
_tokens = tokens.ToArray();
39-
40-
if (_tokens.Length == 0)
41-
throw new ArgumentException("You did not provide any tokens.");
4244
}
4345
}
4446
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.
4747
}
4848
}
4949

50-
internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
50+
/// <inheritdoc/>
51+
protected internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
5152
{
5253
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase>? tokens))
5354
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: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
2727
/// </summary>
2828
protected TTokenBase[] _tokens;
2929

30-
internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
30+
/// <summary>
31+
/// Gets an authentication token to be used in request authorization.
32+
/// </summary>
33+
/// <param name="header"></param>
34+
/// <param name="cancellation"></param>
35+
protected internal abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
3136

3237
/// <summary>
3338
/// Instantiates a TokenProvider.
@@ -36,9 +41,6 @@ public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
3641
public TokenProvider(IEnumerable<TTokenBase> tokens)
3742
{
3843
_tokens = tokens.ToArray();
39-
40-
if (_tokens.Length == 0)
41-
throw new ArgumentException("You did not provide any tokens.");
4244
}
4345
}
4446
}

0 commit comments

Comments
 (0)