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 RubyNetHttpCodeGen = {
rawInput,
rawParams,
rawRequestBody,
contentType,
headers,
}) => {
const requestString = []
@@ -23,7 +22,9 @@ export const RubyNetHttpCodeGen = {
// initial request setup
let requestBody = rawInput ? rawParams : rawRequestBody
requestBody = requestBody.replace(/'/g, "\\'") // escape single-quotes for single-quoted string compatibility
if (requestBody) {
requestBody = requestBody.replaceAll(/'/g, "\\'") // escape single-quotes for single-quoted string compatibility
}
const verbs = [
{ verb: "GET", rbMethod: "Get" },
@@ -35,14 +36,10 @@ export const RubyNetHttpCodeGen = {
// create URI and request
const verb = verbs.find((v) => v.verb === method)
if (!verb) return ""
requestString.push(`uri = URI.parse('${url}${pathName}?${queryString}')\n`)
requestString.push(`request = Net::HTTP::${verb.rbMethod}.new(uri)`)
// content type
if (contentType) {
requestString.push(`request['Content-Type'] = '${contentType}'`)
}
// custom headers
if (headers) {
headers.forEach(({ key, value }) => {
@@ -60,7 +57,7 @@ export const RubyNetHttpCodeGen = {
}
// set body
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
if (["POST", "PUT", "PATCH", "DELETE"].includes(method) && requestBody) {
requestString.push(`request.body = '${requestBody}'\n`)
}