diff --git a/codegens/curl/README.md b/codegens/curl/README.md index a9962c100..cfa143d90 100644 --- a/codegens/curl/README.md +++ b/codegens/curl/README.md @@ -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 diff --git a/codegens/curl/lib/index.js b/codegens/curl/lib/index.js index 253ffedc8..6bfe8e04e 100644 --- a/codegens/curl/lib/index.js +++ b/codegens/curl/lib/index.js @@ -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; @@ -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': @@ -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',