Skip to content

Commit 9fd665b

Browse files
Copilotkazrael2119
andauthored
fix: update modularUnit scenario to test response-side */* + bytes deserialization
Agent-Logs-Url: https://github.com/Azure/autorest.typescript/sessions/91d71912-6e66-4c90-a423-3556edeb1ce8 Co-authored-by: kazrael2119 <98569699+kazrael2119@users.noreply.github.com>
1 parent e1c5f7c commit 9fd665b

1 file changed

Lines changed: 21 additions & 12 deletions

File tree

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,24 @@
1-
# bytes body with */* content type should be treated as binary
1+
# bytes response with */* content type should be treated as binary
22

3-
When an operation has `*/* ` content type and a `bytes` body, `isBinaryPayload` should return
4-
`true` so the parameter is typed as `Uint8Array` (binary) rather than `string` (base64).
3+
When a response has `*/*` content type and a `bytes` body, `isBinaryPayload` should return
4+
`true` so the response is deserialized as `Uint8Array` (binary) rather than `string` (base64).
55

66
## TypeSpec
77

88
```tsp
99
@post op uploadFile(
10+
@body body: string
11+
): {
1012
@header contentType: "*/*",
1113
@body body: bytes
12-
): void;
14+
};
1315
```
1416

1517
## Operations
1618

1719
```ts operations
1820
import { TestingContext as Client } from "./index.js";
21+
import { getBinaryResponse } from "../static-helpers/serialization/get-binary-response.js";
1922
import { UploadFileOptionalParams } from "./options.js";
2023
import {
2124
StreamableMethod,
@@ -26,29 +29,35 @@ import {
2629

2730
export function _uploadFileSend(
2831
context: Client,
29-
body: Uint8Array,
32+
body: string,
3033
options: UploadFileOptionalParams = { requestOptions: {} },
3134
): StreamableMethod {
3235
return context
3336
.path("/")
34-
.post({ ...operationOptionsToRequestParameters(options), contentType: "*/*", body: body });
37+
.post({
38+
...operationOptionsToRequestParameters(options),
39+
contentType: "text/plain",
40+
headers: { accept: "*/*", ...options.requestOptions?.headers },
41+
body: body,
42+
});
3543
}
3644

37-
export async function _uploadFileDeserialize(result: PathUncheckedResponse): Promise<void> {
38-
const expectedStatuses = ["204"];
45+
export async function _uploadFileDeserialize(result: PathUncheckedResponse): Promise<Uint8Array> {
46+
const expectedStatuses = ["200"];
3947
if (!expectedStatuses.includes(result.status)) {
4048
throw createRestError(result);
4149
}
4250

43-
return;
51+
return result.body;
4452
}
4553

4654
export async function uploadFile(
4755
context: Client,
48-
body: Uint8Array,
56+
body: string,
4957
options: UploadFileOptionalParams = { requestOptions: {} },
50-
): Promise<void> {
51-
const result = await _uploadFileSend(context, body, options);
58+
): Promise<Uint8Array> {
59+
const streamableMethod = _uploadFileSend(context, body, options);
60+
const result = await getBinaryResponse(streamableMethod);
5261
return _uploadFileDeserialize(result);
5362
}
5463
```

0 commit comments

Comments
 (0)