Skip to content

Commit 32e5f0b

Browse files
authored
refactor AsModel template (#24650)
1 parent dc80646 commit 32e5f0b

156 files changed

Lines changed: 6929 additions & 533 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// This logic may be modified with the AsModel.mustache template
1+
// NOTICE: Consider this AsModel template deprecated. Implement the appropriate partial method instead
22
return Is{{vendorExtensions.x-http-status}}
33
? {{#isBinary}}ContentStream{{/isBinary}}{{^isBinary}}System.Text.Json.JsonSerializer.Deserialize<{{#isModel}}{{^containerType}}{{packageName}}.{{modelPackage}}.{{/containerType}}{{/isModel}}{{{dataType}}}>(RawContent, _jsonSerializerOptions){{/isBinary}}
44
: {{#net60OrLater}}null{{/net60OrLater}}{{^net60OrLater}}default{{/net60OrLater}};

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,16 @@ namespace {{packageName}}.{{apiPackage}}
896896
/// </summary>
897897
/// <returns></returns>
898898
public {{#isModel}}{{^containerType}}{{packageName}}.{{modelPackage}}.{{/containerType}}{{/isModel}}{{{dataType}}}{{#nrt}}?{{/nrt}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}} {{vendorExtensions.x-http-status}}()
899+
{
900+
bool suppressDefault = false;
901+
{{#isModel}}{{^containerType}}{{packageName}}.{{modelPackage}}.{{/containerType}}{{/isModel}}{{{dataType}}}{{#nrt}}?{{/nrt}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}} result = {{#net60OrLater}}null{{/net60OrLater}}{{^net60OrLater}}default{{/net60OrLater}};
902+
On{{vendorExtensions.x-http-status}}(ref suppressDefault, ref result);
903+
if (!suppressDefault)
904+
result = Default{{vendorExtensions.x-http-status}}();
905+
return result;
906+
}
907+
908+
private {{#isModel}}{{^containerType}}{{packageName}}.{{modelPackage}}.{{/containerType}}{{/isModel}}{{{dataType}}}{{#nrt}}?{{/nrt}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}} Default{{vendorExtensions.x-http-status}}()
899909
{
900910
{{#lambda.trimTrailingWithNewLine}}
901911
{{#lambda.indent4}}
@@ -904,6 +914,8 @@ namespace {{packageName}}.{{apiPackage}}
904914
{{/lambda.trimTrailingWithNewLine}}
905915
}
906916

917+
partial void On{{vendorExtensions.x-http-status}}(ref bool suppressDefault, ref {{#isModel}}{{^containerType}}{{packageName}}.{{modelPackage}}.{{/containerType}}{{/isModel}}{{{dataType}}}{{#nrt}}?{{/nrt}}{{^nrt}}{{#vendorExtensions.x-is-value-type}}?{{/vendorExtensions.x-is-value-type}}{{/nrt}} result);
918+
907919
/// <summary>
908920
/// Returns true if the response is {{code}} {{vendorExtensions.x-http-status}} and the deserialized response is not null
909921
/// </summary>

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,12 +337,24 @@ public ListApiResponse(ILogger<DefaultApi> logger, System.Net.Http.HttpRequestMe
337337
/// <returns></returns>
338338
public string? Ok()
339339
{
340-
// This logic may be modified with the AsModel.mustache template
340+
bool suppressDefault = false;
341+
string? result = null;
342+
OnOk(ref suppressDefault, ref result);
343+
if (!suppressDefault)
344+
result = DefaultOk();
345+
return result;
346+
}
347+
348+
private string? DefaultOk()
349+
{
350+
// NOTICE: Consider this AsModel template deprecated. Implement the appropriate partial method instead
341351
return IsOk
342352
? System.Text.Json.JsonSerializer.Deserialize<string>(RawContent, _jsonSerializerOptions)
343353
: null;
344354
}
345355

356+
partial void OnOk(ref bool suppressDefault, ref string? result);
357+
346358
/// <summary>
347359
/// Returns true if the response is 200 Ok and the deserialized response is not null
348360
/// </summary>

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,12 +344,24 @@ public IconsApiResponse(ILogger<DefaultApi> logger, System.Net.Http.HttpRequestM
344344
/// <returns></returns>
345345
public Org.OpenAPITools.Model.IconsDefaultResponse? Default()
346346
{
347-
// This logic may be modified with the AsModel.mustache template
347+
bool suppressDefault = false;
348+
Org.OpenAPITools.Model.IconsDefaultResponse? result = null;
349+
OnDefault(ref suppressDefault, ref result);
350+
if (!suppressDefault)
351+
result = DefaultDefault();
352+
return result;
353+
}
354+
355+
private Org.OpenAPITools.Model.IconsDefaultResponse? DefaultDefault()
356+
{
357+
// NOTICE: Consider this AsModel template deprecated. Implement the appropriate partial method instead
348358
return IsDefault
349359
? System.Text.Json.JsonSerializer.Deserialize<Org.OpenAPITools.Model.IconsDefaultResponse>(RawContent, _jsonSerializerOptions)
350360
: null;
351361
}
352362

363+
partial void OnDefault(ref bool suppressDefault, ref Org.OpenAPITools.Model.IconsDefaultResponse? result);
364+
353365
/// <summary>
354366
/// Returns true if the response is 0 Default and the deserialized response is not null
355367
/// </summary>

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,24 @@ public GetWidgetApiResponse(ILogger<DefaultApi> logger, System.Net.Http.HttpRequ
331331
/// <returns></returns>
332332
public Org.OpenAPITools.Model.Widget? Ok()
333333
{
334-
// This logic may be modified with the AsModel.mustache template
334+
bool suppressDefault = false;
335+
Org.OpenAPITools.Model.Widget? result = null;
336+
OnOk(ref suppressDefault, ref result);
337+
if (!suppressDefault)
338+
result = DefaultOk();
339+
return result;
340+
}
341+
342+
private Org.OpenAPITools.Model.Widget? DefaultOk()
343+
{
344+
// NOTICE: Consider this AsModel template deprecated. Implement the appropriate partial method instead
335345
return IsOk
336346
? System.Text.Json.JsonSerializer.Deserialize<Org.OpenAPITools.Model.Widget>(RawContent, _jsonSerializerOptions)
337347
: null;
338348
}
339349

350+
partial void OnOk(ref bool suppressDefault, ref Org.OpenAPITools.Model.Widget? result);
351+
340352
/// <summary>
341353
/// Returns true if the response is 200 Ok and the deserialized response is not null
342354
/// </summary>

samples/client/petstore/csharp/generichost/latest/UseDateTimeOffset/src/Org.OpenAPITools/Api/AnotherFakeApi.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,24 @@ public Call123TestSpecialTagsApiResponse(ILogger<AnotherFakeApi> logger, System.
385385
/// <returns></returns>
386386
public Org.OpenAPITools.Model.ModelClient? Ok()
387387
{
388-
// This logic may be modified with the AsModel.mustache template
388+
bool suppressDefault = false;
389+
Org.OpenAPITools.Model.ModelClient? result = null;
390+
OnOk(ref suppressDefault, ref result);
391+
if (!suppressDefault)
392+
result = DefaultOk();
393+
return result;
394+
}
395+
396+
private Org.OpenAPITools.Model.ModelClient? DefaultOk()
397+
{
398+
// NOTICE: Consider this AsModel template deprecated. Implement the appropriate partial method instead
389399
return IsOk
390400
? System.Text.Json.JsonSerializer.Deserialize<Org.OpenAPITools.Model.ModelClient>(RawContent, _jsonSerializerOptions)
391401
: null;
392402
}
393403

404+
partial void OnOk(ref bool suppressDefault, ref Org.OpenAPITools.Model.ModelClient? result);
405+
394406
/// <summary>
395407
/// Returns true if the response is 200 Ok and the deserialized response is not null
396408
/// </summary>

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

Lines changed: 65 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,24 @@ public FooGetApiResponse(ILogger<DefaultApi> logger, System.Net.Http.HttpRequest
620620
/// <returns></returns>
621621
public Org.OpenAPITools.Model.FooGetDefaultResponse? Default()
622622
{
623-
// This logic may be modified with the AsModel.mustache template
623+
bool suppressDefault = false;
624+
Org.OpenAPITools.Model.FooGetDefaultResponse? result = null;
625+
OnDefault(ref suppressDefault, ref result);
626+
if (!suppressDefault)
627+
result = DefaultDefault();
628+
return result;
629+
}
630+
631+
private Org.OpenAPITools.Model.FooGetDefaultResponse? DefaultDefault()
632+
{
633+
// NOTICE: Consider this AsModel template deprecated. Implement the appropriate partial method instead
624634
return IsDefault
625635
? System.Text.Json.JsonSerializer.Deserialize<Org.OpenAPITools.Model.FooGetDefaultResponse>(RawContent, _jsonSerializerOptions)
626636
: null;
627637
}
628638

639+
partial void OnDefault(ref bool suppressDefault, ref Org.OpenAPITools.Model.FooGetDefaultResponse? result);
640+
629641
/// <summary>
630642
/// Returns true if the response is 0 Default and the deserialized response is not null
631643
/// </summary>
@@ -1047,12 +1059,24 @@ public HelloApiResponse(ILogger<DefaultApi> logger, System.Net.Http.HttpRequestM
10471059
/// <returns></returns>
10481060
public List<Guid>? Ok()
10491061
{
1050-
// This logic may be modified with the AsModel.mustache template
1062+
bool suppressDefault = false;
1063+
List<Guid>? result = null;
1064+
OnOk(ref suppressDefault, ref result);
1065+
if (!suppressDefault)
1066+
result = DefaultOk();
1067+
return result;
1068+
}
1069+
1070+
private List<Guid>? DefaultOk()
1071+
{
1072+
// NOTICE: Consider this AsModel template deprecated. Implement the appropriate partial method instead
10511073
return IsOk
10521074
? System.Text.Json.JsonSerializer.Deserialize<List<Guid>>(RawContent, _jsonSerializerOptions)
10531075
: null;
10541076
}
10551077

1078+
partial void OnOk(ref bool suppressDefault, ref List<Guid>? result);
1079+
10561080
/// <summary>
10571081
/// Returns true if the response is 200 Ok and the deserialized response is not null
10581082
/// </summary>
@@ -1270,12 +1294,24 @@ public RedirectOrDefaultApiResponse(ILogger<DefaultApi> logger, System.Net.Http.
12701294
/// <returns></returns>
12711295
public string? Default()
12721296
{
1273-
// This logic may be modified with the AsModel.mustache template
1297+
bool suppressDefault = false;
1298+
string? result = null;
1299+
OnDefault(ref suppressDefault, ref result);
1300+
if (!suppressDefault)
1301+
result = DefaultDefault();
1302+
return result;
1303+
}
1304+
1305+
private string? DefaultDefault()
1306+
{
1307+
// NOTICE: Consider this AsModel template deprecated. Implement the appropriate partial method instead
12741308
return IsDefault
12751309
? System.Text.Json.JsonSerializer.Deserialize<string>(RawContent, _jsonSerializerOptions)
12761310
: null;
12771311
}
12781312

1313+
partial void OnDefault(ref bool suppressDefault, ref string? result);
1314+
12791315
/// <summary>
12801316
/// Returns true if the response is 0 Default and the deserialized response is not null
12811317
/// </summary>
@@ -1487,12 +1523,24 @@ public RolesReportGetApiResponse(ILogger<DefaultApi> logger, System.Net.Http.Htt
14871523
/// <returns></returns>
14881524
public List<List<RolesReportsHash>>? Ok()
14891525
{
1490-
// This logic may be modified with the AsModel.mustache template
1526+
bool suppressDefault = false;
1527+
List<List<RolesReportsHash>>? result = null;
1528+
OnOk(ref suppressDefault, ref result);
1529+
if (!suppressDefault)
1530+
result = DefaultOk();
1531+
return result;
1532+
}
1533+
1534+
private List<List<RolesReportsHash>>? DefaultOk()
1535+
{
1536+
// NOTICE: Consider this AsModel template deprecated. Implement the appropriate partial method instead
14911537
return IsOk
14921538
? System.Text.Json.JsonSerializer.Deserialize<List<List<RolesReportsHash>>>(RawContent, _jsonSerializerOptions)
14931539
: null;
14941540
}
14951541

1542+
partial void OnOk(ref bool suppressDefault, ref List<List<RolesReportsHash>>? result);
1543+
14961544
/// <summary>
14971545
/// Returns true if the response is 200 Ok and the deserialized response is not null
14981546
/// </summary>
@@ -1704,12 +1752,24 @@ public TestApiResponse(ILogger<DefaultApi> logger, System.Net.Http.HttpRequestMe
17041752
/// <returns></returns>
17051753
public Org.OpenAPITools.Model.NotificationtestGetElementsV1ResponseMPayload? Ok()
17061754
{
1707-
// This logic may be modified with the AsModel.mustache template
1755+
bool suppressDefault = false;
1756+
Org.OpenAPITools.Model.NotificationtestGetElementsV1ResponseMPayload? result = null;
1757+
OnOk(ref suppressDefault, ref result);
1758+
if (!suppressDefault)
1759+
result = DefaultOk();
1760+
return result;
1761+
}
1762+
1763+
private Org.OpenAPITools.Model.NotificationtestGetElementsV1ResponseMPayload? DefaultOk()
1764+
{
1765+
// NOTICE: Consider this AsModel template deprecated. Implement the appropriate partial method instead
17081766
return IsOk
17091767
? System.Text.Json.JsonSerializer.Deserialize<Org.OpenAPITools.Model.NotificationtestGetElementsV1ResponseMPayload>(RawContent, _jsonSerializerOptions)
17101768
: null;
17111769
}
17121770

1771+
partial void OnOk(ref bool suppressDefault, ref Org.OpenAPITools.Model.NotificationtestGetElementsV1ResponseMPayload? result);
1772+
17131773
/// <summary>
17141774
/// Returns true if the response is 200 Ok and the deserialized response is not null
17151775
/// </summary>

0 commit comments

Comments
 (0)