Skip to content

Commit

Permalink
fix for swagger-api/swagger-ui#770, checking method instead of type
Browse files Browse the repository at this point in the history
  • Loading branch information
fehguy committed Dec 10, 2014
1 parent ae4e70b commit a685505
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 69 deletions.
126 changes: 63 additions & 63 deletions lib/swagger-client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,61 @@
// swagger-client.js
// version 2.1.0-alpha.3
// version 2.1.0-alpha.4
/**
* Array Model
**/
var ArrayModel = function(definition) {
this.name = "name";
this.definition = definition || {};
this.properties = [];
this.type;
this.ref;

var requiredFields = definition.enum || [];
var items = definition.items;
if(items) {
var type = items.type;
if(items.type) {
this.type = typeFromJsonSchema(type.type, type.format);
}
else {
this.ref = items['$ref'];
}
}
}

ArrayModel.prototype.createJSONSample = function(modelsToIgnore) {
var result;
modelsToIgnore = (modelsToIgnore||{})
if(this.type) {
result = type;
}
else if (this.ref) {
var name = simpleRef(this.ref);
result = models[name].createJSONSample();
}
return [ result ];
};

ArrayModel.prototype.getSampleValue = function(modelsToIgnore) {
var result;
modelsToIgnore = (modelsToIgnore || {})
if(this.type) {
result = type;
}
else if (this.ref) {
var name = simpleRef(this.ref);
result = models[name].getSampleValue(modelsToIgnore);
}
return [ result ];
}

ArrayModel.prototype.getMockSignature = function(modelsToIgnore) {
var propertiesStr = [];

if(this.ref) {
return models[simpleRef(this.ref)].getMockSignature();
}
};

/**
* SwaggerAuthorizations applys the correct authorization to an operation being executed
Expand Down Expand Up @@ -101,63 +157,7 @@ PasswordAuthorization.prototype.apply = function(obj, authorizations) {
var base64encoder = this._btoa;
obj.headers["Authorization"] = "Basic " + base64encoder(this.username + ":" + this.password);
return true;
};/**
* Array Model
**/
var ArrayModel = function(definition) {
this.name = "name";
this.definition = definition || {};
this.properties = [];
this.type;
this.ref;

var requiredFields = definition.enum || [];
var items = definition.items;
if(items) {
var type = items.type;
if(items.type) {
this.type = typeFromJsonSchema(type.type, type.format);
}
else {
this.ref = items['$ref'];
}
}
}

ArrayModel.prototype.createJSONSample = function(modelsToIgnore) {
var result;
modelsToIgnore = (modelsToIgnore||{})
if(this.type) {
result = type;
}
else if (this.ref) {
var name = simpleRef(this.ref);
result = models[name].createJSONSample();
}
return [ result ];
};

ArrayModel.prototype.getSampleValue = function(modelsToIgnore) {
var result;
modelsToIgnore = (modelsToIgnore || {})
if(this.type) {
result = type;
}
else if (this.ref) {
var name = simpleRef(this.ref);
result = models[name].getSampleValue(modelsToIgnore);
}
return [ result ];
}

ArrayModel.prototype.getMockSignature = function(modelsToIgnore) {
var propertiesStr = [];

if(this.ref) {
return models[simpleRef(this.ref)].getMockSignature();
}
};
var __bind = function(fn, me){
};var __bind = function(fn, me){
return function(){
return fn.apply(me, arguments);
};
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,11 +1379,11 @@ JQueryHttpClient.prototype.execute = function(obj) {

if(contentType != null) {
if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) {
if(response.responseText && response.responseText !== "")
if(response.responseText && response.responseText !== "") {
try {
out.obj = JSON.parse(response.content.data);
}
catch () {
catch (ex) {
// do not set out.obj
log ("unable to parse JSON content");
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
],
"description": "swagger.js is a javascript client for use with swaggering APIs.",
"version": "2.1.0-alpha.3",
"version": "2.1.0-alpha.4",
"homepage": "http://swagger.io",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion src/main/javascript/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,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
8 changes: 4 additions & 4 deletions src/main/javascript/swaggerHttp.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,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 @@ -82,7 +82,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 @@ -98,11 +98,11 @@ JQueryHttpClient.prototype.execute = function(obj) {

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

0 comments on commit a685505

Please sign in to comment.