updated files

This commit is contained in:
Tony Tam
2015-02-10 12:49:36 -08:00
parent 61a87b8fd7
commit 9ce5187312
7 changed files with 239 additions and 217 deletions

View File

@@ -291,13 +291,14 @@ var SwaggerClient = function(url, options) {
this.isValid = false;
this.info = null;
this.useJQuery = false;
this.resourceCount = 0;
if(typeof url !== 'undefined')
return this.initialize(url, options);
};
SwaggerClient.prototype.initialize = function (url, options) {
this.models = models;
this.models = models = {};
options = (options||{});
@@ -1569,6 +1570,7 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
this.apisArray.push(res);
} else {
var k;
this.expectedResourceCount = response.apis.length;
for (k = 0; k < response.apis.length; k++) {
var resource = response.apis[k];
res = new SwaggerResource(resource, this);
@@ -1577,12 +1579,17 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
}
}
this.isValid = true;
if (typeof this.success === 'function') {
this.success();
}
return this;
};
SwaggerClient.prototype.finish = function() {
if (typeof this.success === 'function') {
console.log('success');
this.selfReflect();
this.success();
}
}
SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
log('This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info');
if (response.apiVersion != null)
@@ -1702,7 +1709,7 @@ var SwaggerResource = function (resourceObj, api) {
this.operations = {};
this.operationsArray = [];
this.modelsArray = [];
this.models = {};
this.models = api.models || {};
this.rawModels = {};
this.useJQuery = (typeof api.useJQuery !== 'undefined') ? api.useJQuery : null;
@@ -1728,9 +1735,11 @@ var SwaggerResource = function (resourceObj, api) {
on: {
response: function (resp) {
var responseObj = resp.obj || JSON.parse(resp.data);
_this.api.resourceCount += 1;
return _this.addApiDeclaration(responseObj);
},
error: function (response) {
_this.api.resourceCount += 1;
return _this.api.fail('Unable to read api \'' +
_this.name + '\' from path ' + _this.url + ' (server returned ' + response.statusText + ')');
}
@@ -1784,7 +1793,9 @@ SwaggerResource.prototype.addApiDeclaration = function (response) {
}
this.api[this.name] = this;
this.ready = true;
return this.api.selfReflect();
if(this.api.resourceCount === this.api.expectedResourceCount)
this.api.finish();
return this;
};
SwaggerResource.prototype.addModels = function (models) {