diff --git a/lib/types/operation.js b/lib/types/operation.js index bce47d7cb..8672e7419 100644 --- a/lib/types/operation.js +++ b/lib/types/operation.js @@ -861,9 +861,9 @@ Operation.prototype.asCurl = function (args1, args2) { for (key in obj.headers) { var value = obj.headers[key]; if(typeof value === 'string'){ - value = value.replace(/"/g, '\\"'); + value = value.replace(/\'/g, '\\u0027'); } - results.push('--header "' + key + ': ' + value + '"'); + results.push('--header \'' + key + ': ' + value + '\''); } } @@ -876,7 +876,7 @@ Operation.prototype.asCurl = function (args1, args2) { body = obj.body; } - results.push('-d "' + body.replace(/"/g, '\\"') + '"'); + results.push('-d \'' + body.replace(/\'/g, '\\u0027') + '\''); } return 'curl ' + (results.join(' ')) + ' "' + obj.url + '"'; diff --git a/test/compat/request.js b/test/compat/request.js index f3e74ae7e..a99bf1766 100644 --- a/test/compat/request.js +++ b/test/compat/request.js @@ -34,7 +34,7 @@ describe('1.2 request operations', function () { it('shows curl syntax', function () { var curl = sample.pet.getPetById.asCurl({petId: 1}); - expect(curl).toBe('curl -X GET --header "Accept: application/json" "http://localhost:8001/v1/api/pet/1"'); + expect(curl).toBe('curl -X GET --header \'Accept: application/json\' "http://localhost:8001/v1/api/pet/1"'); }); it('generate a get request', function () { diff --git a/test/help.js b/test/help.js index bcc7dd310..ecbebd235 100644 --- a/test/help.js +++ b/test/help.js @@ -35,7 +35,7 @@ describe('help options', function () { new auth.SwaggerAuthorizations()); var curl = op.asCurl({}); - expect(curl).toBe('curl -X GET --header "Accept: application/json" "http://localhost/path"'); + expect(curl).toBe('curl -X GET --header \'Accept: application/json\' "http://localhost/path"'); }); it('prints a curl statement with headers', function () { @@ -65,7 +65,7 @@ describe('help options', function () { Authorization: 'Oauth:"test"' }); - expect(curl).toBe('curl -X GET --header "Accept: application/json" --header "name: tony" --header "age: 42" --header "Authorization: Oauth:\\"test\\"" "http://localhost/path"'); + expect(curl).toBe('curl -X GET --header \'Accept: application/json\' --header \'name: tony\' --header \'age: 42\' --header \'Authorization: Oauth:"test"\' "http://localhost/path"'); }); it('prints a curl statement with custom content-type', function () { @@ -75,6 +75,6 @@ describe('help options', function () { responseContentType: 'application/xml' }); - expect(curl).toBe('curl -X GET --header "Accept: application/xml" "http://localhost/path"'); + expect(curl).toBe('curl -X GET --header \'Accept: application/xml\' "http://localhost/path"'); }); }); diff --git a/test/request.js b/test/request.js index c75ba85a3..521d402a0 100644 --- a/test/request.js +++ b/test/request.js @@ -303,14 +303,21 @@ describe('swagger request functions', function () { var petApi = sample.pet; var curl = petApi.addPet.asCurl({body: {id:10101}}); - expect(curl).toBe('curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "{\\"id\\":10101}" "http://localhost:8000/v2/api/pet"'); + expect(curl).toBe('curl -X POST --header \'Content-Type: application/json\' --header \'Accept: application/json\' -d \'{"id":10101}\' "http://localhost:8000/v2/api/pet"'); }); it('prints a curl post statement from a string', function () { var petApi = sample.pet; var curl = petApi.addPet.asCurl({body: '{"id":10101}'}); - expect(curl).toBe('curl -X POST --header "Content-Type: application/json" --header "Accept: application/json" -d "{\\"id\\":10101}" "http://localhost:8000/v2/api/pet"'); + expect(curl).toBe('curl -X POST --header \'Content-Type: application/json\' --header \'Accept: application/json\' -d \'{"id":10101}\' "http://localhost:8000/v2/api/pet"'); + }); + + it('prints a curl post statement from a string containing a single quote', function () { + var petApi = sample.pet; + var curl = petApi.addPet.asCurl({body: '{"id":"foo\'bar"}'}); + + expect(curl).toBe('curl -X POST --header \'Content-Type: application/json\' --header \'Accept: application/json\' -d \'{"id":"foo\\u0027bar"}\' "http://localhost:8000/v2/api/pet"'); }); it('gets an server side 404, and verifies that the content-type in the response is correct, and different than one in the request', function (done) { @@ -404,4 +411,4 @@ describe('swagger basePath override functions', function () { sample.clientAuthorizations.authz = {}; done(); }); -}); \ No newline at end of file +});