Skip to content

Commit 4a54379

Browse files
authored
added OrDefault method (#15551)
1 parent d8ed253 commit 4a54379

25 files changed

Lines changed: 3938 additions & 45 deletions

File tree

modules/openapi-generator/src/main/resources/csharp-netcore/libraries/generichost/api.mustache

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,21 @@ namespace {{packageName}}.{{interfacePrefix}}{{apiPackage}}
3838
/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>
3939
{{/allParams}}
4040
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
41-
/// <returns>Task&lt;ApiResponse&lt;{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}object{{/returnType}}{{nrt?}}&gt;&gt;</returns>
41+
/// <returns>Task&lt;ApiResponse&lt;{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}object{{/returnType}}&gt;&gt;</returns>
4242
Task<ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}object{{/returnType}}>> {{operationId}}Async({{>OperationSignature}});
43+
44+
/// <summary>
45+
/// {{summary}}
46+
/// </summary>
47+
/// <remarks>
48+
/// {{notes}}
49+
/// </remarks>
50+
{{#allParams}}
51+
/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>
52+
{{/allParams}}
53+
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
54+
/// <returns>Task&lt;ApiResponse&gt;{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}object{{/returnType}}&gt;{{nrt?}}&gt;</returns>
55+
Task<ApiResponse<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}object{{/returnType}}>{{nrt?}}> {{operationId}}OrDefaultAsync({{>OperationSignature}});
4356
{{^-last}}
4457

4558
{{/-last}}
@@ -183,6 +196,26 @@ namespace {{packageName}}.{{apiPackage}}
183196
Logger.LogError(exception, "An error occurred while sending the request to the server.");
184197
}
185198

