Skip to content

Commit 32ff947

Browse files
committed
Fix undefined request body when body === false or 0, "" in other clients
1 parent aa20f9e commit 32ff947

File tree

3 files changed

+4
-5
lines changed

3 files changed

+4
-5
lines changed

src/templates/core/node/getRequestBody.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const getRequestBody = (options: ApiRequestOptions): any => {
2-
if (options.body) {
2+
if (options.body !== undefined) {
33
if (options.mediaType?.includes('/json')) {
44
return JSON.stringify(options.body)
55
} else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const getRequestBody = (options: ApiRequestOptions): any => {
2-
if (options.body) {
2+
if (options.body !== undefined) {
33
if (options.mediaType?.includes('/json')) {
44
return JSON.stringify(options.body)
55
} else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
@@ -8,6 +8,5 @@ const getRequestBody = (options: ApiRequestOptions): any => {
88
return JSON.stringify(options.body);
99
}
1010
}
11-
1211
return undefined;
1312
};

test/__snapshots__/index.spec.ts.snap

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
409409
};
410410

411411
const getRequestBody = (options: ApiRequestOptions): any => {
412-
if (options.body) {
412+
if (options.body !== undefined) {
413413
if (options.mediaType?.includes('/json')) {
414414
return JSON.stringify(options.body)
415415
} else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {
@@ -3468,7 +3468,7 @@ const getHeaders = async (config: OpenAPIConfig, options: ApiRequestOptions): Pr
34683468
};
34693469

34703470
const getRequestBody = (options: ApiRequestOptions): any => {
3471-
if (options.body) {
3471+
if (options.body !== undefined) {
34723472
if (options.mediaType?.includes('/json')) {
34733473
return JSON.stringify(options.body)
34743474
} else if (isString(options.body) || isBlob(options.body) || isFormData(options.body)) {

0 commit comments

Comments
 (0)