From 2ffde7a3841851db737c15ae072257b642291dfb Mon Sep 17 00:00:00 2001 From: Vishal Shingala Date: Mon, 30 Sep 2024 10:56:28 +0530 Subject: [PATCH] Added support for usage of --data-binary flag when using long format option for body typr binary --- codegens/curl/lib/index.js | 2 +- codegens/curl/test/unit/convert.test.js | 32 +++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/codegens/curl/lib/index.js b/codegens/curl/lib/index.js index 8abc73df6..d55ad5550 100644 --- a/codegens/curl/lib/index.js +++ b/codegens/curl/lib/index.js @@ -201,7 +201,7 @@ self = module.exports = { }); break; case 'file': - snippet += indent + form('-d', format); + snippet += indent + (format ? '--data-binary' : '-d'); snippet += ` ${quoteType}@${sanitize(body[body.mode].src, trim)}${quoteType}`; break; default: diff --git a/codegens/curl/test/unit/convert.test.js b/codegens/curl/test/unit/convert.test.js index 849395a5e..ae2111acc 100644 --- a/codegens/curl/test/unit/convert.test.js +++ b/codegens/curl/test/unit/convert.test.js @@ -1144,5 +1144,37 @@ describe('curl convert function', function () { }); }); }); + + it('should use --data-binary when request body type is binary', function () { + var request = new Request({ + 'method': 'POST', + 'header': [], + 'body': { + 'mode': 'file', + 'file': { + 'src': 'file-path/collection123.json' + } + }, + 'url': { + 'raw': 'https://postman-echo.com/get', + 'protocol': 'https', + 'host': [ + 'postman-echo', + 'com' + ], + 'path': [ + 'get' + ] + } + }); + + convert(request, { longFormat: true }, function (error, snippet) { + if (error) { + expect.fail(null, null, error); + } + expect(snippet).to.be.a('string'); + expect(snippet).to.include('--data-binary \'@file-path/collection123.json\''); + }); + }); }); });