199+
/// <summary>
200+
/// {{summary}} {{notes}}
201+
/// </summary>
202+
{{#allParams}}
203+
/// <param name="{{paramName}}">{{description}}{{^required}} (optional{{#defaultValue}}, default to {{.}}{{/defaultValue}}){{/required}}</param>
204+
{{/allParams}}
205+
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
206+
/// <returns><see cref="Task"/>&lt;<see cref="ApiResponse{T}"/>&gt; where T : <see cref="{{#returnType}}{{returnType}}{{/returnType}}{{^returnType}}object{{/returnType}}"/></returns>
207+
public async Task<ApiResponse<{{#returnType}}{{{.}}}{{/returnType}}{{^returnType}}object{{/returnType}}>{{nrt?}}> {{operationId}}OrDefaultAsync({{>OperationSignature}})
208+
{
209+
try
210+
{
211+
return await {{operationId}}Async({{#allParams}}{{paramName}}{{^-last}}, {{/-last}}{{/allParams}}{{#allParams.0}}, {{/allParams.0}}cancellationToken).ConfigureAwait(false);
212+
}
213+
catch (Exception)
214+
{
215+
return null;
216+
}
217+
}
218+
186219
/// <summary>
187220
/// {{summary}} {{notes}}
188221
/// </summary>

samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Api/AnotherFakeApi.cs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,19 @@ public interface IAnotherFakeApi : IApi
3838
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
3939
/// <param name="modelClient">client model</param>
4040
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
41-
/// <returns>Task&lt;ApiResponse&lt;ModelClient?&gt;&gt;</returns>
41+
/// <returns>Task&lt;ApiResponse&lt;ModelClient&gt;&gt;</returns>
4242
Task<ApiResponse<ModelClient>> Call123TestSpecialTagsAsync(ModelClient modelClient, System.Threading.CancellationToken? cancellationToken = null);
43+
44+
/// <summary>
45+
/// To test special tags
46+
/// </summary>
47+
/// <remarks>
48+
/// To test special tags and operation ID starting with number
49+
/// </remarks>
50+
/// <param name="modelClient">client model</param>
51+
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
52+
/// <returns>Task&lt;ApiResponse&gt;ModelClient&gt;?&gt;</returns>
53+
Task<ApiResponse<ModelClient>?> Call123TestSpecialTagsOrDefaultAsync(ModelClient modelClient, System.Threading.CancellationToken? cancellationToken = null);
4354
}
4455
}
4556

@@ -157,6 +168,24 @@ protected virtual void OnErrorCall123TestSpecialTags(Exception exception, string
157168
Logger.LogError(exception, "An error occurred while sending the request to the server.");
158169
}
159170

171+
/// <summary>
172+
/// To test special tags To test special tags and operation ID starting with number
173+
/// </summary>
174+
/// <param name="modelClient">client model</param>
175+
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
176+
/// <returns><see cref="Task"/>&lt;<see cref="ApiResponse{T}"/>&gt; where T : <see cref="ModelClient"/></returns>
177+
public async Task<ApiResponse<ModelClient>?> Call123TestSpecialTagsOrDefaultAsync(ModelClient modelClient, System.Threading.CancellationToken? cancellationToken = null)
178+
{
179+
try
180+
{
181+
return await Call123TestSpecialTagsAsync(modelClient, cancellationToken).ConfigureAwait(false);
182+
}
183+
catch (Exception)
184+
{
185+
return null;
186+
}
187+
}
188+
160189
/// <summary>
161190
/// To test special tags To test special tags and operation ID starting with number
162191
/// </summary>

samples/client/petstore/csharp-netcore/OpenAPIClient-generichost-net6.0-nrt/src/Org.OpenAPITools/Api/DefaultApi.cs

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,19 @@ public interface IDefaultApi : IApi
3737
/// </remarks>
3838
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
3939
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
40-
/// <returns>Task&lt;ApiResponse&lt;FooGetDefaultResponse?&gt;&gt;</returns>
40+
/// <returns>Task&lt;ApiResponse&lt;FooGetDefaultResponse&gt;&gt;</returns>
4141
Task<ApiResponse<FooGetDefaultResponse>> FooGetAsync(System.Threading.CancellationToken? cancellationToken = null);
4242

43+
/// <summary>
44+
///
45+
/// </summary>
46+
/// <remarks>
47+
///
48+
/// </remarks>
49+
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
50+
/// <returns>Task&lt;ApiResponse&gt;FooGetDefaultResponse&gt;?&gt;</returns>
51+
Task<ApiResponse<FooGetDefaultResponse>?> FooGetOrDefaultAsync(System.Threading.CancellationToken? cancellationToken = null);
52+
4353
/// <summary>
4454
///
4555
/// </summary>
@@ -49,9 +59,20 @@ public interface IDefaultApi : IApi
4959
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
5060
/// <param name="country"></param>
5161
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
52-
/// <returns>Task&lt;ApiResponse&lt;object?&gt;&gt;</returns>
62+
/// <returns>Task&lt;ApiResponse&lt;object&gt;&gt;</returns>
5363
Task<ApiResponse<object>> GetCountryAsync(string country, System.Threading.CancellationToken? cancellationToken = null);
5464

65+
/// <summary>
66+
///
67+
/// </summary>
68+
/// <remarks>
69+
///
70+
/// </remarks>
71+
/// <param name="country"></param>
72+
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
73+
/// <returns>Task&lt;ApiResponse&gt;object&gt;?&gt;</returns>
74+
Task<ApiResponse<object>?> GetCountryOrDefaultAsync(string country, System.Threading.CancellationToken? cancellationToken = null);
75+
5576
/// <summary>
5677
/// Hello
5778
/// </summary>
@@ -60,8 +81,18 @@ public interface IDefaultApi : IApi
6081
/// </remarks>
6182
/// <exception cref="ApiException">Thrown when fails to make API call</exception>
6283
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
63-
/// <returns>Task&lt;ApiResponse&lt;List&lt;Guid&gt;?&gt;&gt;</returns>
84+
/// <returns>Task&lt;ApiResponse&lt;List&lt;Guid&gt;&gt;&gt;</returns>
6485
Task<ApiResponse<List<Guid>>> HelloAsync(System.Threading.CancellationToken? cancellationToken = null);
86+
87+
/// <summary>
88+
/// Hello
89+
/// </summary>
90+
/// <remarks>
91+
/// Hello
92+
/// </remarks>
93+
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
94+
/// <returns>Task&lt;ApiResponse&gt;List&lt;Guid&gt;&gt;?&gt;</returns>
95+
Task<ApiResponse<List<Guid>>?> HelloOrDefaultAsync(System.Threading.CancellationToken? cancellationToken = null);
6596
}
6697
}
6798

@@ -167,6 +198,23 @@ protected virtual void OnErrorFooGet(Exception exception, string pathFormat, str
167198
Logger.LogError(exception, "An error occurred while sending the request to the server.");
168199
}
169200

201+
/// <summary>
202+
///
203+
/// </summary>
204+
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
205+
/// <returns><see cref="Task"/>&lt;<see cref="ApiResponse{T}"/>&gt; where T : <see cref="FooGetDefaultResponse"/></returns>
206+
public async Task<ApiResponse<FooGetDefaultResponse>?> FooGetOrDefaultAsync(System.Threading.CancellationToken? cancellationToken = null)
207+
{
208+
try
209+
{
210+
return await FooGetAsync(cancellationToken).ConfigureAwait(false);
211+
}
212+
catch (Exception)
213+
{
214+
return null;
215+
}
216+
}
217+
170218
/// <summary>
171219
///
172220
/// </summary>
@@ -266,6 +314,24 @@ protected virtual void OnErrorGetCountry(Exception exception, string pathFormat,
266314
Logger.LogError(exception, "An error occurred while sending the request to the server.");
267315
}
268316

317+
/// <summary>
318+
///
319+
/// </summary>
320+
/// <param name="country"></param>
321+
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
322+
/// <returns><see cref="Task"/>&lt;<see cref="ApiResponse{T}"/>&gt; where T : <see cref="object"/></returns>
323+
public async Task<ApiResponse<object>?> GetCountryOrDefaultAsync(string country, System.Threading.CancellationToken? cancellationToken = null)
324+
{
325+
try
326+
{
327+
return await GetCountryAsync(country, cancellationToken).ConfigureAwait(false);
328+
}
329+
catch (Exception)
330+
{
331+
return null;
332+
}
333+
}
334+
269335
/// <summary>
270336
///
271337
/// </summary>
@@ -364,6 +430,23 @@ protected virtual void OnErrorHello(Exception exception, string pathFormat, stri
364430
Logger.LogError(exception, "An error occurred while sending the request to the server.");
365431
}
366432

433+
/// <summary>
434+
/// Hello Hello
435+
/// </summary>
436+
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
437+
/// <returns><see cref="Task"/>&lt;<see cref="ApiResponse{T}"/>&gt; where T : <see cref="List&lt;Guid&gt;"/></returns>
438+
public async Task<ApiResponse<List<Guid>>?> HelloOrDefaultAsync(System.Threading.CancellationToken? cancellationToken = null)
439+
{
440+
try
441+
{
442+
return await HelloAsync(cancellationToken).ConfigureAwait(false);
443+
}
444+
catch (Exception)
445+
{
446+
return null;
447+
}
448+
}
449+
367450
/// <summary>
368451
/// Hello Hello
369452
/// </summary>

0 commit comments

Comments
 (0)