Skip to content

Commit ad53f63

Browse files
committed
samples update
1 parent 17f5b6a commit ad53f63

File tree

181 files changed

+8365
-1418
lines changed

Some content is hidden

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

181 files changed

+8365
-1418
lines changed

samples/client/echo_api/csharp/restsharp/net8/EchoApi/src/Org.OpenAPITools/Client/ApiClient.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
using System.Threading;
2424
using System.Text.RegularExpressions;
2525
using System.Threading.Tasks;
26+
#if !NET6_0_OR_GREATER
27+
using System.Web;
28+
#endif
2629
using Newtonsoft.Json;
2730
using Newtonsoft.Json.Serialization;
2831
using RestSharp;

samples/client/echo_api/csharp/restsharp/net8/EchoApi/src/Org.OpenAPITools/Client/ClientUtils.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,14 @@ public static string ParameterToString(object obj, IReadableConfiguration config
101101
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8
102102
// For example: 2009-06-15T13:45:30.0000000
103103
return dateTimeOffset.ToString((configuration ?? GlobalConfiguration.Instance).DateTimeFormat);
104+
#if NET6_0_OR_GREATER
104105
if (obj is DateOnly dateOnly)
105106
// Return a formatted date string - Can be customized with Configuration.DateTimeFormat
106107
// Defaults to an ISO 8601, using the known as a Round-trip date/time pattern ("o")
107108
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8
108109
// For example: 2009-06-15
109110
return dateOnly.ToString((configuration ?? GlobalConfiguration.Instance).DateTimeFormat);
111+
#endif
110112
if (obj is bool boolean)
111113
return boolean ? "true" : "false";
112114
if (obj is ICollection collection) {

samples/client/others/csharp-complex-files/src/Org.OpenAPITools/Client/ApiClient.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222
using System.Threading;
2323
using System.Text.RegularExpressions;
2424
using System.Threading.Tasks;
25+
#if !NET6_0_OR_GREATER
2526
using System.Web;
27+
#endif
2628
using Newtonsoft.Json;
2729
using Newtonsoft.Json.Serialization;
2830
using RestSharp;

samples/client/others/csharp-complex-files/src/Org.OpenAPITools/Client/ClientUtils.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ public static string ParameterToString(object obj, IReadableConfiguration config
116116
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8
117117
// For example: 2009-06-15T13:45:30.0000000
118118
return dateTimeOffset.ToString((configuration ?? GlobalConfiguration.Instance).DateTimeFormat);
119+
#if NET6_0_OR_GREATER
120+
if (obj is DateOnly dateOnly)
121+
// Return a formatted date string - Can be customized with Configuration.DateTimeFormat
122+
// Defaults to an ISO 8601, using the known as a Round-trip date/time pattern ("o")
123+
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8
124+
// For example: 2009-06-15
125+
return dateOnly.ToString((configuration ?? GlobalConfiguration.Instance).DateTimeFormat);
126+
#endif
119127
if (obj is bool boolean)
120128
return boolean ? "true" : "false";
121129
if (obj is ICollection collection) {

samples/client/petstore/csharp/generichost/latest/Tags/src/Org.OpenAPITools/Api/APIKEYSApi.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,18 +234,25 @@ public async Task<IGetApiKeysIdApiResponse> GetApiKeysIdAsync(int id, System.Thr
234234
uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7Bid%7D", Uri.EscapeDataString(id.ToString()));
235235

236236
httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri;
237-
237+
#if NET6_0_OR_GREATER
238238
httpRequestMessageLocalVar.Method = HttpMethod.Get;
239+
#else
240+
httpRequestMessageLocalVar.Method = new HttpMethod("GET");
241+
#endif
239242

240243
DateTime requestedAtLocalVar = DateTime.UtcNow;
241244

242245
using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false))
243246
{
244-
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
247+
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(
248+
#if NET6_0_OR_GREATER
249+
cancellationToken
250+
#endif
251+
).ConfigureAwait(false);
245252

246253
ILogger<GetApiKeysIdApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<GetApiKeysIdApiResponse>();
247254

248-
GetApiKeysIdApiResponse apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);
255+
GetApiKeysIdApiResponse apiResponseLocalVar = new GetApiKeysIdApiResponse(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);
249256

250257
AfterGetApiKeysIdDefaultImplementation(apiResponseLocalVar, id);
251258

samples/client/petstore/csharp/generichost/latest/Tags/src/Org.OpenAPITools/Api/APIKeys0Api.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,25 @@ public async Task<IGetApiKeysIdApiResponse> GetApiKeysIdAsync(int id, System.Thr
222222
uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7Bid%7D", Uri.EscapeDataString(id.ToString()));
223223

224224
httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri;
225-
225+
#if NET6_0_OR_GREATER
226226
httpRequestMessageLocalVar.Method = HttpMethod.Get;
227+
#else
228+
httpRequestMessageLocalVar.Method = new HttpMethod("GET");
229+
#endif
227230

228231
DateTime requestedAtLocalVar = DateTime.UtcNow;
229232

230233
using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false))
231234
{
232-
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
235+
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(
236+
#if NET6_0_OR_GREATER
237+
cancellationToken
238+
#endif
239+
).ConfigureAwait(false);
233240

234241
ILogger<APIKEYSApi.GetApiKeysIdApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<APIKEYSApi.GetApiKeysIdApiResponse>();
235242

236-
APIKEYSApi.GetApiKeysIdApiResponse apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);
243+
APIKEYSApi.GetApiKeysIdApiResponse apiResponseLocalVar = new GetApiKeysIdApiResponse(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);
237244

238245
AfterGetApiKeysIdDefaultImplementation(apiResponseLocalVar, id);
239246

samples/client/petstore/csharp/generichost/latest/Tags/src/Org.OpenAPITools/Api/ApiKeys1Api.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,25 @@ public async Task<IGetApiKeysIdApiResponse> GetApiKeysIdAsync(int id, System.Thr
222222
uriBuilderLocalVar.Path = uriBuilderLocalVar.Path.Replace("%7Bid%7D", Uri.EscapeDataString(id.ToString()));
223223

224224
httpRequestMessageLocalVar.RequestUri = uriBuilderLocalVar.Uri;
225-
225+
#if NET6_0_OR_GREATER
226226
httpRequestMessageLocalVar.Method = HttpMethod.Get;
227+
#else
228+
httpRequestMessageLocalVar.Method = new HttpMethod("GET");
229+
#endif
227230

228231
DateTime requestedAtLocalVar = DateTime.UtcNow;
229232

230233
using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false))
231234
{
232-
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
235+
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(
236+
#if NET6_0_OR_GREATER
237+
cancellationToken
238+
#endif
239+
).ConfigureAwait(false);
233240

234241
ILogger<APIKEYSApi.GetApiKeysIdApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<APIKEYSApi.GetApiKeysIdApiResponse>();
235242

236-
APIKEYSApi.GetApiKeysIdApiResponse apiResponseLocalVar = new(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);
243+
APIKEYSApi.GetApiKeysIdApiResponse apiResponseLocalVar = new GetApiKeysIdApiResponse(apiResponseLoggerLocalVar, httpRequestMessageLocalVar, httpResponseMessageLocalVar, responseContentLocalVar, "/api_keys/{id}", requestedAtLocalVar, _jsonSerializerOptions);
237244

238245
AfterGetApiKeysIdDefaultImplementation(apiResponseLocalVar, id);
239246

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,15 @@ public static string ApiKeyHeaderToString(ApiKeyHeader value)
7373
/// <param name="options"></param>
7474
/// <param name="result"></param>
7575
/// <returns></returns>
76-
public static bool TryDeserialize<T>(string json, JsonSerializerOptions options, [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T? result)
76+
public static bool TryDeserialize<T>(string json, JsonSerializerOptions options,
77+
#if NET6_0_OR_GREATER
78+
[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)]
79+
#endif
80+
out T
81+
#if NET6_0_OR_GREATER
82+
?
83+
#endif
84+
result)
7785
{
7886
try
7987
{
@@ -95,7 +103,15 @@ public static bool TryDeserialize<T>(string json, JsonSerializerOptions options,
95103
/// <param name="options"></param>
96104
/// <param name="result"></param>
97105
/// <returns></returns>
98-
public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOptions options, [global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)] out T? result)
106+
public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOptions options,
107+
#if NET6_0_OR_GREATER
108+
[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)]
109+
#endif
110+
out T
111+
#if NET6_0_OR_GREATER
112+
?
113+
#endif
114+
result)
99115
{
100116
try
101117
{
@@ -142,8 +158,10 @@ public static string SanitizeFilename(string filename)
142158
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8
143159
// For example: 2009-06-15T13:45:30.0000000
144160
return dateTimeOffset.ToString(format);
161+
#if NET6_0_OR_GREATER
145162
if (obj is DateOnly dateOnly)
146163
return dateOnly.ToString(format);
164+
#endif
147165
if (obj is bool boolean)
148166
return boolean
149167
? "true"

samples/client/petstore/csharp/generichost/latest/Tags/src/Org.OpenAPITools/Client/HostConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public HostConfiguration(IServiceCollection services)
4343
_jsonOptions.Converters.Add(new DateTimeNullableJsonConverter());
4444
_jsonOptions.Converters.Add(new DateOnlyJsonConverter());
4545
_jsonOptions.Converters.Add(new DateOnlyNullableJsonConverter());
46-
JsonSerializerOptionsProvider jsonSerializerOptionsProvider = new(_jsonOptions);
46+
JsonSerializerOptionsProvider jsonSerializerOptionsProvider = new JsonSerializerOptionsProvider(_jsonOptions);
4747
_services.AddSingleton(jsonSerializerOptionsProvider);
4848
_services.AddSingleton<IApiFactory, ApiFactory>();
4949
_services.AddSingleton<APIKEYSApiEvents>();

samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Api/DefaultApi.cs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,21 @@ public async Task<IListApiResponse> ListAsync(string personId, System.Threading.
247247

248248
if (acceptLocalVar != null)
249249
httpRequestMessageLocalVar.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptLocalVar));
250+
#if NET6_0_OR_GREATER
251+
httpRequestMessageLocalVar.Method = HttpMethod.Get;
252+
#else
250253
httpRequestMessageLocalVar.Method = new HttpMethod("GET");
254+
#endif
251255

252256
DateTime requestedAtLocalVar = DateTime.UtcNow;
253257

254258
using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false))
255259
{
256-
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync().ConfigureAwait(false);
260+
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(
261+
#if NET6_0_OR_GREATER
262+
cancellationToken
263+
#endif
264+
).ConfigureAwait(false);
257265

258266
ILogger<ListApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<ListApiResponse>();
259267

@@ -318,15 +326,24 @@ public Org.OpenAPITools.Model.Person Ok()
318326
// This logic may be modified with the AsModel.mustache template
319327
return IsOk
320328
? System.Text.Json.JsonSerializer.Deserialize<Org.OpenAPITools.Model.Person>(RawContent, _jsonSerializerOptions)
321-
: default;
329+
:
330+
#if NET6_0_OR_GREATER
331+
null
332+
#else
333+
default
334+
#endif;
322335
}
323336

324337
/// <summary>
325338
/// Returns true if the response is 200 Ok and the deserialized response is not null
326339
/// </summary>
327340
/// <param name="result"></param>
328341
/// <returns></returns>
329-
public bool TryOk(out Org.OpenAPITools.Model.Person result)
342+
public bool TryOk(
343+
#if NET6_0_OR_GREATER
344+
[NotNullWhen(true)]
345+
#endif
346+
out Org.OpenAPITools.Model.Person result)
330347
{
331348
result = null;
332349

0 commit comments

Comments
 (0)