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

@@ -23,7 +23,9 @@ export const CsRestsharpCodegen = {
// initial request setup
let requestBody = rawInput ? rawParams : rawRequestBody
requestBody = requestBody.replace(/"/g, '""') // escape quotes for C# verbatim string compatibility
if (requestBody) {
requestBody = requestBody.replace(/"/g, '""') // escape quotes for C# verbatim string compatibility
}
// prepare data
let requestDataFormat
@@ -62,13 +64,6 @@ export const CsRestsharpCodegen = {
)
}
// content type
if (contentType) {
requestString.push(
`request.AddHeader("Content-Type", "${contentType}");\n`
)
}
// custom headers
if (headers) {
headers.forEach(({ key, value }) => {
@@ -81,7 +76,7 @@ export const CsRestsharpCodegen = {
requestString.push(`\n`)
// set body
if (["POST", "PUT", "PATCH", "DELETE"].includes(method)) {
if (["POST", "PUT", "PATCH", "DELETE"].includes(method) && requestBody) {
requestString.push(
`request.AddParameter("${requestContentType}", @"${requestBody}", ParameterType.RequestBody);\n\n`
)
@@ -89,7 +84,11 @@ export const CsRestsharpCodegen = {
// process
const verb = verbs.find((v) => v.verb === method)
requestString.push(`var response = client.${verb.csMethod}(request);\n\n`)
if (verb) {
requestString.push(`var response = client.${verb.csMethod}(request);\n\n`)
} else {
return ""
}
// analyse result
requestString.push(