refactor: lint

This commit is contained in:
liyasthomas
2021-05-18 14:57:29 +05:30
parent 7f248da0b3
commit cc27c552af
84 changed files with 1444 additions and 973 deletions

View File

@@ -8,7 +8,7 @@ const TEST_HTTP_PASSWORD = "mockPassword"
const TEST_BEARER_TOKEN = "abcdefghijklmn"
const TEST_RAW_REQUEST_BODY = "foo=bar&baz=qux"
const TEST_RAW_PARAMS_JSON = '{"foo": "bar", "baz": "qux"}'
const TEST_RAW_PARAMS_XML = `<?xml version=\'1.0\' encoding=\'utf-8\'?>
const TEST_RAW_PARAMS_XML = `<?xml version='1.0' encoding='utf-8'?>
<xml>
<element foo="bar"></element>
</xml>`

View File

@@ -20,13 +20,20 @@ export const CLibcurlCodegen = {
const requestString = []
requestString.push("CURL *hnd = curl_easy_init();")
requestString.push(`curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "${method}");`)
requestString.push(`curl_easy_setopt(hnd, CURLOPT_URL, "${url}${pathName}${queryString}");`)
requestString.push(
`curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "${method}");`
)
requestString.push(
`curl_easy_setopt(hnd, CURLOPT_URL, "${url}${pathName}${queryString}");`
)
requestString.push(`struct curl_slist *headers = NULL;`)
if (headers) {
headers.forEach(({ key, value }) => {
if (key) requestString.push(`headers = curl_slist_append(headers, "${key}: ${value}");`)
if (key)
requestString.push(
`headers = curl_slist_append(headers, "${key}: ${value}");`
)
})
}
@@ -50,10 +57,15 @@ export const CLibcurlCodegen = {
requestBody = `"${requestBody}"`
} else requestBody = JSON.stringify(requestBody)
requestString.push(`headers = curl_slist_append(headers, "Content-Type: ${contentType}");`)
requestString.push(
`headers = curl_slist_append(headers, "Content-Type: ${contentType}");`
)
requestString.push("curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);")
requestString.push(
`curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, ${requestBody});`
)
} else
requestString.push("curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);")
requestString.push(`curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, ${requestBody});`)
} else requestString.push("curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);")
requestString.push(`CURLcode ret = curl_easy_perform(hnd);`)
return requestString.join("\n")

View File

@@ -57,12 +57,16 @@ export const CsRestsharpCodegen = {
`client.Authenticator = new HttpBasicAuthenticator("${httpUser}", "${httpPassword}");\n`
)
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
requestString.push(`request.AddHeader("Authorization", "Bearer ${bearerToken}");\n`)
requestString.push(
`request.AddHeader("Authorization", "Bearer ${bearerToken}");\n`
)
}
// content type
if (contentType) {
requestString.push(`request.AddHeader("Content-Type", "${contentType}");\n`)
requestString.push(
`request.AddHeader("Content-Type", "${contentType}");\n`
)
}
// custom headers

View File

@@ -23,7 +23,9 @@ export const CurlCodegen = {
if (auth === "Basic Auth") {
const basic = `${httpUser}:${httpPassword}`
requestString.push(
` -H 'Authorization: Basic ${window.btoa(unescape(encodeURIComponent(basic)))}'`
` -H 'Authorization: Basic ${window.btoa(
unescape(encodeURIComponent(basic))
)}'`
)
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
requestString.push(` -H 'Authorization: Bearer ${bearerToken}'`)

View File

