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

@@ -14,7 +14,6 @@ export const PowershellRestmethodCodegen = {
rawInput,
rawParams,
rawRequestBody,
contentType,
headers,
}) => {
const methodsWithBody = ["Put", "Post", "Delete"]
@@ -30,8 +29,10 @@ export const PowershellRestmethodCodegen = {
)
const requestBody = rawInput ? rawParams : rawRequestBody
if (requestBody.length !== 0 && includeBody) {
variables = variables.concat(`$body = @'\n${requestBody}\n'@\n\n`)
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
if (requestBody && includeBody) {
variables = variables.concat(`$body = @'\n${requestBody}\n'@\n\n`)
}
}
if (headers) {
headers.forEach(({ key, value }) => {
@@ -39,11 +40,6 @@ export const PowershellRestmethodCodegen = {
})
}
if (contentType) {
genHeaders.push(` 'Content-Type' = '${contentType}; charset=utf-8'\n`)
requestString.push(` -ContentType '${contentType}; charset=utf-8'`)
}
if (auth === "Basic Auth") {
const basic = `${httpUser}:${httpPassword}`
genHeaders.push(
@@ -55,11 +51,13 @@ export const PowershellRestmethodCodegen = {
genHeaders.push(` 'Authorization' = 'Bearer ${bearerToken}'\n`)
}
genHeaders = genHeaders.join("").slice(0, -1)
variables = variables.concat(`$headers = @{\n${genHeaders}\n}\n`)
requestString.push(` -Headers $headers`)
if (includeBody) {
if (genHeaders) {
variables = variables.concat(`$headers = @{\n${genHeaders}\n}\n`)
requestString.push(` -Headers $headers`)
}
if (requestBody && includeBody) {
requestString.push(` -Body $body`)
}
return `${variables}\n${requestString.join("")}`
return `${variables}${requestString.join("")}`
},
}