Skip to content

Commit fa75fef

Browse files
committed
Update documentation and samples
1 parent 0bfc7f8 commit fa75fef

File tree

425 files changed

+3617
-2490
lines changed

Some content is hidden

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

425 files changed

+3617
-2490
lines changed

samples/client/petstore/csharp/generichost/latest/ComposedEnum/src/Org.OpenAPITools/Client/ApiException.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@
77
* The version of the OpenAPI document: 0.0.1
88
* Generated by: https://github.com/openapitools/openapi-generator.git
99
*/
10-
1110
#nullable enable
1211

1312
using System;
13+
using System.IO;
1414

1515
namespace Org.OpenAPITools.Client
1616
{
@@ -33,20 +33,27 @@ public class ApiException : Exception
3333
/// The raw data returned by the api
3434
/// </summary>
3535
public string RawContent { get; }
36+
37+
/// <summary>
38+
/// The HttpResponseMessage object
39+
/// </summary>
40+
public System.Net.Http.HttpResponseMessage? RawResponse { get; }
3641

3742
/// <summary>
3843
/// Construct the ApiException from parts of the response
3944
/// </summary>
4045
/// <param name="reasonPhrase"></param>
4146
/// <param name="statusCode"></param>
4247
/// <param name="rawContent"></param>
43-
public ApiException(string? reasonPhrase, System.Net.HttpStatusCode statusCode, string rawContent) : base(reasonPhrase ?? rawContent)
48+
public ApiException(string? reasonPhrase, System.Net.HttpStatusCode statusCode, string rawContent, System.Net.Http.HttpResponseMessage? rawResponse = null) : base(reasonPhrase ?? rawContent)
4449
{
4550
ReasonPhrase = reasonPhrase;
4651

4752
StatusCode = statusCode;
4853

4954
RawContent = rawContent;
55+
56+
RawResponse = rawResponse;
5057
}
5158
}
5259
}

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ public partial interface IApiResponse
5252
/// </summary>
5353
System.Net.Http.Headers.HttpResponseHeaders Headers { get; }
5454

55+
/// <summary>
56+
/// The headers contained in the api response related to the content
57+
/// </summary>
58+
System.Net.Http.Headers.HttpContentHeaders ContentHeaders { get; }
59+
5560
/// <summary>
5661
/// The path used when making the request.
5762
/// </summary>
@@ -109,6 +114,11 @@ public partial class ApiResponse : IApiResponse
109114
/// </summary>
110115
public System.Net.Http.Headers.HttpResponseHeaders Headers { get; }
111116