@@ -22,8 +22,8 @@ export const GoNativeCodegen = {
const requestString = []
let genHeaders = []
// initial request setup
let requestBody = rawInput ? rawParams : rawRequestBody
if (method == "GET") {
const requestBody = rawInput ? rawParams : rawRequestBody
if (method === "GET") {
requestString.push(
`req, err := http.NewRequest("${method}", "${url}${pathName}${queryString}")\n`
)
@@ -52,7 +52,9 @@ export const GoNativeCodegen = {
)}")\n`
)
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
genHeaders.push(`req.Header.Set("Authorization", "Bearer ${bearerToken}")\n`)
genHeaders.push(
`req.Header.Set("Authorization", "Bearer ${bearerToken}")\n`
)
}
// custom headers
if (headers) {
@@ -62,7 +64,9 @@ export const GoNativeCodegen = {
}
genHeaders = genHeaders.join("").slice(0, -1)
requestString.push(`${genHeaders}\n`)
requestString.push(`if err != nil {\n log.Fatalf("An Error Occured %v", err)\n}\n\n`)
requestString.push(
`if err != nil {\n log.Fatalf("An Error Occured %v", err)\n}\n\n`
)
// request boilerplate
requestString.push(`client := &http.Client{}\n`)

View File

@@ -19,7 +19,9 @@ export const JavaOkhttpCodegen = {
}) => {
const requestString = []
requestString.push("OkHttpClient client = new OkHttpClient().newBuilder().build();")
requestString.push(
"OkHttpClient client = new OkHttpClient().newBuilder().build();"
)
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
let requestBody = rawInput ? rawParams : rawRequestBody
@@ -28,17 +30,21 @@ export const JavaOkhttpCodegen = {
requestBody = `"${requestBody}"`
} else requestBody = JSON.stringify(requestBody)
requestString.push(`MediaType mediaType = MediaType.parse("${contentType}");`)
requestString.push(`RequestBody body = RequestBody.create(mediaType,${requestBody});`)
requestString.push(
`MediaType mediaType = MediaType.parse("${contentType}");`
)
requestString.push(
`RequestBody body = RequestBody.create(mediaType,${requestBody});`
)
}
requestString.push("Request request = new Request.Builder()")
requestString.push(`.url(\"${url}${pathName}${queryString}\")`)
requestString.push(`.url("${url}${pathName}${queryString}")`)
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
requestString.push(`.method(\"${method}\", body)`)
requestString.push(`.method("${method}", body)`)
} else {
requestString.push(`.method(\"${method}\", null)`)
requestString.push(`.method("${method}", null)`)
}
if (auth === "Basic Auth") {
@@ -49,12 +55,14 @@ export const JavaOkhttpCodegen = {
)}") \n`
)
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
requestString.push(`.addHeader("authorization", "Bearer ${bearerToken}" ) \n`)
requestString.push(
`.addHeader("authorization", "Bearer ${bearerToken}" ) \n`
)
}
if (headers) {
headers.forEach(({ key, value }) => {
if (key) requestString.push(`.addHeader(\"${key}\", \"${value}\")`)
if (key) requestString.push(`.addHeader("${key}", "${value}")`)
})
}

View File

