Skip to content

Commit 968bef7

Browse files
committed
test(media type): update snapshot
1 parent ea7f26b commit 968bef7

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

test/__snapshots__/index.spec.js.snap

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export type ApiRequestOptions = {
3535
readonly query?: Record<string, any>;
3636
readonly formData?: Record<string, any>;
3737
readonly body?: any;
38+
readonly bodyMediaType?: string;
3839
readonly responseHeader?: string;
3940
readonly errors?: Record<number, string>;
4041
}"
@@ -180,12 +181,16 @@ async function getHeaders(options: ApiRequestOptions): Promise<Headers> {
180181
}
181182

182183
if (options.body) {
183-
if (isBlob(options.body)) {
184-
headers.append('Content-Type', options.body.type || 'application/octet-stream');
185-
} else if (isString(options.body)) {
186-
headers.append('Content-Type', 'text/plain');
184+
if (options.bodyMediaType) {
185+
headers.append('Content-Type', options.bodyMediaType);
187186
} else {
188-
headers.append('Content-Type', 'application/json');
187+
if (isBlob(options.body)) {
188+
headers.append('Content-Type', options.body.type || 'application/octet-stream');
189+
} else if (isString(options.body)) {
190+
headers.append('Content-Type', 'text/plain');
191+
} else {
192+
headers.append('Content-Type', 'application/json');
193+
}
189194
}
190195
}
191196
return headers;
@@ -196,7 +201,9 @@ function getRequestBody(options: ApiRequestOptions): BodyInit | undefined {
196201
return getFormData(options.formData);
197202
}
198203
if (options.body) {
199-
if (isString(options.body) || isBlob(options.body)) {
204+
if (options.bodyMediaType?.includes('/json')) {
205+
return JSON.stringify(options.body)
206+
} else if (isString(options.body) || isBlob(options.body)) {
200207
return options.body;
201208
} else {
202209
return JSON.stringify(options.body);
@@ -2383,6 +2390,7 @@ export type ApiRequestOptions = {
23832390
readonly query?: Record<string, any>;
23842391
readonly formData?: Record<string, any>;
23852392
readonly body?: any;
2393+
readonly bodyMediaType?: string;
23862394
readonly responseHeader?: string;
23872395
readonly errors?: Record<number, string>;
23882396
}"
@@ -2528,12 +2536,16 @@ async function getHeaders(options: ApiRequestOptions): Promise<Headers> {
25282536
}
25292537

25302538
if (options.body) {
2531-
if (isBlob(options.body)) {
2532-
headers.append('Content-Type', options.body.type || 'application/octet-stream');
2533-
} else if (isString(options.body)) {
2534-
headers.append('Content-Type', 'text/plain');
2539+
if (options.bodyMediaType) {
2540+
headers.append('Content-Type', options.bodyMediaType);
25352541
} else {
2536-
headers.append('Content-Type', 'application/json');
2542+
if (isBlob(options.body)) {
2543+
headers.append('Content-Type', options.body.type || 'application/octet-stream');
2544+
} else if (isString(options.body)) {
2545+
headers.append('Content-Type', 'text/plain');
2546+
} else {
2547+
headers.append('Content-Type', 'application/json');
2548+
}
25372549
}
25382550
}
25392551
return headers;
@@ -2544,7 +2556,9 @@ function getRequestBody(options: ApiRequestOptions): BodyInit | undefined {
25442556
return getFormData(options.formData);
25452557
}
25462558
if (options.body) {
2547-
if (isString(options.body) || isBlob(options.body)) {
2559+
if (options.bodyMediaType?.includes('/json')) {
2560+
return JSON.stringify(options.body)
2561+
} else if (isString(options.body) || isBlob(options.body)) {
25482562
return options.body;
25492563
} else {
25502564
return JSON.stringify(options.body);
@@ -4481,6 +4495,7 @@ export class ComplexService {
44814495
method: 'PUT',
44824496
path: \`/api/v\${OpenAPI.VERSION}/complex/\${id}\`,
44834497
body: requestBody,
4498+
bodyMediaType: 'application/json-patch+json',
44844499
});
44854500
return result.body;
44864501
}
@@ -4777,6 +4792,7 @@ export class ParametersService {
47774792
'parameterForm': parameterForm,
47784793
},
47794794
body: requestBody,
4795+
bodyMediaType: 'application/json',
47804796
});
47814797
return result.body;
47824798
}
@@ -4821,6 +4837,7 @@ export class ParametersService {
48214837
'parameter_form': parameterForm,
48224838
},
48234839
body: requestBody,
4840+
bodyMediaType: 'application/json',
48244841
});
48254842
return result.body;
48264843
}
@@ -4841,6 +4858,7 @@ export class ParametersService {
48414858
'parameter': parameter,
48424859
},
48434860
body: requestBody,
4861+
bodyMediaType: 'application/json',
48444862
});
48454863
return result.body;
48464864
}
@@ -4861,6 +4879,7 @@ export class ParametersService {
48614879
'parameter': parameter,
48624880
},
48634881
body: requestBody,
4882+
bodyMediaType: 'application/json',
48644883
});
48654884
return result.body;
48664885
}
@@ -4889,6 +4908,7 @@ export class RequestBodyService {
48894908
method: 'POST',
48904909
path: \`/api/v\${OpenAPI.VERSION}/requestBody/\`,
48914910
body: requestBody,
4911+
bodyMediaType: 'application/json',
48924912
});
48934913
return result.body;
48944914
}

0 commit comments

Comments
 (0)