-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
[csharp][generichost] Refactor AsModel template #24650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // This logic may be modified with the AsModel.mustache template | ||
| // NOTICE: Consider this AsModel template deprecated. Implement the appropriate partial method instead | ||
| return Is{{vendorExtensions.x-http-status}} | ||
| ? {{#isBinary}}ContentStream{{/isBinary}}{{^isBinary}}System.Text.Json.JsonSerializer.Deserialize<{{#isModel}}{{^containerType}}{{packageName}}.{{modelPackage}}.{{/containerType}}{{/isModel}}{{{dataType}}}>(RawContent, _jsonSerializerOptions){{/isBinary}} | ||
| : {{#net60OrLater}}null{{/net60OrLater}}{{^net60OrLater}}default{{/net60OrLater}}; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -331,12 +331,24 @@ public GetWidgetApiResponse(ILogger<DefaultApi> logger, System.Net.Http.HttpRequ | |
| /// <returns></returns> | ||
| public Org.OpenAPITools.Model.Widget? Ok() | ||
| { | ||
| // This logic may be modified with the AsModel.mustache template | ||
| bool suppressDefault = false; | ||
| Org.OpenAPITools.Model.Widget? result = null; | ||
| OnOk(ref suppressDefault, ref result); | ||
| if (!suppressDefault) | ||
| result = DefaultOk(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The hook silently discards a caller's patched Prompt for AI agents |
||
| return result; | ||
| } | ||
|
|
||
| private Org.OpenAPITools.Model.Widget? DefaultOk() | ||
| { | ||
| // NOTICE: Consider this AsModel template deprecated. Implement the appropriate partial method instead | ||
| return IsOk | ||
| ? System.Text.Json.JsonSerializer.Deserialize<Org.OpenAPITools.Model.Widget>(RawContent, _jsonSerializerOptions) | ||
| : null; | ||
| } | ||
|
|
||
| partial void OnOk(ref bool suppressDefault, ref Org.OpenAPITools.Model.Widget? result); | ||
|
devhl-labs marked this conversation as resolved.
|
||
|
|
||
| /// <summary> | ||
| /// Returns true if the response is 200 Ok and the deserialized response is not null | ||
| /// </summary> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: The Ok() flow re-runs DefaultOk() after the OnOk hook whenever suppressDefault is false. If a hook follows the documented "set result = DefaultOk() first, then patch, while letting DefaultOk run" guidance, the response body is deserialized twice and the second DefaultOk() overwrites the patched result, silently discarding the customization. The guide should instruct hooks to set suppressDefault = true after calling DefaultOk(), or the hook should be the single deserialization point.
Prompt for AI agents