Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to remove new line characters from raw body in cURL cod… #541

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions codegens/curl/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Convert function takes three parameters
* `followRedirect` - Boolean denoting whether to redirect a request
* `requestTimeoutInSeconds` - Integer denoting time after which the request will bail out in seconds
* `multiLine` - Boolean denoting whether to output code snippet with multi line breaks
* `bodySingleLine` - Boolean denoting whether to remove new line characters from raw body
* `longFormat` - Boolean denoting whether to use longform cURL options in snippet
* `quoteType` - String denoting the quote type to use (single or double) for URL

Expand Down
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 any new line character if bodySingleLine is true
if (bodySingleLine) {
snippet += indent + `--data-raw ${quoteType}${sanitize(body.raw.toString(), trim, quoteType).replace(/[\n\r]/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: 'Remove new line characters from raw body',
id: 'bodySingleLine',
type: 'boolean',
default: false,
description: 'Remove new line characters from raw body so that cURL code snippet will for sure be one line when used with Generate multiline snippet option'
},
{
name: 'Use long form options',
id: 'longFormat',
Expand Down