From 968bef7215c8cb3b9767d59940831e4f2ac8e661 Mon Sep 17 00:00:00 2001 From: Maarten Van Hoof Date: Wed, 7 Apr 2021 15:31:00 +0200 Subject: [PATCH] test(media type): update snapshot --- test/__snapshots__/index.spec.js.snap | 44 +++++++++++++++++++-------- 1 file changed, 32 insertions(+), 12 deletions(-) diff --git a/test/__snapshots__/index.spec.js.snap b/test/__snapshots__/index.spec.js.snap index 488b8b79..93f69f28 100644 --- a/test/__snapshots__/index.spec.js.snap +++ b/test/__snapshots__/index.spec.js.snap @@ -35,6 +35,7 @@ export type ApiRequestOptions = { readonly query?: Record; readonly formData?: Record; readonly body?: any; + readonly bodyMediaType?: string; readonly responseHeader?: string; readonly errors?: Record; }" @@ -180,12 +181,16 @@ async function getHeaders(options: ApiRequestOptions): Promise { } if (options.body) { - if (isBlob(options.body)) { - headers.append('Content-Type', options.body.type || 'application/octet-stream'); - } else if (isString(options.body)) { - headers.append('Content-Type', 'text/plain'); + if (options.bodyMediaType) { + headers.append('Content-Type', options.bodyMediaType); } else { - headers.append('Content-Type', 'application/json'); + if (isBlob(options.body)) { + headers.append('Content-Type', options.body.type || 'application/octet-stream'); + } else if (isString(options.body)) { + headers.append('Content-Type', 'text/plain'); + } else { + headers.append('Content-Type', 'application/json'); + } } } return headers; @@ -196,7 +201,9 @@ function getRequestBody(options: ApiRequestOptions): BodyInit | undefined { return getFormData(options.formData); } if (options.body) { - if (isString(options.body) || isBlob(options.body)) { + if (options.bodyMediaType?.includes('/json')) { + return JSON.stringify(options.body) + } else if (isString(options.body) || isBlob(options.body)) { return options.body; } else { return JSON.stringify(options.body); @@ -2383,6 +2390,7 @@ export type ApiRequestOptions = { readonly query?: Record; readonly formData?: Record; readonly body?: any; + readonly bodyMediaType?: string; readonly responseHeader?: string; readonly errors?: Record; }" @@ -2528,12 +2536,16 @@ async function getHeaders(options: ApiRequestOptions): Promise { } if (options.body) { - if (isBlob(options.body)) { - headers.append('Content-Type', options.body.type || 'application/octet-stream'); - } else if (isString(options.body)) { - headers.append('Content-Type', 'text/plain'); + if (options.bodyMediaType) { + headers.append('Content-Type', options.bodyMediaType); } else { - headers.append('Content-Type', 'application/json'); + if (isBlob(options.body)) { + headers.append('Content-Type', options.body.type || 'application/octet-stream'); + } else if (isString(options.body)) { + headers.append('Content-Type', 'text/plain'); + } else { + headers.append('Content-Type', 'application/json'); + } } } return headers; @@ -2544,7 +2556,9 @@ function getRequestBody(options: ApiRequestOptions): BodyInit | undefined { return getFormData(options.formData); } if (options.body) { - if (isString(options.body) || isBlob(options.body)) { + if (options.bodyMediaType?.includes('/json')) { + return JSON.stringify(options.body) + } else if (isString(options.body) || isBlob(options.body)) { return options.body; } else { return JSON.stringify(options.body); @@ -4481,6 +4495,7 @@ export class ComplexService { method: 'PUT', path: \`/api/v\${OpenAPI.VERSION}/complex/\${id}\`, body: requestBody, + bodyMediaType: 'application/json-patch+json', }); return result.body; } @@ -4777,6 +4792,7 @@ export class ParametersService { 'parameterForm': parameterForm, }, body: requestBody, + bodyMediaType: 'application/json', }); return result.body; } @@ -4821,6 +4837,7 @@ export class ParametersService { 'parameter_form': parameterForm, }, body: requestBody, + bodyMediaType: 'application/json', }); return result.body; } @@ -4841,6 +4858,7 @@ export class ParametersService { 'parameter': parameter, }, body: requestBody, + bodyMediaType: 'application/json', }); return result.body; } @@ -4861,6 +4879,7 @@ export class ParametersService { 'parameter': parameter, }, body: requestBody, + bodyMediaType: 'application/json', }); return result.body; } @@ -4889,6 +4908,7 @@ export class RequestBodyService { method: 'POST', path: \`/api/v\${OpenAPI.VERSION}/requestBody/\`, body: requestBody, + bodyMediaType: 'application/json', }); return result.body; }