117+
/// <summary>
118+
/// The headers contained in the api response related to the content
119+
/// </summary>
120+
public System.Net.Http.Headers.HttpContentHeaders ContentHeaders { get; }
121+
112122
/// <summary>
113123
/// The DateTime when the request was retrieved.
114124
/// </summary>
@@ -147,6 +157,7 @@ public ApiResponse(global::System.Net.Http.HttpRequestMessage httpRequestMessage
147157
{
148158
StatusCode = httpResponseMessage.StatusCode;
149159
Headers = httpResponseMessage.Headers;
160+
ContentHeaders = httpResponseMessage.Content.Headers;
150161
IsSuccessStatusCode = httpResponseMessage.IsSuccessStatusCode;
151162
ReasonPhrase = httpResponseMessage.ReasonPhrase;
152163
RawContent = rawContent;
@@ -170,6 +181,7 @@ public ApiResponse(global::System.Net.Http.HttpRequestMessage httpRequestMessage
170181
{
171182
StatusCode = httpResponseMessage.StatusCode;
172183
Headers = httpResponseMessage.Headers;
184+
ContentHeaders = httpResponseMessage.Content.Headers;
173185
IsSuccessStatusCode = httpResponseMessage.IsSuccessStatusCode;
174186
ReasonPhrase = httpResponseMessage.ReasonPhrase;
175187
ContentStream = contentStream;
@@ -181,6 +193,7 @@ public ApiResponse(global::System.Net.Http.HttpRequestMessage httpRequestMessage
181193
OnCreated(httpRequestMessage, httpResponseMessage);
182194
}
183195

196+
184197
partial void OnCreated(global::System.Net.Http.HttpRequestMessage httpRequestMessage, System.Net.Http.HttpResponseMessage httpResponseMessage);
185198
}
186199
}

samples/client/petstore/csharp/generichost/latest/ComposedEnum/src/Org.OpenAPITools/Client/ClientUtils.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using System.Text.RegularExpressions;
2020
using Org.OpenAPITools.Model;
2121
using System.Runtime.CompilerServices;
22+
using System.Net.Http.Headers;
2223

2324
[assembly: InternalsVisibleTo("Org.OpenAPITools.Test")]
2425

@@ -226,6 +227,26 @@ public static byte[] ReadAsBytes(Stream inputStream)
226227
return string.Join(",", accepts);
227228
}
228229

230+
231+
232+
/// <summary>
233+
/// Select the Accept header's value from the given accepts array:
234+
/// if JSON exists in the given array, use it;
235+
/// otherwise use all of them.
236+
/// </summary>
237+
/// <param name="accepts">The accepts array to select from.</param>
238+
/// <returns>The Accept header values to use.</returns>
239+
public static IEnumerable<MediaTypeWithQualityHeaderValue> SelectHeaderAcceptArray(string[] accepts)
240+
{
241+
if (accepts.Length == 0)
242+
return null;
243+
244+
if (accepts.Contains("application/json", StringComparer.OrdinalIgnoreCase))
245+
return [MediaTypeWithQualityHeaderValue.Parse("application/json")];
246+
247+
return accepts.Select(MediaTypeWithQualityHeaderValue.Parse);
248+
}
249+
229250
/// <summary>
230251
/// Provides a case-insensitive check that a provided content type is a known JSON-like content type.
231252
/// </summary>

samples/client/petstore/csharp/generichost/latest/ComposedEnum/src/Org.OpenAPITools/Client/DateOnlyJsonConverter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public class DateOnlyJsonConverter : JsonConverter<DateOnly>
2626
public static string[] Formats { get; } = {
2727
"yyyy'-'MM'-'dd",
2828
"yyyyMMdd"
29-
3029
};
3130

3231
/// <summary>
@@ -43,7 +42,7 @@ public override DateOnly Read(ref Utf8JsonReader reader, Type typeToConvert, Jso
4342
string value = reader.GetString()!;
4443

4544
foreach(string format in Formats)
46-
if (DateOnly.TryParseExact(value, format, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out DateOnly result))
45+
if (DateOnly.TryParseExact(value, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateOnly result))
4746
return result;
4847

4948
throw new NotSupportedException();

samples/client/petstore/csharp/generichost/latest/ComposedEnum/src/Org.OpenAPITools/Client/DateOnlyNullableJsonConverter.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ public class DateOnlyNullableJsonConverter : JsonConverter<DateOnly?>
2626
public static string[] Formats { get; } = {
2727
"yyyy'-'MM'-'dd",
2828
"yyyyMMdd"
29-
3029
};
3130

3231
/// <summary>
@@ -43,7 +42,7 @@ public class DateOnlyNullableJsonConverter : JsonConverter<DateOnly?>
4342
string value = reader.GetString()!;
4443

4544
foreach(string format in Formats)
46-
if (DateOnly.TryParseExact(value, format, CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal | DateTimeStyles.AssumeUniversal, out DateOnly result))
45+
if (DateOnly.TryParseExact(value, format, CultureInfo.InvariantCulture, DateTimeStyles.None, out DateOnly result))
4746
return result;
4847

4948
throw new NotSupportedException();

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* The version of the OpenAPI document: 0.0.1
88
* Generated by: https://github.com/openapitools/openapi-generator.git
99
*/
10-
1110
#nullable enable
1211

1312
using System;
@@ -22,32 +21,32 @@ namespace Org.OpenAPITools.Client
2221
/// <typeparam name="TTokenBase"></typeparam>
2322
public class RateLimitProvider<TTokenBase> : TokenProvider<TTokenBase> where TTokenBase : TokenBase
2423
{
25-
internal Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
24+
public Dictionary<string, global::System.Threading.Channels.Channel<TTokenBase>> AvailableTokens { get; } = new();
2625

2726
/// <summary>
2827
/// Instantiates a ThrottledTokenProvider. Your tokens will be rate limited based on the token's timeout.
2928
/// </summary>
3029
/// <param name="container"></param>
31-
public RateLimitProvider(TokenContainer<TTokenBase> container) : base(container.Tokens)
30+
public RateLimitProvider(TokenContainer<TTokenBase> container) : base()
3231
{
33-
foreach(TTokenBase token in _tokens)
32+
foreach(TTokenBase token in container.Tokens)
3433
token.StartTimer(token.Timeout ?? TimeSpan.FromMilliseconds(40));
3534

36-
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(_tokens.Length)
35+
global::System.Threading.Channels.BoundedChannelOptions options = new global::System.Threading.Channels.BoundedChannelOptions(container.Tokens.Count)
3736
{
38-
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropWrite
37+
FullMode = global::System.Threading.Channels.BoundedChannelFullMode.DropOldest
3938
};
4039

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

4342
foreach (var availableToken in AvailableTokens)
44-
foreach(TTokenBase token in _tokens)
43+
foreach(TTokenBase token in container.Tokens)
4544
{
4645
token.TokenBecameAvailable += ((sender) => availableToken.Value.Writer.TryWrite((TTokenBase)sender));
4746
}
4847
}
4948

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

samples/client/petstore/csharp/generichost/latest/ComposedEnum/src/Org.OpenAPITools/Client/TokenBase.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ public abstract class TokenBase
1717

1818

1919
internal TimeSpan? Timeout { get; set; }
20-
internal delegate void TokenBecameAvailableEventHandler(object sender);
21-
internal event TokenBecameAvailableEventHandler? TokenBecameAvailable;
20+
public delegate void TokenBecameAvailableEventHandler(object sender);
21+
public event TokenBecameAvailableEventHandler? TokenBecameAvailable;
2222

2323

2424
/// <summary>

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
* The version of the OpenAPI document: 0.0.1
88
* Generated by: https://github.com/openapitools/openapi-generator.git
99
*/
10-
1110
#nullable enable
1211

1312
using System;
@@ -22,23 +21,6 @@ namespace Org.OpenAPITools
2221
/// </summary>
2322
public abstract class TokenProvider<TTokenBase> where TTokenBase : TokenBase
2423
{
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-
}
24+
public abstract System.Threading.Tasks.ValueTask<TTokenBase> GetAsync(string header = "", System.Threading.CancellationToken cancellation = default);
4325
}
4426
}

samples/client/petstore/csharp/generichost/latest/ComposedEnum/src/Org.OpenAPITools/Org.OpenAPITools.csproj

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@
2222
</PropertyGroup>
2323

2424
<ItemGroup>
25-
<PackageReference Include="Microsoft.Extensions.Http" Version="9.0.5" />
26-
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.5" />
27-
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="9.0.5" />
28-
<PackageReference Include="Microsoft.Net.Http.Headers" Version="9.0.5" />
25+
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.3.0" />
26+
27+
<PackageReference Include="Microsoft.Extensions.Http" Condition="'$(TargetFramework)' == 'net9.0'" Version="9.0.6" />
28+
<PackageReference Include="Microsoft.Extensions.Hosting" Condition="'$(TargetFramework)' == 'net9.0'" Version="9.0.6" />
29+
<PackageReference Include="Microsoft.Extensions.Http.Polly" Condition="'$(TargetFramework)' == 'net9.0'" Version="9.0.6" />
30+
<PackageReference Include="Microsoft.Net.Http.Headers" Condition="'$(TargetFramework)' == 'net9.0'" Version="9.0.6" />
31+
<PackageReference Include="Microsoft.AspNetCore.JsonPatch" Condition="'$(TargetFramework)' == 'net9.0'" Version="9.0.6" />
2932
</ItemGroup>
3033

3134
</Project>

samples/client/petstore/csharp/generichost/latest/HelloWorld/src/Org.OpenAPITools/Api/DefaultApi.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212

1313
using System;
1414
using System.Collections.Generic;
15+
using System.Collections.ObjectModel;
1516
using System.Net;
17+
using System.IO;
1618
using System.Threading.Tasks;
1719
using Microsoft.Extensions.Logging;
1820
using System.Net.Http;

0 commit comments

Comments
 (0)