Skip to content

Commit

Permalink
Add an option to remove new line characters from body in cURL code sn…
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawloland committed Oct 24, 2021
1 parent 2d9f862 commit eed1cd3
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions codegens/curl/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ self = module.exports = {
}
options = sanitizeOptions(options, self.getOptions());

var indent, trim, headersData, body, redirect, timeout, multiLine,
var indent, trim, headersData, body, redirect, timeout, multiLine, bodySingleLine,
format, snippet, silent, url, quoteType;

redirect = options.followRedirect;
timeout = options.requestTimeoutInSeconds;
multiLine = options.multiLine;
bodySingleLine = options.bodySingleLine;
format = options.longFormat;
trim = options.trimRequestBody;
silent = options.silent;
Expand Down Expand Up @@ -136,7 +137,12 @@ self = module.exports = {
});
break;
case 'raw':
snippet += indent + `--data-raw ${quoteType}${sanitize(body.raw.toString(), trim, quoteType)}${quoteType}`;
// remove newlines from body when bodySingleLine is true
if (bodySingleLine) {
snippet += indent + `--data-raw ${quoteType}${sanitize(body.raw.toString(), trim, quoteType).replace(/\n/g, "")}${quoteType}`;
} else {
snippet += indent + `--data-raw ${quoteType}${sanitize(body.raw.toString(), trim, quoteType)}${quoteType}`;
}
break;

case 'graphql':
Expand Down Expand Up @@ -196,6 +202,13 @@ self = module.exports = {
default: true,
description: 'Split cURL command across multiple lines'
},
{
name: 'Generate single line body',
id: 'bodySingleLine',
type: 'boolean',
default: false,
description: 'Removes every new line character from body to make the whole cURL command trully one line'
},
{
name: 'Use long form options',
id: 'longFormat',
Expand Down

0 comments on commit eed1cd3

Please sign in to comment.