Skip to content
Merged
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
6 changes: 3 additions & 3 deletions lib/types/operation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 + '\'');
}
}

Expand All @@ -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 + '"';
Expand Down
2 changes: 1 addition & 1 deletion test/compat/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down
6 changes: 3 additions & 3 deletions test/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand All @@ -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"');
});
});
13 changes: 10 additions & 3 deletions test/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -404,4 +411,4 @@ describe('swagger basePath override functions', function () {
sample.clientAuthorizations.authz = {};
done();
});
});
});