Skip to content

Commit d5ec58a

Browse files
committed
replace empty request body
1 parent 594733e commit d5ec58a

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/templates/template.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -238,23 +238,25 @@ ${options.useStaticMethod ? 'static' : ''} ${camelcase(
238238
}
239239

240240
function requestBodyString(method: string, parsedParameters: [], bodyParameter: [], requestBody: string, contentType: string, formData: string) {
241-
let tips = ''
242-
if (method != 'post' && method != 'put') {
243-
tips = `/** 适配移动开发(iOS13 等版本),只有 POST、PUT 等请求允许带body */ \n
244-
console.warn('适配移动开发(iOS13 等版本),只有 POST、PUT 等请求允许带body')
245-
`
246-
}
247-
return `
248-
${tips}
241+
if (parsedParameters && bodyParameter && bodyParameter.length > 0 || !!requestBody || formData.length > 0) {
242+
243+
const tips = `/** 适配移动开发(iOS13 等版本),只有 POST、PUT 等请求允许带body */ \n
244+
console.warn('适配移动开发(iOS13 等版本),只有 POST、PUT 等请求允许带body')`
245+
return `
246+
247+
${method === 'post' || method === 'put' ? '' : tips}
248+
249249
let data = ${parsedParameters && bodyParameter && bodyParameter.length > 0
250-
?
251-
bodyParameter
252-
: !!requestBody
253-
? 'params.body'
254-
: 'null'
255-
}
250+
?
251+
bodyParameter
252+
: !!requestBody
253+
? 'params.body'
254+
: 'null'
255+
}
256256
${contentType === 'multipart/form-data' ? formData : ''}
257257
configs.data = data;`
258+
}
259+
return ''
258260
}
259261

260262
/** serviceTemplate */

0 commit comments

Comments
 (0)