Skip to content

Commit

Permalink
fix for #770
Browse files Browse the repository at this point in the history
  • Loading branch information
fehguy committed Dec 10, 2014
1 parent 886145b commit f1e394b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 12 deletions.
19 changes: 13 additions & 6 deletions dist/lib/swagger-client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// swagger-client.js
// version 2.1.0-alpha.3
// version 2.1.0-alpha.4
/**
* Array Model
**/
Expand Down Expand Up @@ -936,7 +936,7 @@ Operation.prototype.setContentTypes = function(args, opts) {
}

// if there's a body, need to set the accepts header via requestContentType
if (body && (this.type === 'post' || this.type === 'put' || this.type === 'patch' || this.type === 'delete')) {
if (body && (this.method === 'post' || this.method === 'put' || this.method === 'patch' || this.method === 'delete')) {
if (opts.requestContentType)
consumes = opts.requestContentType;
} else {
Expand Down Expand Up @@ -1350,7 +1350,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
obj.data = obj.body;
obj.complete = function(response, textStatus, opts) {
var headers = {},
headerArray = response.getAllResponseHeaders().split("\n");
headerArray = response.getAllResponseHeaders().split("\n");

for(var i = 0; i < headerArray.length; i++) {
var toSplit = headerArray[i].trim();
Expand All @@ -1363,7 +1363,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
continue;
}
var name = toSplit.substring(0, separator).trim(),
value = toSplit.substring(separator + 1).trim();
value = toSplit.substring(separator + 1).trim();
headers[name] = value;
}

Expand All @@ -1379,8 +1379,15 @@ JQueryHttpClient.prototype.execute = function(obj) {

if(contentType != null) {
if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) {
if(response.responseText && response.responseText !== "")
out.obj = JSON.parse(response.responseText);
if(response.responseText && response.responseText !== "") {
try {
out.obj = JSON.parse(response.content.data);
}
catch (ex) {
// do not set out.obj
log ("unable to parse JSON content");
}
}
else
out.obj = {}
}
Expand Down
19 changes: 13 additions & 6 deletions lib/swagger-client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// swagger-client.js
// version 2.1.0-alpha.3
// version 2.1.0-alpha.4
/**
* Array Model
**/
Expand Down Expand Up @@ -936,7 +936,7 @@ Operation.prototype.setContentTypes = function(args, opts) {
}

// if there's a body, need to set the accepts header via requestContentType
if (body && (this.type === 'post' || this.type === 'put' || this.type === 'patch' || this.type === 'delete')) {
if (body && (this.method === 'post' || this.method === 'put' || this.method === 'patch' || this.method === 'delete')) {
if (opts.requestContentType)
consumes = opts.requestContentType;
} else {
Expand Down Expand Up @@ -1350,7 +1350,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
obj.data = obj.body;
obj.complete = function(response, textStatus, opts) {
var headers = {},
headerArray = response.getAllResponseHeaders().split("\n");
headerArray = response.getAllResponseHeaders().split("\n");

for(var i = 0; i < headerArray.length; i++) {
var toSplit = headerArray[i].trim();
Expand All @@ -1363,7 +1363,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
continue;
}
var name = toSplit.substring(0, separator).trim(),
value = toSplit.substring(separator + 1).trim();
value = toSplit.substring(separator + 1).trim();
headers[name] = value;
}

Expand All @@ -1379,8 +1379,15 @@ JQueryHttpClient.prototype.execute = function(obj) {

if(contentType != null) {
if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) {
if(response.responseText && response.responseText !== "")
out.obj = JSON.parse(response.responseText);
if(response.responseText && response.responseText !== "") {
try {
out.obj = JSON.parse(response.content.data);
}
catch (ex) {
// do not set out.obj
log ("unable to parse JSON content");
}
}
else
out.obj = {}
}
Expand Down

0 comments on commit f1e394b

Please sign in to comment.