Skip to content

Commit b1a3658

Browse files
author
Fransis Young
committed
test(client): updates snapshots
refs: #2553
1 parent 7c3e725 commit b1a3658

File tree

139 files changed

+3475
-834
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+3475
-834
lines changed

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/body-response-text-plain/client/client.gen.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,15 @@ export const createClient = (config: Config = {}): Client => {
6060
await opts.requestValidator(opts);
6161
}
6262

63-
if (opts.body && opts.bodySerializer) {
63+
if (opts.body !== undefined && opts.bodySerializer) {
6464
opts.serializedBody = opts.bodySerializer(opts.body);
6565
}
6666

6767
// remove Content-Type header if body is empty to avoid sending invalid requests
68-
if (opts.body === undefined || opts.body === '') {
68+
if (
69+
opts.body === undefined ||
70+
(opts.serializedBody !== undefined && opts.serializedBody === '')
71+
) {
6972
opts.headers.delete('Content-Type');
7073
}
7174

@@ -80,12 +83,9 @@ export const createClient = (config: Config = {}): Client => {
8083
const requestInit: ReqInit = {
8184
redirect: 'follow',
8285
...opts,
86+
body: getValidRequestBody(opts),
8387
};
8488

85-
if (opts.serializedBody) {
86-
requestInit.body = opts.serializedBody;
87-
}
88-
8989
let request = new Request(url, requestInit);
9090

9191
for (const fn of interceptors.request._fns) {
@@ -215,6 +215,25 @@ export const createClient = (config: Config = {}): Client => {
215215
};
216216
};
217217

218+
function getValidRequestBody(options: ResolvedRequestOptions) {
219+
const hasBody = options.body !== undefined;
220+
const isSerializedBody = hasBody && options.bodySerializer;
221+
222+
if (isSerializedBody) {
223+
const hasSerializedBody =
224+
options.serializedBody !== undefined && options.serializedBody !== '';
225+
226+
return hasSerializedBody ? options.serializedBody : null;
227+
}
228+
229+
// plain/text body
230+
if (hasBody) {
231+
return options.body;
232+
}
233+
234+
return null;
235+
}
236+
218237
const makeMethodFn =
219238
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
220239
request({ ...options, method });

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/form-data/client/client.gen.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,15 @@ export const createClient = (config: Config = {}): Client => {
6060
await opts.requestValidator(opts);
6161
}
6262

63-
if (opts.body && opts.bodySerializer) {
63+
if (opts.body !== undefined && opts.bodySerializer) {
6464
opts.serializedBody = opts.bodySerializer(opts.body);
6565
}
6666

6767
// remove Content-Type header if body is empty to avoid sending invalid requests
68-
if (opts.body === undefined || opts.body === '') {
68+
if (
69+
opts.body === undefined ||
70+
(opts.serializedBody !== undefined && opts.serializedBody === '')
71+
) {
6972
opts.headers.delete('Content-Type');
7073
}
7174

@@ -80,12 +83,9 @@ export const createClient = (config: Config = {}): Client => {
8083
const requestInit: ReqInit = {
8184
redirect: 'follow',
8285
...opts,
86+
body: getValidRequestBody(opts),
8387
};
8488

85-
if (opts.serializedBody) {
86-
requestInit.body = opts.serializedBody;
87-
}
88-
8989
let request = new Request(url, requestInit);
9090

9191
for (const fn of interceptors.request._fns) {
@@ -215,6 +215,25 @@ export const createClient = (config: Config = {}): Client => {
215215
};
216216
};
217217

218+
function getValidRequestBody(options: ResolvedRequestOptions) {
219+
const hasBody = options.body !== undefined;
220+
const isSerializedBody = hasBody && options.bodySerializer;
221+
222+
if (isSerializedBody) {
223+
const hasSerializedBody =
224+
options.serializedBody !== undefined && options.serializedBody !== '';
225+
226+
return hasSerializedBody ? options.serializedBody : null;
227+
}
228+
229+
// plain/text body
230+
if (hasBody) {
231+
return options.body;
232+
}
233+
234+
return null;
235+
}
236+
218237
const makeMethodFn =
219238
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
220239
request({ ...options, method });

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes-instance/client/client.gen.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,15 @@ export const createClient = (config: Config = {}): Client => {
6060
await opts.requestValidator(opts);
6161
}
6262

63-
if (opts.body && opts.bodySerializer) {
63+
if (opts.body !== undefined && opts.bodySerializer) {
6464
opts.serializedBody = opts.bodySerializer(opts.body);
6565
}
6666

6767
// remove Content-Type header if body is empty to avoid sending invalid requests
68-
if (opts.body === undefined || opts.body === '') {
68+
if (
69+
opts.body === undefined ||
70+
(opts.serializedBody !== undefined && opts.serializedBody === '')
71+
) {
6972
opts.headers.delete('Content-Type');
7073
}
7174

@@ -80,12 +83,9 @@ export const createClient = (config: Config = {}): Client => {
8083
const requestInit: ReqInit = {
8184
redirect: 'follow',
8285
...opts,
86+
body: getValidRequestBody(opts),
8387
};
8488

85-
if (opts.serializedBody) {
86-
requestInit.body = opts.serializedBody;
87-
}
88-
8989
let request = new Request(url, requestInit);
9090

9191
for (const fn of interceptors.request._fns) {
@@ -215,6 +215,25 @@ export const createClient = (config: Config = {}): Client => {
215215
};
216216
};
217217

218+
function getValidRequestBody(options: ResolvedRequestOptions) {
219+
const hasBody = options.body !== undefined;
220+
const isSerializedBody = hasBody && options.bodySerializer;
221+
222+
if (isSerializedBody) {
223+
const hasSerializedBody =
224+
options.serializedBody !== undefined && options.serializedBody !== '';
225+
226+
return hasSerializedBody ? options.serializedBody : null;
227+
}
228+
229+
// plain/text body
230+
if (hasBody) {
231+
return options.body;
232+
}
233+
234+
return null;
235+
}
236+
218237
const makeMethodFn =
219238
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
220239
request({ ...options, method });

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/client-fetch/sdk-nested-classes/client/client.gen.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,15 @@ export const createClient = (config: Config = {}): Client => {
6060
await opts.requestValidator(opts);
6161
}
6262

63-
if (opts.body && opts.bodySerializer) {
63+
if (opts.body !== undefined && opts.bodySerializer) {
6464
opts.serializedBody = opts.bodySerializer(opts.body);
6565
}
6666

6767
// remove Content-Type header if body is empty to avoid sending invalid requests
68-
if (opts.body === undefined || opts.body === '') {
68+
if (
69+
opts.body === undefined ||
70+
(opts.serializedBody !== undefined && opts.serializedBody === '')
71+
) {
6972
opts.headers.delete('Content-Type');
7073
}
7174

@@ -80,12 +83,9 @@ export const createClient = (config: Config = {}): Client => {
8083
const requestInit: ReqInit = {
8184
redirect: 'follow',
8285
...opts,
86+
body: getValidRequestBody(opts),
8387
};
8488

85-
if (opts.serializedBody) {
86-
requestInit.body = opts.serializedBody;
87-
}
88-
8989
let request = new Request(url, requestInit);
9090

9191
for (const fn of interceptors.request._fns) {
@@ -215,6 +215,25 @@ export const createClient = (config: Config = {}): Client => {
215215
};
216216
};
217217

218+
function getValidRequestBody(options: ResolvedRequestOptions) {
219+
const hasBody = options.body !== undefined;
220+
const isSerializedBody = hasBody && options.bodySerializer;
221+
222+
if (isSerializedBody) {
223+
const hasSerializedBody =
224+
options.serializedBody !== undefined && options.serializedBody !== '';
225+
226+
return hasSerializedBody ? options.serializedBody : null;
227+
}
228+
229+
// plain/text body
230+
if (hasBody) {
231+
return options.body;
232+
}
233+
234+
return null;
235+
}
236+
218237
const makeMethodFn =
219238
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
220239
request({ ...options, method });

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/default/client/client.gen.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,15 @@ export const createClient = (config: Config = {}): Client => {
6060
await opts.requestValidator(opts);
6161
}
6262

63-
if (opts.body && opts.bodySerializer) {
63+
if (opts.body !== undefined && opts.bodySerializer) {
6464
opts.serializedBody = opts.bodySerializer(opts.body);
6565
}
6666

6767
// remove Content-Type header if body is empty to avoid sending invalid requests
68-
if (opts.body === undefined || opts.body === '') {
68+
if (
69+
opts.body === undefined ||
70+
(opts.serializedBody !== undefined && opts.serializedBody === '')
71+
) {
6972
opts.headers.delete('Content-Type');
7073
}
7174

@@ -80,12 +83,9 @@ export const createClient = (config: Config = {}): Client => {
8083
const requestInit: ReqInit = {
8184
redirect: 'follow',
8285
...opts,
86+
body: getValidRequestBody(opts),
8387
};
8488

85-
if (opts.serializedBody) {
86-
requestInit.body = opts.serializedBody;
87-
}
88-
8989
let request = new Request(url, requestInit);
9090

9191
for (const fn of interceptors.request._fns) {
@@ -215,6 +215,25 @@ export const createClient = (config: Config = {}): Client => {
215215
};
216216
};
217217

218+
function getValidRequestBody(options: ResolvedRequestOptions) {
219+
const hasBody = options.body !== undefined;
220+
const isSerializedBody = hasBody && options.bodySerializer;
221+
222+
if (isSerializedBody) {
223+
const hasSerializedBody =
224+
options.serializedBody !== undefined && options.serializedBody !== '';
225+
226+
return hasSerializedBody ? options.serializedBody : null;
227+
}
228+
229+
// plain/text body
230+
if (hasBody) {
231+
return options.body;
232+
}
233+
234+
return null;
235+
}
236+
218237
const makeMethodFn =
219238
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
220239
request({ ...options, method });

packages/openapi-ts-tests/main/test/__snapshots__/2.0.x/plugins/@hey-api/sdk/instance/client/client.gen.ts

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,15 @@ export const createClient = (config: Config = {}): Client => {
6060
await opts.requestValidator(opts);
6161
}
6262

63-
if (opts.body && opts.bodySerializer) {
63+
if (opts.body !== undefined && opts.bodySerializer) {
6464
opts.serializedBody = opts.bodySerializer(opts.body);
6565
}
6666

6767
// remove Content-Type header if body is empty to avoid sending invalid requests
68-
if (opts.body === undefined || opts.body === '') {
68+
if (
69+
opts.body === undefined ||
70+
(opts.serializedBody !== undefined && opts.serializedBody === '')
71+
) {
6972
opts.headers.delete('Content-Type');
7073
}
7174

@@ -80,12 +83,9 @@ export const createClient = (config: Config = {}): Client => {
8083
const requestInit: ReqInit = {
8184
redirect: 'follow',
8285
...opts,
86+
body: getValidRequestBody(opts),
8387
};
8488

85-
if (opts.serializedBody) {
86-
requestInit.body = opts.serializedBody;
87-
}
88-
8989
let request = new Request(url, requestInit);
9090

9191
for (const fn of interceptors.request._fns) {
@@ -215,6 +215,25 @@ export const createClient = (config: Config = {}): Client => {
215215
};
216216
};
217217

218+
function getValidRequestBody(options: ResolvedRequestOptions) {
219+
const hasBody = options.body !== undefined;
220+
const isSerializedBody = hasBody && options.bodySerializer;
221+
222+
if (isSerializedBody) {
223+
const hasSerializedBody =
224+
options.serializedBody !== undefined && options.serializedBody !== '';
225+
226+
return hasSerializedBody ? options.serializedBody : null;
227+
}
228+
229+
// plain/text body
230+
if (hasBody) {
231+
return options.body;
232+
}
233+
234+
return null;
235+
}
236+
218237
const makeMethodFn =
219238
(method: Uppercase<HttpMethod>) => (options: RequestOptions) =>
220239
request({ ...options, method });

0 commit comments

Comments
 (0)