Skip to content

Commit c8af701

Browse files
author
Bryan Aldrich
committed
samples update
1 parent 9879fa5 commit c8af701

File tree

183 files changed

+8367
-1420
lines changed

Some content is hidden

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

183 files changed

+8367
-1420
lines changed

Diff for: samples/client/echo_api/csharp-restsharp/src/Org.OpenAPITools.Test/CustomTest.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Newtonsoft.Json.Linq;
1+
using Newtonsoft.Json.Linq;
22
using Org.OpenAPITools.Api;
33
using Org.OpenAPITools.Model;
44
using System;

Diff for: samples/client/echo_api/csharp-restsharp/src/Org.OpenAPITools.Test/EchoServerResponseParser.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech)
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");

Diff for: samples/client/echo_api/csharp-restsharp/src/Org.OpenAPITools/Client/ApiClient.cs

+3
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;

Diff for: samples/client/echo_api/csharp-restsharp/src/Org.OpenAPITools/Client/ClientUtils.cs

+2
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) {

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

+2
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;

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

+8
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) {

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

+10-3
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

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

+10-3
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

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

+10-3
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

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

+20-2
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"

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

+1-1
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>();

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

+20-3
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

Diff for: samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Client/ApiResponse`1.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ public interface IOk<TType> : IApiResponse
165165
/// </summary>
166166
/// <param name="result"></param>
167167
/// <returns></returns>
168-
bool TryOk(out TType result);
168+
bool TryOk(
169+
#if NET6_0_OR_GREATER
170+
[NotNullWhen(true)]
171+
#endif
172+
out TType result);
169173
}
170174
}

Diff for: samples/client/petstore/csharp/generichost/net4.7/AllOf/src/Org.OpenAPITools/Client/ClientUtils.cs

+14-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,11 @@ static ClientUtils()
6060
/// <param name="options"></param>
6161
/// <param name="result"></param>
6262
/// <returns></returns>
63-
public static bool TryDeserialize<T>(string json, JsonSerializerOptions options, out T result)
63+
public static bool TryDeserialize<T>(string json, JsonSerializerOptions options,
64+
#if NET6_0_OR_GREATER
65+
[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)]
66+
#endif
67+
out T result)
6468
{
6569
try
6670
{
@@ -82,7 +86,11 @@ public static bool TryDeserialize<T>(string json, JsonSerializerOptions options,
8286
/// <param name="options"></param>
8387
/// <param name="result"></param>
8488
/// <returns></returns>
85-
public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOptions options, out T result)
89+
public static bool TryDeserialize<T>(ref Utf8JsonReader reader, JsonSerializerOptions options,
90+
#if NET6_0_OR_GREATER
91+
[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)]
92+
#endif
93+
out T result)
8694
{
8795
try
8896
{
@@ -129,6 +137,10 @@ public static string ParameterToString(object obj, string format = ISO8601_DATET
129137
// https://msdn.microsoft.com/en-us/library/az4se3k1(v=vs.110).aspx#Anchor_8
130138
// For example: 2009-06-15T13:45:30.0000000
131139
return dateTimeOffset.ToString(format);
140+
#if NET6_0_OR_GREATER
141+
if (obj is DateOnly dateOnly)
142+
return dateOnly.ToString(format);
143+
#endif
132144
if (obj is bool boolean)
133145
return boolean
134146
? "true"

Diff for: samples/client/petstore/csharp/generichost/net4.7/AnyOf/src/Org.OpenAPITools/Api/DefaultApi.cs

+20-3
Original file line numberDiff line numberDiff line change
@@ -221,13 +221,21 @@ public async Task<IRootGetApiResponse> RootGetAsync(System.Threading.Cancellatio
221221

222222
if (acceptLocalVar != null)
223223
httpRequestMessageLocalVar.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(acceptLocalVar));
224+
#if NET6_0_OR_GREATER
225+
httpRequestMessageLocalVar.Method = HttpMethod.Get;
226+
#else
224227
httpRequestMessageLocalVar.Method = new HttpMethod("GET");
228+
#endif
225229

226230
DateTime requestedAtLocalVar = DateTime.UtcNow;
227231

228232
using (HttpResponseMessage httpResponseMessageLocalVar = await HttpClient.SendAsync(httpRequestMessageLocalVar, cancellationToken).ConfigureAwait(false))
229233
{
230-
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync().ConfigureAwait(false);
234+
string responseContentLocalVar = await httpResponseMessageLocalVar.Content.ReadAsStringAsync(
235+
#if NET6_0_OR_GREATER
236+
cancellationToken
237+
#endif
238+
).ConfigureAwait(false);
231239

232240
ILogger<RootGetApiResponse> apiResponseLoggerLocalVar = LoggerFactory.CreateLogger<RootGetApiResponse>();
233241

@@ -292,15 +300,24 @@ public Org.OpenAPITools.Model.Fruit Ok()
292300
// This logic may be modified with the AsModel.mustache template
293301
return IsOk
294302
? System.Text.Json.JsonSerializer.Deserialize<Org.OpenAPITools.Model.Fruit>(RawContent, _jsonSerializerOptions)
295-
: default;
303+
:
304+
#if NET6_0_OR_GREATER
305+
null
306+
#else
307+
default
308+
#endif;
296309
}
297310

298311
/// <summary>
299312
/// Returns true if the response is 200 Ok and the deserialized response is not null
300313
/// </summary>
301314
/// <param name="result"></param>
302315
/// <returns></returns>
303-
public bool TryOk(out Org.OpenAPITools.Model.Fruit result)
316+
public bool TryOk(
317+
#if NET6_0_OR_GREATER
318+
[NotNullWhen(true)]
319+
#endif
320+
out Org.OpenAPITools.Model.Fruit result)
304321
{
305322
result = null;
306323

Diff for: samples/client/petstore/csharp/generichost/net4.7/AnyOf/src/Org.OpenAPITools/Client/ApiResponse`1.cs

+5-1
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ public interface IOk<TType> : IApiResponse
165165
/// </summary>
166166
/// <param name="result"></param>
167167
/// <returns></returns>
168-
bool TryOk(out TType result);
168+
bool TryOk(
169+
#if NET6_0_OR_GREATER
170+
[NotNullWhen(true)]
171+
#endif
172+
out TType result);
169173
}
170174
}

0 commit comments

Comments
 (0)