Skip to content

Commit d00d307

Browse files
Aman SinghAman Singh
authored andcommitted
Curl Codesnippet JSON body must not be multilined if disabled
1 parent a23f21d commit d00d307

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

codegens/curl/lib/index.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,14 @@ self = module.exports = {
152152
isAsperandPresent = _.includes(rawBody, '@'),
153153
// Use the long option if `@` is present in the request body otherwise follow user setting
154154
optionName = isAsperandPresent ? '--data-raw' : form('-d', format);
155-
// eslint-disable-next-line max-len
156-
snippet += indent + `${optionName} ${quoteType}${sanitize(rawBody, trim, quoteType)}${quoteType}`;
155+
156+
if (!multiLine && body.options.raw && body.options.raw.language === 'json') {
157+
// eslint-disable-next-line max-len
158+
snippet += indent + `${optionName} ${quoteType}${JSON.stringify(JSON.parse(sanitize(rawBody, trim, quoteType)))}${quoteType}`;
159+
}
160+
else {
161+
snippet += indent + `${optionName} ${quoteType}${sanitize(rawBody, trim, quoteType)}${quoteType}`;
162+
}
157163
break;
158164
}
159165

0 commit comments

Comments
 (0)