Skip to content

Commit eed1cd3

Browse files
committed
Add an option to remove new line characters from body in cURL code snippet
postmanlabs#540
1 parent 2d9f862 commit eed1cd3

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

codegens/curl/lib/index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ self = module.exports = {
1414
}
1515
options = sanitizeOptions(options, self.getOptions());
1616

17-
var indent, trim, headersData, body, redirect, timeout, multiLine,
17+
var indent, trim, headersData, body, redirect, timeout, multiLine, bodySingleLine,
1818
format, snippet, silent, url, quoteType;
1919

2020
redirect = options.followRedirect;
2121
timeout = options.requestTimeoutInSeconds;
2222
multiLine = options.multiLine;
23+
bodySingleLine = options.bodySingleLine;
2324
format = options.longFormat;
2425
trim = options.trimRequestBody;
2526
silent = options.silent;
@@ -136,7 +137,12 @@ self = module.exports = {
136137
});
137138
break;
138139
case 'raw':
139-
snippet += indent + `--data-raw ${quoteType}${sanitize(body.raw.toString(), trim, quoteType)}${quoteType}`;
140+
// remove newlines from body when bodySingleLine is true
141+
if (bodySingleLine) {
142+
snippet += indent + `--data-raw ${quoteType}${sanitize(body.raw.toString(), trim, quoteType).replace(/\n/g, "")}${quoteType}`;
143+
} else {
144+
snippet += indent + `--data-raw ${quoteType}${sanitize(body.raw.toString(), trim, quoteType)}${quoteType}`;
145+
}
140146
break;
141147

142148
case 'graphql':
@@ -196,6 +202,13 @@ self = module.exports = {
196202
default: true,
197203
description: 'Split cURL command across multiple lines'
198204
},
205+
{
206+
name: 'Generate single line body',
207+
id: 'bodySingleLine',
208+
type: 'boolean',
209+
default: false,
210+
description: 'Removes every new line character from body to make the whole cURL command trully one line'
211+
},
199212
{
200213
name: 'Use long form options',
201214
id: 'longFormat',

0 commit comments

Comments
 (0)