Skip to content

Commit

Permalink
fixed value inits, missing models
Browse files Browse the repository at this point in the history
  • Loading branch information
fehguy committed Feb 13, 2014
1 parent fcaff7c commit 7ba959a
Showing 1 changed file with 26 additions and 20 deletions.
46 changes: 26 additions & 20 deletions lib/swagger.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,8 @@ SwaggerResource.prototype.addModels = function(models) {
}
}
var output = [];
for (var i = 0; i < this.modelsArray; i++) {
model = this.modelsArray[_i];
for (var i = 0; i < this.modelsArray.length; i++) {
model = this.modelsArray[i];
output.push(model.setReferencedModels(this.models));
}
return output;
Expand Down Expand Up @@ -450,7 +450,7 @@ var SwaggerModel = function(modelName, obj) {

SwaggerModel.prototype.setReferencedModels = function(allModels) {
var results = [];
for (i = 0; i < this.properties.length; i++) {
for (var i = 0; i < this.properties.length; i++) {
var property = this.properties[i];
var type = property.type || property.dataType;
if (allModels[type] != null)
Expand All @@ -465,7 +465,7 @@ SwaggerModel.prototype.setReferencedModels = function(allModels) {

SwaggerModel.prototype.getMockSignature = function(modelsToIgnore) {
var propertiesStr = [];
for (i = 0; i < this.properties.length; i++) {
for (var i = 0; i < this.properties.length; i++) {
prop = this.properties[i];
propertiesStr.push(prop.toString());
}
Expand All @@ -480,7 +480,7 @@ SwaggerModel.prototype.getMockSignature = function(modelsToIgnore) {
modelsToIgnore = [];
modelsToIgnore.push(this);

for (i = 0; i < this.properties.length; i++) {
for (var i = 0; i < this.properties.length; i++) {
prop = this.properties[i];
if ((prop.refModel != null) && modelsToIgnore.indexOf(prop.refModel) === -1) {
returnVal = returnVal + ('<br>' + prop.refModel.getMockSignature(modelsToIgnore));
Expand All @@ -493,7 +493,7 @@ SwaggerModel.prototype.createJSONSample = function(modelsToIgnore) {
var result = {};
var modelsToIgnore = (modelsToIgnore||[])
modelsToIgnore.push(this.name);
for (i = 0; i < this.properties.length; i++) {
for (var i = 0; i < this.properties.length; i++) {
prop = this.properties[i];
result[prop.name] = prop.getSampleValue(modelsToIgnore);
}
Expand Down Expand Up @@ -534,7 +534,7 @@ var SwaggerModelProperty = function(name, obj) {

SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
var result;
if ((this.refModel != null) && (modelsToIgnore[this.refModel.name] === 'undefined')) {
if ((this.refModel != null) && (modelsToIgnore[this.refModel.name] === undefined)) {
result = this.refModel.createJSONSample(modelsToIgnore);
} else {
if (this.isCollection) {
Expand Down Expand Up @@ -615,7 +615,7 @@ var SwaggerOperation = function(nickname, path, method, parameters, summary, not
this.responseSampleJSON = this.getSampleJSON(this.type, this.resource.models);
}

for(i = 0; i < this.parameters.length; i ++) {
for(var i = 0; i < this.parameters.length; i ++) {
var param = this.parameters[i];
// might take this away
param.name = param.name || param.type || param.dataType;
Expand Down Expand Up @@ -763,7 +763,7 @@ SwaggerOperation.prototype["do"] = function(args, opts, callback, error) {
}

var possibleParams = [];
for(i = 0; i < this.parameters.length; i++) {
for(var i = 0; i < this.parameters.length; i++) {
var param = this.parameters[i];
if(param.paramType === 'header') {
if(args[param.name])
Expand Down Expand Up @@ -806,7 +806,7 @@ SwaggerOperation.prototype.pathXml = function() {
SwaggerOperation.prototype.urlify = function(args) {
var url = this.resource.basePath + this.pathJson();
var params = this.parameters;
for(i = 0; i < params.length; i ++){
for(var i = 0; i < params.length; i ++){

This comment has been minimized.

Copy link
@rage-shadowman

rage-shadowman Feb 13, 2014

In JavaScript, all variables (including var i) should be declared at the beginning of the function (closure) and the for statement should just initialize it for(i = 0; i < iterations; ++i). There are a couple of places in this file where 2 separate for loops occur inside the same closure, each declaring the same variable (this is one of them).

This comment has been minimized.

Copy link
@fehguy

fehguy Mar 5, 2014

Author Contributor

Yes, this appears to cause lots of troubles in IE. Fixed in master.

var param = params[i];
if (param.paramType === 'path') {
if(args[param.name]) {
Expand All @@ -821,7 +821,7 @@ SwaggerOperation.prototype.urlify = function(args) {
}

var queryParams = "";
for(i = 0; i < params.length; i ++){
for(var i = 0; i < params.length; i ++){
var param = params[i];
if(param.paramType === 'query') {
if(queryParams !== '')
Expand Down Expand Up @@ -853,7 +853,7 @@ SwaggerOperation.prototype.getHeaderParams = function(args) {
SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args) {
var matchingParams = {};
var params = this.parameters;
for (i = 0; i < params.length; i++) {
for (var i = 0; i < params.length; i++) {
param = params[i];
if (args && args[param.name])
matchingParams[param.name] = args[param.name];
Expand All @@ -869,7 +869,7 @@ SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args) {
SwaggerOperation.prototype.help = function() {
var msg = "";
var params = this.parameters;
for (i = 0; i < params.length; i++) {
for (var i = 0; i < params.length; i++) {
var param = params[i];
if (msg !== "")
msg += "\n";
Expand Down Expand Up @@ -908,7 +908,7 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
var params = this.operation.parameters;


for(i = 0; i < params.length; i++) {
for(var i = 0; i < params.length; i++) {
var param = params[i];
if(param.paramType === "form")
formParams.push(param);
Expand Down Expand Up @@ -958,7 +958,7 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
var possibleParams = {};
var values = {};

for(i = 0; i < formParams.length; i++){
for(var i = 0; i < formParams.length; i++){
var param = formParams[i];
values[param.name] = param;
}
Expand Down Expand Up @@ -1095,7 +1095,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
headers = {};
headerArray = response.getAllResponseHeaders().split(":");

for(i = 0; i < headerArray.length / 2; i++)
for(var i = 0; i < headerArray.length / 2; i++)
headers[headerArray[i] = headerArray[i+1]];

out = {
Expand All @@ -1107,9 +1107,15 @@ JQueryHttpClient.prototype.execute = function(obj) {
headers: headers
};

if(response._headers["Content-Type"] && response._headers["Content-Type"].indexOf("application/json") == 0 &&
response.content.data && response.content.data !== "") {
out.obj = JSON.parse(response.responseText);
var contentType = (response._headers["content-type"]||response._headers["Content-Type"]||null)

if(contentType != null) {
if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) {
if(response.responseText && response.responseText !== "")
out.obj = JSON.parse(response.responseText);
else
out.obj = {}
}
}

if(response.status >= 200 && response.status < 300)
Expand Down Expand Up @@ -1186,7 +1192,7 @@ ShredHttpClient.prototype.execute = function(obj) {
var contentType = (response._headers["content-type"]||response._headers["Content-Type"]||null)

if(contentType != null) {
if(contentType.indexOf("application/json") == 0) {
if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) {
if(response.content.data && response.content.data !== "")
out.obj = JSON.parse(response.content.data);
else
Expand Down

0 comments on commit 7ba959a

Please sign in to comment.