fix: code generators (#1985)
Co-authored-by: liyasthomas <liyascthomas@gmail.com>
This commit is contained in:
@@ -21,6 +21,9 @@ export const JavascriptXhrCodegen = {
|
||||
}) => {
|
||||
const requestString = []
|
||||
requestString.push("const xhr = new XMLHttpRequest()")
|
||||
requestString.push(`xhr.addEventListener("readystatechange", function() {`)
|
||||
requestString.push(` if(this.readyState === 4) {`)
|
||||
requestString.push(` console.log(this.responseText)\n }\n})`)
|
||||
|
||||
const user = auth === "Basic Auth" ? `'${httpUser}'` : null
|
||||
const password = auth === "Basic Auth" ? `'${httpPassword}'` : null
|
||||
@@ -40,14 +43,14 @@ export const JavascriptXhrCodegen = {
|
||||
}
|
||||
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
|
||||
let requestBody = rawInput ? rawParams : rawRequestBody
|
||||
if (isJSONContentType(contentType)) {
|
||||
requestBody = `JSON.stringify(${requestBody})`
|
||||
} else if (contentType.includes("x-www-form-urlencoded")) {
|
||||
requestBody = `"${requestBody}"`
|
||||
if (contentType && requestBody) {
|
||||
if (isJSONContentType(contentType)) {
|
||||
requestBody = `JSON.stringify(${requestBody})`
|
||||
} else if (contentType.includes("x-www-form-urlencoded")) {
|
||||
requestBody = `"${requestBody}"`
|
||||
}
|
||||
}
|
||||
requestString.push(
|
||||
`xhr.setRequestHeader('Content-Type', '${contentType}; charset=utf-8')`
|
||||
)
|
||||
requestBody = requestBody || ""
|
||||
requestString.push(`xhr.send(${requestBody})`)
|
||||
} else {
|
||||
requestString.push("xhr.send()")
|
||||
|
||||
Reference in New Issue
Block a user