more phrases

This commit is contained in:
Константин Калинин
2015-02-13 15:37:48 +03:00
parent 483fff8f32
commit 020c738e95
5 changed files with 104 additions and 51 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||{});
@@ -338,7 +339,7 @@ SwaggerClient.prototype.initialize = function (url, options) {
SwaggerClient.prototype.build = function(mock) {
if (this.isBuilt) return this;
var self = this;
this.progress('fetching resource list: ' + this.url);
this.progress('<span data-swTarnslate="1">fetching resource list</span>: ' + this.url);
var obj = {
useJQuery: this.useJQuery,
url: this.url,
@@ -349,11 +350,11 @@ SwaggerClient.prototype.build = function(mock) {
on: {
error: function(response) {
if (self.url.substring(0, 4) !== 'http')
return self.fail('Please specify the protocol for ' + self.url);
return self.fail('<span data-swTarnslate="1">Please specify the protocol for</span> ' + self.url);
else if (response.status === 0)
return self.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
return self.fail('<span data-swTarnslate="1">Can\'t read from server. It may not have the appropriate access-control-origin settings.</span>');
else if (response.status === 404)
return self.fail('Can\'t read swagger JSON from ' + self.url);
return self.fail('<span data-swTarnslate="1">Can\'t read swagger JSON from</span> ' + self.url);
else
return self.fail(response.status + ' : ' + response.statusText + ' ' + self.url);
},
@@ -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;
@@ -1717,7 +1724,7 @@ var SwaggerResource = function (resourceObj, api) {
} else {
this.url = this.api.basePath + this.path.replace('{format}', 'json');
}
this.api.progress('fetching resource ' + this.name + ': ' + this.url);
this.api.progress('<span data-swTarnslate="1">fetching resource</span> ' + this.name + ': ' + this.url);
var obj = {
url: this.url,
method: 'GET',
@@ -1728,11 +1735,13 @@ 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) {
return _this.api.fail('Unable to read api \'' +
_this.name + '\' from path ' + _this.url + ' (server returned ' + response.statusText + ')');
_this.api.resourceCount += 1;
return _this.api.fail('<span data-swTarnslate="1">Unable to read api</span> \'' +
_this.name + '\' <span data-swTarnslate="1">from path</span> ' + _this.url + ' (<span data-swTarnslate="1">server returned</span> ' + 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) {