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
1820import { TestingContext as Client } from " ./index.js" ;
21+ import { getBinaryResponse } from " ../static-helpers/serialization/get-binary-response.js" ;
1922import { UploadFileOptionalParams } from " ./options.js" ;
2023import {
2124 StreamableMethod ,
@@ -26,29 +29,35 @@ import {
2629
2730export 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
4654export 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