Skip to content

Commit 393eefd

Browse files
Aman SinghAman Singh
Aman Singh
authored and
Aman Singh
committed
make json body single line for multiline disabled config
1 parent d00d307 commit 393eefd

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

codegens/curl/lib/index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,15 +151,20 @@ self = module.exports = {
151151
let rawBody = body.raw.toString(),
152152
isAsperandPresent = _.includes(rawBody, '@'),
153153
// Use the long option if `@` is present in the request body otherwise follow user setting
154-
optionName = isAsperandPresent ? '--data-raw' : form('-d', format);
154+
optionName = isAsperandPresent ? '--data-raw' : form('-d', format),
155+
sanitizedBody = sanitize(rawBody, trim, quoteType);
155156

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}`;
157+
if (!multiLine) {
158+
try {
159+
sanitizedBody = JSON.stringify(JSON.parse(sanitizedBody));
160+
}
161+
catch (e) {
162+
// Do nothing
163+
}
162164
}
165+
166+
snippet += indent + `${optionName} ${quoteType}${sanitizedBody}${quoteType}`;
167+
163168
break;
164169
}
165170

0 commit comments

Comments
 (0)