Skip to content

Commit 168cebe

Browse files
committed
Merge pull request swagger-api#505 from iushankin/issue-504
Fixed swagger-api#504: The `asCurl` method doesn't allow to set content type for response and request
2 parents 7952025 + 7d934f0 commit 168cebe

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

lib/types/operation.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,8 +809,14 @@ Operation.prototype.matchesAccept = function(accepts) {
809809
return this.produces.indexOf(accepts) !== -1 || this.produces.indexOf('*/*') !== -1;
810810
};
811811

812-
Operation.prototype.asCurl = function (args) {
813-
var obj = this.execute(args, {mock: true});
812+
Operation.prototype.asCurl = function (args1, args2) {
813+
var opts = {mock: true};
814+
if (typeof args2 === 'object') {
815+
for (var argKey in args2) {
816+
opts[argKey] = args2[argKey];
817+
}
818+
}
819+
var obj = this.execute(args1, opts);
814820

815821
this.clientAuthorizations.apply(obj);
816822

test/help.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,14 @@ describe('help options', function () {
6060

6161
expect(curl).toBe('curl -X GET --header "Accept: application/json" --header "name: tony" --header "age: 42" "http://localhost/path"');
6262
});
63+
64+
it('prints a curl statement with custom content-type', function () {
65+
var op = new Operation({}, 'http', 'test', 'get', '/path', {summary: 'test operation'}, {}, {},
66+
new auth.SwaggerAuthorizations());
67+
var curl = op.asCurl({}, {
68+
responseContentType: 'application/xml'
69+
});
70+
71+
expect(curl).toBe('curl -X GET --header "Accept: application/xml" "http://localhost/path"');
72+
});
6373
});

0 commit comments

Comments
 (0)