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

@@ -26,16 +26,26 @@ export const JavaOkhttpCodegen = {
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
let requestBody = rawInput ? rawParams : rawRequestBody
if (contentType.includes("x-www-form-urlencoded")) {
if (contentType && contentType.includes("x-www-form-urlencoded")) {
requestBody = `"${requestBody}"`
} else requestBody = JSON.stringify(requestBody)
} else {
requestBody = requestBody ? JSON.stringify(requestBody) : null
}
requestString.push(
`MediaType mediaType = MediaType.parse("${contentType}");`
)
requestString.push(
`RequestBody body = RequestBody.create(mediaType,${requestBody});`
)
if (contentType) {
requestString.push(
`MediaType mediaType = MediaType.parse("${contentType}");`
)
}
if (requestBody) {
requestString.push(
`RequestBody body = RequestBody.create(mediaType,${requestBody});`
)
} else {
requestString.push(
"RequestBody body = RequestBody.create(null, new byte[0]);"
)
}
}
requestString.push("Request request = new Request.Builder()")