Skip to content

Commit

Permalink
replace empty request body
Browse files Browse the repository at this point in the history
  • Loading branch information
Manweill committed Mar 15, 2024
1 parent 594733e commit d5ec58a
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/templates/template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,23 +238,25 @@ ${options.useStaticMethod ? 'static' : ''} ${camelcase(
}

function requestBodyString(method: string, parsedParameters: [], bodyParameter: [], requestBody: string, contentType: string, formData: string) {
let tips = ''
if (method != 'post' && method != 'put') {
tips = `/** 适配移动开发(iOS13 等版本),只有 POST、PUT 等请求允许带body */ \n
console.warn('适配移动开发(iOS13 等版本),只有 POST、PUT 等请求允许带body')
`
}
return `
${tips}
if (parsedParameters && bodyParameter && bodyParameter.length > 0 || !!requestBody || formData.length > 0) {

const tips = `/** 适配移动开发(iOS13 等版本),只有 POST、PUT 等请求允许带body */ \n
console.warn('适配移动开发(iOS13 等版本),只有 POST、PUT 等请求允许带body')`
return `
${method === 'post' || method === 'put' ? '' : tips}
let data = ${parsedParameters && bodyParameter && bodyParameter.length > 0
?
bodyParameter
: !!requestBody
? 'params.body'
: 'null'
}
?
bodyParameter
: !!requestBody
? 'params.body'
: 'null'
}
${contentType === 'multipart/form-data' ? formData : ''}
configs.data = data;`
}
return ''
}

/** serviceTemplate */
Expand Down

0 comments on commit d5ec58a

Please sign in to comment.