fix: code generators (#1985)

Co-authored-by: liyasthomas <liyascthomas@gmail.com>
This commit is contained in:
Deepanshu Dhruw
2021-11-30 07:46:45 +05:30
committed by GitHub
parent 2a59557851
commit 520ac8ede5
21 changed files with 285 additions and 263 deletions

View File

@@ -43,16 +43,11 @@ export const NodejsNativeCodegen = {
let requestBody
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
requestBody = rawInput ? rawParams : rawRequestBody
if (isJSONContentType(contentType)) {
if (isJSONContentType(contentType) && requestBody) {
requestBody = `JSON.stringify(${requestBody})`
} else {
} else if (requestBody) {
requestBody = `\`${requestBody}\``
}
if (contentType) {
genHeaders.push(
` "Content-Type": "${contentType}; charset=utf-8",\n`
)
}
}
if (headers) {
@@ -62,7 +57,7 @@ export const NodejsNativeCodegen = {
}
if (genHeaders.length > 0 || headers.length > 0) {
requestString.push(
` headers: {\n${genHeaders.join("").slice(0, -2)}\n }`
` headers: {\n${genHeaders.join("").slice(0, -2)}\n }\n`
)
}
requestString.push(`};\n\n`)