Fix deserializer throwing on empty response body (success and error paths)#3948
Fix deserializer throwing on empty response body (success and error paths)#3948Copilot wants to merge 11 commits into
Conversation
Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/9cea75e6-362d-497d-b471-3d26d5fe7ecf Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>
|
@copilot fix smoke test and integration test error. |
…or-path body guard Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/45ad9841-31d3-4494-a8a8-045ffbf9684c Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>
Fixed in a362d34. The CI failures were caused by the emitter changes regenerating different output (adding |
|
@copilot run |
Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/dd967836-7410-40c5-85ee-58d7bc40411f Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>
|
@copilot fix integration test ci error. |
Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/94b2b2ef-70d7-49cb-af43-a8fea6ebdbd8 Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>
Ran
Fixed in a6a3939. The
Regenerated all 4 integration test sets and committed the missing files. |
| } | ||
| ``` | ||
|
|
||
| # Error path deserializer handles empty body (no body on error response) |
There was a problem hiding this comment.
Could you add another case where there are both empty body response and error response?
There was a problem hiding this comment.
Added in 8b66451. The new scenario covers an operation that returns 200 with a KeyValue body, 204 with no body, or a ServiceError — exercising both the success-path body guard (if (!result.body)) and the error-path body guard (if (result.body) { error.details = ... }) together.
| if (!result.body) { | ||
| return result.body as KeyValue | undefined; | ||
| } | ||
|
|
||
| return keyValueDeserializer(result.body); |
There was a problem hiding this comment.
Can these lines be simplified as
return result.body ? keyValueDeserializer(result.body) : undefined;
There was a problem hiding this comment.
Applied in 4fcb15c. The emitter now generates the ternary form return result.body ? deserializer(result.body) : undefined for the JSON path when the response is optional. The if (!result.body) guard is moved into the XML/dual-format branches where it's still needed. armPatchWithUnionResponse.md was also updated to reflect the new output.
Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/edf2ea05-e029-419b-b517-50c8ad04128c Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>
…lizer(result.body) : undefined Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/33c8fdc1-5862-4a7d-9291-235114985f10 Co-authored-by: v-jiaodi <80496810+v-jiaodi@users.noreply.github.com>
pnpm formatto fix CI formatting errorscheck:treefails because.api.mdreview files inpackages/typespec-test/were committed with CRLF line endings, but.gitattributesenforceseol=lf.api.mdfiles with correct LF line endings.api.mdfiles socheck:treepasses in CIfixes [typespec-ts] Deserializer Throwing An Error on Empty Body #3937