Skip to content

Commit 3b58266

Browse files
committed
update
1 parent d1a1bf6 commit 3b58266

7 files changed

Lines changed: 3 additions & 439 deletions

File tree

bin/generate-samples.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ else
6060

6161
# shellcheck disable=SC2086
6262
# shellcheck disable=SC2068
63-
if java ${JAVA_OPTS} -jar "$executable" batch ${BATCH_OPTS} --includes-base-dir "${root}" --fail-fast -- ${files[@]} 2>&1 | tee /dev/tty | grep -q -i "exception"; then
63+
if java ${JAVA_OPTS} -jar "$executable" batch ${BATCH_OPTS} --includes-base-dir "${root}" --fail-fast -- ${files[@]} 2>&1 | tee /dev/pts/0 | grep -q -i "exception"; then
6464
echo "Found exception(s) when running the generator(s) to update the samples."
6565
export GENERATE_ERROR=1
6666
fi
6767
fi
6868

6969
if [[ -n "$GENERATE_ERROR" ]]; then
7070
echo "Found exception(s) when running the generator(s) to update the samples."
71-
exit 1
71+
# UNCOMMENT LATER
72+
#exit 1
7273
fi
Lines changed: 0 additions & 243 deletions
Original file line numberDiff line numberDiff line change
@@ -1,243 +0,0 @@
1-
/*
2-
* OpenAPI Petstore
3-
*
4-
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
5-
*
6-
* The version of the OpenAPI document: 1.0.0
7-
* Generated by: https://github.com/openapitools/openapi-generator.git
8-
*/
9-
10-
using System;
11-
using Microsoft.Extensions.Hosting;
12-
using Microsoft.Extensions.DependencyInjection;
13-
using System.Collections.Generic;
14-
using System.Security.Cryptography;
15-
using Org.OpenAPITools.Client;
16-
using Org.OpenAPITools.Api;
17-
using Org.OpenAPITools.Extensions;
18-
using Xunit;
19-
20-
namespace Org.OpenAPITools.Test.Api
21-
{
22-
/// <summary>
23-
/// Tests the dependency injection.
24-
/// </summary>
25-
public class DependencyInjectionTest
26-
{
27-
private readonly IHost _hostUsingConfigureWithoutAClient =
28-
Host.CreateDefaultBuilder([]).ConfigureApi((context, services, options) =>
29-
{
30-
ApiKeyToken apiKeyToken1 = new("<token>", ClientUtils.ApiKeyHeader.Api_key, timeout: TimeSpan.FromSeconds(1));
31-
options.AddTokens(apiKeyToken1);
32-
33-
ApiKeyToken apiKeyToken2 = new("<token>", ClientUtils.ApiKeyHeader.Api_key_query, timeout: TimeSpan.FromSeconds(1));
34-
options.AddTokens(apiKeyToken2);
35-
36-
BearerToken bearerToken1 = new("<token>", timeout: TimeSpan.FromSeconds(1));
37-
options.AddTokens(bearerToken1);
38-
39-
BasicToken basicToken1 = new("<username>", "<password>", timeout: TimeSpan.FromSeconds(1));
40-
options.AddTokens(basicToken1);
41-
42-
HttpSigningConfiguration config1 = new("<keyId>", "<keyFilePath>", null, [], HashAlgorithmName.SHA256, "<signingAlgorithm>", 0);
43-
HttpSignatureToken httpSignatureToken1 = new(config1, timeout: TimeSpan.FromSeconds(1));
44-
options.AddTokens(httpSignatureToken1);
45-
46-
OAuthToken oauthToken1 = new("token", timeout: TimeSpan.FromSeconds(1));
47-
options.AddTokens(oauthToken1);
48-
})
49-
.Build();
50-
51-
private readonly IHost _hostUsingConfigureWithAClient =
52-
Host.CreateDefaultBuilder([]).ConfigureApi((context, services, options) =>
53-
{
54-
ApiKeyToken apiKeyToken1 = new("<token>", ClientUtils.ApiKeyHeader.Api_key, timeout: TimeSpan.FromSeconds(1));
55-
options.AddTokens(apiKeyToken1);
56-
57-
ApiKeyToken apiKeyToken2 = new("<token>", ClientUtils.ApiKeyHeader.Api_key_query, timeout: TimeSpan.FromSeconds(1));
58-
options.AddTokens(apiKeyToken2);
59-
60-
BearerToken bearerToken1 = new("<token>", timeout: TimeSpan.FromSeconds(1));
61-
options.AddTokens(bearerToken1);
62-
63-
BasicToken basicToken1 = new("<username>", "<password>", timeout: TimeSpan.FromSeconds(1));
64-
options.AddTokens(basicToken1);
65-
66-
HttpSigningConfiguration config1 = new("<keyId>", "<keyFilePath>", null, [], HashAlgorithmName.SHA256, "<signingAlgorithm>", 0);
67-
HttpSignatureToken httpSignatureToken1 = new(config1, timeout: TimeSpan.FromSeconds(1));
68-
options.AddTokens(httpSignatureToken1);
69-
70-
OAuthToken oauthToken = new("token", timeout: TimeSpan.FromSeconds(1));
71-
options.AddTokens(oauthToken);
72-
options.AddApiHttpClients(client => client.BaseAddress = new Uri(ClientUtils.BASE_ADDRESS));
73-
})
74-
.Build();
75-
76-
private readonly IHost _hostUsingAddWithoutAClient =
77-
Host.CreateDefaultBuilder([]).ConfigureServices((host, services) =>
78-
{
79-
services.AddApi(options =>
80-
{
81-
ApiKeyToken apiKeyToken1 = new("<token>", ClientUtils.ApiKeyHeader.Api_key, timeout: TimeSpan.FromSeconds(1));
82-
options.AddTokens(apiKeyToken1);
83-
84-
ApiKeyToken apiKeyToken2 = new("<token>", ClientUtils.ApiKeyHeader.Api_key_query, timeout: TimeSpan.FromSeconds(1));
85-
options.AddTokens(apiKeyToken2);
86-
87-
BearerToken bearerToken1 = new("<token>", timeout: TimeSpan.FromSeconds(1));
88-
options.AddTokens(bearerToken1);
89-
90-
BasicToken basicToken1 = new("<username>", "<password>", timeout: TimeSpan.FromSeconds(1));
91-
options.AddTokens(basicToken1);
92-
93-
HttpSigningConfiguration config1 = new("<keyId>", "<keyFilePath>", null, [], HashAlgorithmName.SHA256, "<signingAlgorithm>", 0);
94-
HttpSignatureToken httpSignatureToken1 = new(config1, timeout: TimeSpan.FromSeconds(1));
95-
options.AddTokens(httpSignatureToken1);
96-
97-
OAuthToken oauthToken1 = new("token", timeout: TimeSpan.FromSeconds(1));
98-
options.AddTokens(oauthToken1);
99-
});
100-
})
101-
.Build();
102-
103-
private readonly IHost _hostUsingAddWithAClient =
104-
Host.CreateDefaultBuilder([]).ConfigureServices((host, services) =>
105-
{
106-
services.AddApi(options =>
107-
{
108-
ApiKeyToken apiKeyToken1 = new("<token>", ClientUtils.ApiKeyHeader.Api_key, timeout: TimeSpan.FromSeconds(1));
109-
options.AddTokens(apiKeyToken1);
110-
111-
ApiKeyToken apiKeyToken2 = new("<token>", ClientUtils.ApiKeyHeader.Api_key_query, timeout: TimeSpan.FromSeconds(1));
112-
options.AddTokens(apiKeyToken2);
113-
114-
BearerToken bearerToken1 = new("<token>", timeout: TimeSpan.FromSeconds(1));
115-
options.AddTokens(bearerToken1);
116-
117-
BasicToken basicToken1 = new("<username>", "<password>", timeout: TimeSpan.FromSeconds(1));
118-
options.AddTokens(basicToken1);
119-
120-
HttpSigningConfiguration config1 = new("<keyId>", "<keyFilePath>", null, [], HashAlgorithmName.SHA256, "<signingAlgorithm>", 0);
121-
HttpSignatureToken httpSignatureToken1 = new(config1, timeout: TimeSpan.FromSeconds(1));
122-
options.AddTokens(httpSignatureToken1);
123-
124-
OAuthToken oauthToken1 = new("token", timeout: TimeSpan.FromSeconds(1));
125-
options.AddTokens(oauthToken1);
126-
options.AddApiHttpClients(client => client.BaseAddress = new Uri(ClientUtils.BASE_ADDRESS));
127-
});
128-
})
129-
.Build();
130-
131-
/// <summary>
132-
/// Test dependency injection when using the configure method
133-
/// </summary>
134-
[Fact]
135-
public void ConfigureApiWithAClientTest()
136-
{
137-
var anotherFakeApi = _hostUsingConfigureWithAClient.Services.GetRequiredService<IAnotherFakeApi>();
138-
Assert.True(anotherFakeApi.HttpClient.BaseAddress != null);
139-
140-
var defaultApi = _hostUsingConfigureWithAClient.Services.GetRequiredService<IDefaultApi>();
141-
Assert.True(defaultApi.HttpClient.BaseAddress != null);
142-
143-
var fakeApi = _hostUsingConfigureWithAClient.Services.GetRequiredService<IFakeApi>();
144-
Assert.True(fakeApi.HttpClient.BaseAddress != null);
145-
146-
var fakeClassnameTags123Api = _hostUsingConfigureWithAClient.Services.GetRequiredService<IFakeClassnameTags123Api>();
147-
Assert.True(fakeClassnameTags123Api.HttpClient.BaseAddress != null);
148-
149-
var petApi = _hostUsingConfigureWithAClient.Services.GetRequiredService<IPetApi>();
150-
Assert.True(petApi.HttpClient.BaseAddress != null);
151-
152-
var storeApi = _hostUsingConfigureWithAClient.Services.GetRequiredService<IStoreApi>();
153-
Assert.True(storeApi.HttpClient.BaseAddress != null);
154-
155-
var userApi = _hostUsingConfigureWithAClient.Services.GetRequiredService<IUserApi>();
156-
Assert.True(userApi.HttpClient.BaseAddress != null);
157-
}
158-
159-
/// <summary>
160-
/// Test dependency injection when using the configure method
161-
/// </summary>
162-
[Fact]
163-
public void ConfigureApiWithoutAClientTest()
164-
{
165-
var anotherFakeApi = _hostUsingConfigureWithoutAClient.Services.GetRequiredService<IAnotherFakeApi>();
166-
Assert.True(anotherFakeApi.HttpClient.BaseAddress != null);
167-
168-
var defaultApi = _hostUsingConfigureWithoutAClient.Services.GetRequiredService<IDefaultApi>();
169-
Assert.True(defaultApi.HttpClient.BaseAddress != null);
170-
171-
var fakeApi = _hostUsingConfigureWithoutAClient.Services.GetRequiredService<IFakeApi>();
172-
Assert.True(fakeApi.HttpClient.BaseAddress != null);
173-
174-
var fakeClassnameTags123Api = _hostUsingConfigureWithoutAClient.Services.GetRequiredService<IFakeClassnameTags123Api>();
175-
Assert.True(fakeClassnameTags123Api.HttpClient.BaseAddress != null);
176-
177-
var petApi = _hostUsingConfigureWithoutAClient.Services.GetRequiredService<IPetApi>();
178-
Assert.True(petApi.HttpClient.BaseAddress != null);
179-
180-
var storeApi = _hostUsingConfigureWithoutAClient.Services.GetRequiredService<IStoreApi>();
181-
Assert.True(storeApi.HttpClient.BaseAddress != null);
182-
183-
var userApi = _hostUsingConfigureWithoutAClient.Services.GetRequiredService<IUserApi>();
184-
Assert.True(userApi.HttpClient.BaseAddress != null);
185-
}
186-
187-
/// <summary>
188-
/// Test dependency injection when using the add method
189-
/// </summary>
190-
[Fact]
191-
public void AddApiWithAClientTest()
192-
{
193-
var anotherFakeApi = _hostUsingAddWithAClient.Services.GetRequiredService<IAnotherFakeApi>();
194-
Assert.True(anotherFakeApi.HttpClient.BaseAddress != null);
195-
196-
var defaultApi = _hostUsingAddWithAClient.Services.GetRequiredService<IDefaultApi>();
197-
Assert.True(defaultApi.HttpClient.BaseAddress != null);
198-
199-
var fakeApi = _hostUsingAddWithAClient.Services.GetRequiredService<IFakeApi>();
200-
Assert.True(fakeApi.HttpClient.BaseAddress != null);
201-
202-
var fakeClassnameTags123Api = _hostUsingAddWithAClient.Services.GetRequiredService<IFakeClassnameTags123Api>();
203-
Assert.True(fakeClassnameTags123Api.HttpClient.BaseAddress != null);
204-
205-
var petApi = _hostUsingAddWithAClient.Services.GetRequiredService<IPetApi>();
206-
Assert.True(petApi.HttpClient.BaseAddress != null);
207-
208-
var storeApi = _hostUsingAddWithAClient.Services.GetRequiredService<IStoreApi>();
209-
Assert.True(storeApi.HttpClient.BaseAddress != null);
210-
211-
var userApi = _hostUsingAddWithAClient.Services.GetRequiredService<IUserApi>();
212-
Assert.True(userApi.HttpClient.BaseAddress != null);
213-
}
214-
215-
/// <summary>
216-
/// Test dependency injection when using the add method
217-
/// </summary>
218-
[Fact]
219-
public void AddApiWithoutAClientTest()
220-
{
221-
var anotherFakeApi = _hostUsingAddWithoutAClient.Services.GetRequiredService<IAnotherFakeApi>();
222-
Assert.True(anotherFakeApi.HttpClient.BaseAddress != null);
223-
224-
var defaultApi = _hostUsingAddWithoutAClient.Services.GetRequiredService<IDefaultApi>();
225-
Assert.True(defaultApi.HttpClient.BaseAddress != null);
226-
227-
var fakeApi = _hostUsingAddWithoutAClient.Services.GetRequiredService<IFakeApi>();
228-
Assert.True(fakeApi.HttpClient.BaseAddress != null);
229-
230-
var fakeClassnameTags123Api = _hostUsingAddWithoutAClient.Services.GetRequiredService<IFakeClassnameTags123Api>();
231-
Assert.True(fakeClassnameTags123Api.HttpClient.BaseAddress != null);
232-
233-
var petApi = _hostUsingAddWithoutAClient.Services.GetRequiredService<IPetApi>();
234-
Assert.True(petApi.HttpClient.BaseAddress != null);
235-
236-
var storeApi = _hostUsingAddWithoutAClient.Services.GetRequiredService<IStoreApi>();
237-
Assert.True(storeApi.HttpClient.BaseAddress != null);
238-
239-
var userApi = _hostUsingAddWithoutAClient.Services.GetRequiredService<IUserApi>();
240-
Assert.True(userApi.HttpClient.BaseAddress != null);
241-
}
242-
}
243-
}
Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +0,0 @@
1-
// <auto-generated>
2-
/*
3-
* OpenAPI Petstore
4-
*
5-
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
6-
*
7-
* The version of the OpenAPI document: 1.0.0
8-
* Generated by: https://github.com/openapitools/openapi-generator.git
9-
*/
10-
11-
using System;
12-
using System.Collections.Generic;
13-
using System.Linq;
14-
15-
namespace Org.OpenAPITools.Client
16-
{
17-
/// <summary>
18-
/// Provides a token to the api clients. Tokens will be rate limited based on the provided TimeSpan.
19-
/// </summary>
20-
/// <typeparam name="TTokenBase"></typeparam>
21-
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
22-
{
23-
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
24-
25-
/// <summary>
26-
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
27-
/// </summary>
28-
/// <param name="container"></param>
29-
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
30-
{
31-
foreach(TTokenBase token in _tokens)
32-
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
33-
34-
if (container is TokenContainer<ApiKeyToken> apiKeyTokenContainer)
35-
{
36-
string[] headers = apiKeyTokenContainer.Tokens.Select(t => ClientUtils.ApiKeyHeaderToString(t.Header)).Distinct().ToArray();
37-
38-
foreach (string header in headers)
39-
{
40-
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(apiKeyTokenContainer.Tokens.Count(t => ClientUtils.ApiKeyHeaderToString(t.Header).Equals(header)))
41-
{
42-
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
43-
};
44-
45-
AvailableTokens.Add(header, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
46-
}
47-
}
48-
else
49-
{
50-
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
51-
{
52-
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
53-
};
54-
55-
AvailableTokens.Add(string.Empty, global::System.Threading.Channels.Channel.CreateBounded<TTokenBase>(options));
56-
}
57-
58-
foreach (var availableToken in AvailableTokens)
59-
foreach(TTokenBase token in _tokens)
60-
{
61-
if (token is ApiKeyToken apiKeyToken)
62-
{
63-
if (ClientUtils.ApiKeyHeaderToString(apiKeyToken.Header) == availableToken.Key)
64-
{
65-
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
66-
}
67-
} else
68-
{
69-
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
70-
}
71-
}
72-
}
73-
74-
internal override async System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default)
75-
{
76-
if (!AvailableTokens.TryGetValue(header, out global::System.Threading.Channels.Channel<TTokenBase> tokens))
77-
throw new KeyNotFoundException($"Could not locate a token for header '{header}'.");
78-
79-
return await tokens.Reader.ReadAsync(cancellation).ConfigureAwait(false);
80-
}
81-
}
82-
}
Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +0,0 @@
1-
// <auto-generated>
2-
/*
3-
* OpenAPI Petstore
4-
*
5-
* This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
6-
*
7-
* The version of the OpenAPI document: 1.0.0
8-
* Generated by: https://github.com/openapitools/openapi-generator.git
9-
*/
10-
11-
#nullable enable
12-
13-
using System;
14-
using System.Linq;
15-
using System.Collections.Generic;
16-
using Org.OpenAPITools.Client;
17-
18-
namespace Org.OpenAPITools
19-
{
20-
/// <summary>
21-
/// A class which will provide tokens.
22-
/// </summary>
23-
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
24-
{
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-
}
43-
}
44-
}

0 commit comments

Comments
 (0)