@@ -37,7 +37,9 @@ export const JavaUnirestCodegen = {
if (auth === "Basic Auth") {
const basic = `${httpUser}:${httpPassword}`
requestString.push(
`.header("authorization", "Basic ${window.btoa(unescape(encodeURIComponent(basic)))}") \n`
`.header("authorization", "Basic ${window.btoa(
unescape(encodeURIComponent(basic))
)}") \n`
)
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
requestString.push(`.header("authorization", "Bearer ${bearerToken}") \n`)

View File

@@ -26,7 +26,9 @@ export const JavascriptFetchCodegen = {
if (auth === "Basic Auth") {
const basic = `${httpUser}:${httpPassword}`
genHeaders.push(
` "Authorization": "Basic ${window.btoa(unescape(encodeURIComponent(basic)))}",\n`
` "Authorization": "Basic ${window.btoa(
unescape(encodeURIComponent(basic))
)}",\n`
)
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
genHeaders.push(` "Authorization": "Bearer ${bearerToken}",\n`)

View File

@@ -18,9 +18,11 @@ export const JavascriptJqueryCodegen = {
headers,
}) => {
const requestString = []
let genHeaders = []
const genHeaders = []
requestString.push(`jQuery.ajax({\n url: "${url}${pathName}${queryString}"`)
requestString.push(
`jQuery.ajax({\n url: "${url}${pathName}${queryString}"`
)
requestString.push(`,\n method: "${method.toUpperCase()}"`)
const requestBody = rawInput ? rawParams : rawRequestBody
@@ -41,12 +43,16 @@ export const JavascriptJqueryCodegen = {
if (auth === "Basic Auth") {
const basic = `${httpUser}:${httpPassword}`
genHeaders.push(
` "Authorization": "Basic ${window.btoa(unescape(encodeURIComponent(basic)))}",\n`
` "Authorization": "Basic ${window.btoa(
unescape(encodeURIComponent(basic))
)}",\n`
)
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
genHeaders.push(` "Authorization": "Bearer ${bearerToken}",\n`)
}
requestString.push(`,\n headers: {\n${genHeaders.join("").slice(0, -2)}\n }\n})`)
requestString.push(
`,\n headers: {\n${genHeaders.join("").slice(0, -2)}\n }\n})`
)
requestString.push(".then(response => {\n")
requestString.push(" console.log(response);\n")
requestString.push("})")

View File

@@ -28,11 +28,14 @@ export const JavascriptXhrCodegen = {
`xhr.open('${method}', '${url}${pathName}${queryString}', true, ${user}, ${password})`
)
if (auth === "Bearer Token" || auth === "OAuth 2.0") {
requestString.push(`xhr.setRequestHeader('Authorization', 'Bearer ${bearerToken}')`)
requestString.push(
`xhr.setRequestHeader('Authorization', 'Bearer ${bearerToken}')`
)
}
if (headers) {
headers.forEach(({ key, value }) => {
if (key) requestString.push(`xhr.setRequestHeader('${key}', '${value}')`)
if (key)
requestString.push(`xhr.setRequestHeader('${key}', '${value}')`)
})
}
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
@@ -42,7 +45,9 @@ export const JavascriptXhrCodegen = {
} else if (contentType.includes("x-www-form-urlencoded")) {
requestBody = `"${requestBody}"`
}
requestString.push(`xhr.setRequestHeader('Content-Type', '${contentType}; charset=utf-8')`)
requestString.push(
`xhr.setRequestHeader('Content-Type', '${contentType}; charset=utf-8')`
)
requestString.push(`xhr.send(${requestBody})`)
} else {
requestString.push("xhr.send()")

View File

@@ -18,10 +18,12 @@ export const NodejsAxiosCodegen = {
headers,
}) => {
const requestString = []
let genHeaders = []
let requestBody = rawInput ? rawParams : rawRequestBody
const genHeaders = []
const requestBody = rawInput ? rawParams : rawRequestBody
requestString.push(`axios.${method.toLowerCase()}('${url}${pathName}${queryString}'`)
requestString.push(
`axios.${method.toLowerCase()}('${url}${pathName}${queryString}'`
)
if (requestBody.length !== 0) {
requestString.push(", ")
}
@@ -36,12 +38,16 @@ export const NodejsAxiosCodegen = {
if (auth === "Basic Auth") {
const basic = `${httpUser}:${httpPassword}`
genHeaders.push(
` "Authorization": "Basic ${window.btoa(unescape(encodeURIComponent(basic)))}",\n`
` "Authorization": "Basic ${window.btoa(
unescape(encodeURIComponent(basic))
)}",\n`
)
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
genHeaders.push(` "Authorization": "Bearer ${bearerToken}",\n`)
}
requestString.push(`${requestBody},{ \n headers : {${genHeaders.join("").slice(0, -2)}}\n})`)
requestString.push(
`${requestBody},{ \n headers : {${genHeaders.join("").slice(0, -2)}}\n})`
)
requestString.push(".then(response => {\n")
requestString.push(" console.log(response);\n")
requestString.push("})")

View File

@@ -32,7 +32,9 @@ export const NodejsNativeCodegen = {
if (auth === "Basic Auth") {
const basic = `${httpUser}:${httpPassword}`
genHeaders.push(
` "Authorization": "Basic ${window.btoa(unescape(encodeURIComponent(basic)))}",\n`
` "Authorization": "Basic ${window.btoa(
unescape(encodeURIComponent(basic))
)}",\n`
)
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
genHeaders.push(` "Authorization": "Bearer ${bearerToken}",\n`)
@@ -47,7 +49,9 @@ export const NodejsNativeCodegen = {
requestBody = `\`${requestBody}\``
}
if (contentType) {
genHeaders.push(` "Content-Type": "${contentType}; charset=utf-8",\n`)
genHeaders.push(
` "Content-Type": "${contentType}; charset=utf-8",\n`
)
}
}
@@ -57,11 +61,15 @@ export const NodejsNativeCodegen = {
})
}
if (genHeaders.length > 0 || headers.length > 0) {
requestString.push(` headers: {\n${genHeaders.join("").slice(0, -2)}\n }`)
requestString.push(
` headers: {\n${genHeaders.join("").slice(0, -2)}\n }`
)
}
requestString.push(`};\n\n`)
requestString.push(`const request = http.request(url, options, (response) => {\n`)
requestString.push(
`const request = http.request(url, options, (response) => {\n`
)
requestString.push(` console.log(response);\n`)
requestString.push(`});\n\n`)

View File

@@ -20,7 +20,7 @@ export const NodejsRequestCodegen = {
headers,
}) => {
const requestString = []
let genHeaders = []
const genHeaders = []
requestString.push(`const request = require('request');\n`)
requestString.push(`const options = {\n`)
@@ -30,7 +30,9 @@ export const NodejsRequestCodegen = {
if (auth === "Basic Auth") {
const basic = `${httpUser}:${httpPassword}`
genHeaders.push(
` "Authorization": "Basic ${window.btoa(unescape(encodeURIComponent(basic)))}",\n`
` "Authorization": "Basic ${window.btoa(
unescape(encodeURIComponent(basic))
)}",\n`
)
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
genHeaders.push(` "Authorization": "Bearer ${bearerToken}",\n`)
@@ -58,7 +60,9 @@ export const NodejsRequestCodegen = {
reqBodyType = "body"
}
if (contentType) {
genHeaders.push(` "Content-Type": "${contentType}; charset=utf-8",\n`)
genHeaders.push(
` "Content-Type": "${contentType}; charset=utf-8",\n`
)
}
requestString.push(`,\n ${reqBodyType}: ${requestBody}`)
}
@@ -69,7 +73,9 @@ export const NodejsRequestCodegen = {
})
}
if (genHeaders.length > 0 || headers.length > 0) {
requestString.push(`,\n headers: {\n${genHeaders.join("").slice(0, -2)}\n }`)
requestString.push(
`,\n headers: {\n${genHeaders.join("").slice(0, -2)}\n }`
)
}
requestString.push(`\n}`)

View File

@@ -20,16 +20,20 @@ export const NodejsUnirestCodegen = {
headers,
}) => {
const requestString = []
let genHeaders = []
const genHeaders = []
requestString.push(`const unirest = require('unirest');\n`)
requestString.push(`const req = unirest(\n`)
requestString.push(`'${method.toLowerCase()}', '${url}${pathName}${queryString}')\n`)
requestString.push(
`'${method.toLowerCase()}', '${url}${pathName}${queryString}')\n`
)
if (auth === "Basic Auth") {
const basic = `${httpUser}:${httpPassword}`
genHeaders.push(
` "Authorization": "Basic ${window.btoa(unescape(encodeURIComponent(basic)))}",\n`
` "Authorization": "Basic ${window.btoa(
unescape(encodeURIComponent(basic))
)}",\n`
)
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
genHeaders.push(` "Authorization": "Bearer ${bearerToken}",\n`)
@@ -58,7 +62,9 @@ export const NodejsUnirestCodegen = {
reqBodyType = "send"
}
if (contentType) {
genHeaders.push(` "Content-Type": "${contentType}; charset=utf-8",\n`)
genHeaders.push(
` "Content-Type": "${contentType}; charset=utf-8",\n`
)
}
requestString.push(`.\n ${reqBodyType}( ${requestBody})`)
}
@@ -69,7 +75,9 @@ export const NodejsUnirestCodegen = {
})
}
if (genHeaders.length > 0 || headers.length > 0) {
requestString.push(`.\n headers({\n${genHeaders.join("").slice(0, -2)}\n }`)
requestString.push(
`.\n headers({\n${genHeaders.join("").slice(0, -2)}\n }`
)
}
requestString.push(`\n)`)

View File

@@ -20,7 +20,7 @@ export const PhpCurlCodegen = {
headers,
}) => {
const requestString = []
let genHeaders = []
const genHeaders = []
requestString.push(`<?php\n`)
requestString.push(`$curl = curl_init();\n`)
@@ -37,7 +37,9 @@ export const PhpCurlCodegen = {
if (auth === "Basic Auth") {
const basic = `${httpUser}:${httpPassword}`
genHeaders.push(
` "Authorization: Basic ${window.btoa(unescape(encodeURIComponent(basic)))}",\n`
` "Authorization: Basic ${window.btoa(
unescape(encodeURIComponent(basic))
)}",\n`
)
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
genHeaders.push(` "Authorization: Bearer ${bearerToken}",\n`)
@@ -79,7 +81,9 @@ export const PhpCurlCodegen = {
}
if (genHeaders.length > 0 || headers.length > 0) {
requestString.push(
` CURLOPT_HTTPHEADER => array(\n${genHeaders.join("").slice(0, -2)}\n )\n`
` CURLOPT_HTTPHEADER => array(\n${genHeaders
.join("")
.slice(0, -2)}\n )\n`
)
}

View File

@@ -18,7 +18,8 @@ export const PowershellRestmethodCodegen = {
headers,
}) => {
const methodsWithBody = ["Put", "Post", "Delete"]
const formattedMethod = method[0].toUpperCase() + method.substring(1).toLowerCase()
const formattedMethod =
method[0].toUpperCase() + method.substring(1).toLowerCase()
const includeBody = methodsWithBody.includes(formattedMethod)
const requestString = []
let genHeaders = []
@@ -46,7 +47,9 @@ export const PowershellRestmethodCodegen = {
if (auth === "Basic Auth") {
const basic = `${httpUser}:${httpPassword}`
genHeaders.push(
` 'Authorization' = 'Basic ${window.btoa(unescape(encodeURIComponent(basic)))}'\n`
` 'Authorization' = 'Basic ${window.btoa(
unescape(encodeURIComponent(basic))
)}'\n`
)
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
genHeaders.push(` 'Authorization' = 'Bearer ${bearerToken}'\n`)

View File

@@ -28,24 +28,28 @@ export const PythonHttpClientCodegen = {
headers,
}) => {
const requestString = []
let genHeaders = []
const genHeaders = []
requestString.push(`import http.client\n`)
requestString.push(`import mimetypes\n`)
const currentUrl = new URL(url)
let hostname = currentUrl["hostname"]
let port = currentUrl["port"]
const hostname = currentUrl.hostname
const port = currentUrl.port
if (!port) {
requestString.push(`conn = http.client.HTTPSConnection("${hostname}")\n`)
} else {
requestString.push(`conn = http.client.HTTPSConnection("${hostname}", ${port})\n`)
requestString.push(
`conn = http.client.HTTPSConnection("${hostname}", ${port})\n`
)
}
// auth headers
if (auth === "Basic Auth") {
const basic = `${httpUser}:${httpPassword}`
genHeaders.push(
`'Authorization': 'Basic ${window.btoa(unescape(encodeURIComponent(basic)))}'`
`'Authorization': 'Basic ${window.btoa(
unescape(encodeURIComponent(basic))
)}'`
)
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
genHeaders.push(`'Authorization': 'Bearer ${bearerToken}'`)
@@ -60,7 +64,7 @@ export const PythonHttpClientCodegen = {
// initial request setup
let requestBody = rawInput ? rawParams : rawRequestBody
if (method == "GET") {
if (method === "GET") {
requestString.push(...printHeaders(genHeaders))
requestString.push(`payload = ''\n`)
}
@@ -86,7 +90,9 @@ export const PythonHttpClientCodegen = {
requestString.push(`paylod = '''${requestBody}'''\n`)
}
}
requestString.push(`conn.request("${method}", "${pathName}${queryString}", payload, headers)\n`)
requestString.push(
`conn.request("${method}", "${pathName}${queryString}", payload, headers)\n`
)
requestString.push(`res = conn.getresponse()\n`)
requestString.push(`data = res.read()\n`)
requestString.push(`print(data.decode("utf-8"))`)

View File

@@ -28,7 +28,7 @@ export const PythonRequestsCodegen = {
headers,
}) => {
const requestString = []
let genHeaders = []
const genHeaders = []
requestString.push(`import requests\n\n`)
requestString.push(`url = '${url}${pathName}${queryString}'\n`)
@@ -37,7 +37,9 @@ export const PythonRequestsCodegen = {
if (auth === "Basic Auth") {
const basic = `${httpUser}:${httpPassword}`
genHeaders.push(
`'Authorization': 'Basic ${window.btoa(unescape(encodeURIComponent(basic)))}'`
`'Authorization': 'Basic ${window.btoa(
unescape(encodeURIComponent(basic))
)}'`
)
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
genHeaders.push(`'Authorization': 'Bearer ${bearerToken}'`)
@@ -52,7 +54,7 @@ export const PythonRequestsCodegen = {
// initial request setup
let requestBody = rawInput ? rawParams : rawRequestBody
if (method == "GET") {
if (method === "GET") {
requestString.push(...printHeaders(genHeaders))
requestString.push(`response = requests.request(\n`)
requestString.push(` '${method}',\n`)

View File

@@ -71,7 +71,9 @@ export const RubyNetHttpCodeGen = {
// analyse result
requestString.push(`unless response.is_a?(Net::HTTPSuccess) then`)
requestString.push(` raise "An error occurred: #{response.code} #{response.message}"`)
requestString.push(
` raise "An error occurred: #{response.code} #{response.message}"`
)
requestString.push(`else`)
requestString.push(` puts response.body`)
requestString.push(`end`)

View File

@@ -29,7 +29,9 @@ export const SalesforceApexCodegen = {
// create request
requestString.push(`HttpRequest request = new HttpRequest();\n`)
requestString.push(`request.setMethod('${method}');\n`)
requestString.push(`request.setEndpoint('${url}${pathName}${queryString}');\n\n`)
requestString.push(
`request.setEndpoint('${url}${pathName}${queryString}');\n\n`
)
// authentification
if (auth === "Basic Auth") {
@@ -40,12 +42,16 @@ export const SalesforceApexCodegen = {
)}');\n`
)
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
requestString.push(`request.setHeader('Authorization', 'Bearer ${bearerToken}');\n`)
requestString.push(
`request.setHeader('Authorization', 'Bearer ${bearerToken}');\n`
)
}
// content type
if (contentType) {
requestString.push(`request.setHeader('Content-Type', '${contentType}');\n`)
requestString.push(
`request.setHeader('Content-Type', '${contentType}');\n`
)
}
// custom headers
@@ -70,7 +76,9 @@ export const SalesforceApexCodegen = {
requestString.push(` HttpResponse response = client.send(request);\n`)
requestString.push(` System.debug(response.getBody());\n`)
requestString.push(`} catch (CalloutException ex) {\n`)
requestString.push(` System.debug('An error occured ' + ex.getMessage());\n`)
requestString.push(
` System.debug('An error occured ' + ex.getMessage());\n`
)
requestString.push(`}`)
return requestString.join("")

View File

@@ -48,7 +48,9 @@ export const ShellHttpieCodegen = {
if (headers) {
headers.forEach(({ key, value }) => {
requestString.push(` $'${key.replace(/'/g, "\\'")}:${value.replace(/'/g, "\\'")}'`)
requestString.push(
` $'${key.replace(/'/g, "\\'")}:${value.replace(/'/g, "\\'")}'`
)
})
}

View File

@@ -23,7 +23,9 @@ export const ShellWgetCodegen = {
if (auth === "Basic Auth") {
const basic = `${httpUser}:${httpPassword}`
requestString.push(
` --header='Authorization: Basic ${window.btoa(unescape(encodeURIComponent(basic)))}'`
` --header='Authorization: Basic ${window.btoa(
unescape(encodeURIComponent(basic))
)}'`
)
} else if (auth === "Bearer Token" || auth === "OAuth 2.0") {
requestString.push(` --header='Authorization: Bearer ${bearerToken}'`)
@@ -35,7 +37,9 @@ export const ShellWgetCodegen = {
}
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
const requestBody = rawInput ? rawParams : rawRequestBody
requestString.push(` --header='Content-Type: ${contentType}; charset=utf-8'`)
requestString.push(
` --header='Content-Type: ${contentType}; charset=utf-8'`
)
requestString.push(` --body-data='${requestBody}'`)
}
return requestString.join(" \\\n")