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

@@ -31,8 +31,9 @@ export const JavaUnirestCodegen = {
]
// create client and request
const verb = verbs.find((v) => v.verb === method)
const unirestMethod = verb.unirestMethod || "get"
requestString.push(
`HttpResponse<String> response = Unirest.${verb.unirestMethod}("${url}${pathName}?${queryString}")\n`
`HttpResponse<String> response = Unirest.${unirestMethod}("${url}${pathName}?${queryString}")\n`
)
if (auth === "Basic Auth") {
const basic = `${httpUser}:${httpPassword}`
@@ -52,21 +53,21 @@ export const JavaUnirestCodegen = {
}
})
}
if (contentType) {
requestString.push(`.header("Content-Type", "${contentType}")\n`)
}
// set body
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
if (contentType.includes("x-www-form-urlencoded")) {
requestBody = `"${requestBody}"`
} else {
requestBody = JSON.stringify(requestBody)
if (contentType && requestBody) {
if (contentType.includes("x-www-form-urlencoded")) {
requestBody = `"${requestBody}"`
} else {
requestBody = JSON.stringify(requestBody)
}
}
if (requestBody) {
requestString.push(`.body(${requestBody})\n`)
}
requestString.push(`.body(${requestBody})`)
}
requestString.push(`\n.asString();\n`)
requestString.push(`.asString();\n`)
return requestString.join("")
},
}