diff --git a/dist/lang/en.js b/dist/lang/en.js index 4c32ab9e..a7356d9c 100644 --- a/dist/lang/en.js +++ b/dist/lang/en.js @@ -35,4 +35,17 @@ SwaggerTranslator.learn({this._swaggerLang = { "See more at":"See more at", "Contact the developer":"Contact the developer", "api version":"api version", + "Response Content Type":"Response Content Type", + "fetching resource":"fetching resource", + "fetching resource list":"fetching resource list", + "Explore":"Explore", + "Show Swagger Petstore Example Apis":"Show Swagger Petstore Example Apis", + "Show Wordnik Developer Apis":"Show Wordnik Developer Apis", + "Can't read from server. It may not have the appropriate access-control-origin settings.":"Can't read from server. It may not have the appropriate access-control-origin settings.", + "Please specify the protocol for":"Please specify the protocol for", + "Can't read swagger JSON from":"Can't read swagger JSON from", + "Finished Loading Resource Information. Rendering Swagger UI":"Finished Loading Resource Information. Rendering Swagger UI", + "Unable to read api":"Unable to read api", + "from path":"from path", + "server returned":"server returned" }); \ No newline at end of file diff --git a/dist/lang/ru.js b/dist/lang/ru.js index 07dd46fa..65dda864 100644 --- a/dist/lang/ru.js +++ b/dist/lang/ru.js @@ -33,5 +33,19 @@ SwaggerTranslator.learn({ "Created by":"Разработано", "See more at":"Еще тут", "Contact the developer":"Связаться с разработчиком", - "api version":"Версия API" + "api version":"Версия API", + "Response Content Type":"Content Type ответа", + "fetching resource":"Получение ресурса", + "fetching resource list":"Получение ресурсов", + "Explore":"Поехали", + "Show Swagger Petstore Example Apis":"Показать примеры АПИ", + "Show Wordnik Developer Apis":"Показать АПИ Wordnik Developer", + "Can't read from server. It may not have the appropriate access-control-origin settings.":"Не удается получить ответ от сервера. Возможно, какая-то лажа с настройками доступа", + "Please specify the protocol for":"Пожалуйста, укажите протогол для", + "Can't read swagger JSON from":"Не получается прочитать swagger json из", + "Finished Loading Resource Information. Rendering Swagger UI":"Загрузка информации о ресурсах завершена. Рендерим", + "Unable to read api":"Не удалось прочитать api", + "from path":"по адресу", + "server returned":"сервер сказал" + }); \ No newline at end of file diff --git a/dist/lang/translator.js b/dist/lang/translator.js index c46b30bd..eabb5731 100644 --- a/dist/lang/translator.js +++ b/dist/lang/translator.js @@ -5,20 +5,10 @@ * after . * For example - * - * Then you should create a SwaggerUI object this way: - * new SwaggerUi({ - * .... - * onComplete: function(swaggerApi, swaggerUi){ - * SwaggerTranslator.translate(); - * .... - * } - * }) - * in your index.html. - * * If you wish to translate some new texsts you should do two things: - * 1. Add new phrase pair ("New Phrase": "New Translation") into your language file (for example lang/ru.js). It will be great if you add it in other language files too. + * 1. Add a new phrase pair ("New Phrase": "New Translation") into your language file (for example lang/ru.js). It will be great if you add it in other language files too. * 2. Mark that text it templates this way New Phrase or . - * The main thing here is attribute data-swTarnslate. Only inner html and value-attribute are going to translate. + * The main thing here is attribute data-swTarnslate. Only inner html, title-attribute and value-attribute are going to translate. * */ SwaggerTranslator = { @@ -35,6 +25,10 @@ SwaggerTranslator = { $(this).val( $this._tryTranslate($(this).val()) ); + $(this).attr( + 'title', + $this._tryTranslate($(this).attr('title')) + ); } ) }, diff --git a/dist/lib/swagger-client.js b/dist/lib/swagger-client.js index eac794f1..cf036396 100644 --- a/dist/lib/swagger-client.js +++ b/dist/lib/swagger-client.js @@ -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('fetching resource list: ' + 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('Please specify the protocol for ' + 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('Can\'t read from server. It may not have the appropriate access-control-origin settings.'); else if (response.status === 404) - return self.fail('Can\'t read swagger JSON from ' + self.url); + return self.fail('Can\'t read swagger JSON from ' + 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('fetching resource ' + 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('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) { diff --git a/dist/swagger-ui.js b/dist/swagger-ui.js index fa44b5c9..4169bd07 100644 --- a/dist/swagger-ui.js +++ b/dist/swagger-ui.js @@ -212,7 +212,7 @@ this["Handlebars"]["templates"]["apikey_button_view"] = Handlebars.template({"co var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; return "\n
\n
\n
" + escapeExpression(((helper = (helper = helpers.keyName || (depth0 != null ? depth0.keyName : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"keyName","hash":{},"data":data}) : helper))) - + "
\n \n \n
\n
\n\n"; + + "\n \n
apply
\n \n\n\n"; },"useData":true}); var SwaggerUi, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, @@ -289,6 +289,7 @@ SwaggerUi = (function(_super) { }; SwaggerUi.prototype.load = function() { + console.log(0) var url, _ref; if ((_ref = this.mainView) != null) { _ref.clear(); @@ -300,7 +301,8 @@ SwaggerUi = (function(_super) { this.options.url = url; this.headerView.update(url); this.api = new SwaggerClient(this.options); - return this.api.build(); + + return this.api; }; SwaggerUi.prototype.collapseAll = function() { @@ -316,7 +318,7 @@ SwaggerUi = (function(_super) { }; SwaggerUi.prototype.render = function() { - this.showMessage('Finished Loading Resource Information. Rendering Swagger UI...'); + this.showMessage('Finished Loading Resource Information. Rendering Swagger UI...'); this.mainView = new MainView({ model: this.api, el: $('#' + this.dom_id), @@ -331,6 +333,11 @@ SwaggerUi = (function(_super) { this.listAll(); } this.renderGFM(); + + if (typeof SwaggerTranslator != 'undefined') { + SwaggerTranslator.translate(); + } + if (this.options.onComplete) { this.options.onComplete(this.api, this); } @@ -369,7 +376,14 @@ SwaggerUi = (function(_super) { } $('#message-bar').removeClass('message-fail'); $('#message-bar').addClass('message-success'); - return $('#message-bar').html(data); + + var result = $('#message-bar').html(data); + + if (typeof SwaggerTranslator != 'undefined') { + SwaggerTranslator.translate(); + } + + return result; }; SwaggerUi.prototype.onLoadFailure = function(data) { @@ -383,6 +397,12 @@ SwaggerUi = (function(_super) { if (this.options.onFailure != null) { this.options.onFailure(data); } + + if (typeof SwaggerTranslator != 'undefined') { + SwaggerTranslator.translate(); + } + + return val; }; @@ -407,7 +427,7 @@ Handlebars.registerHelper('sanitize', function(html) { }); this["Handlebars"]["templates"]["basic_auth_button_view"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { - return "
\n
\n
\n
Username
\n \n
Password
\n \n \n
\n
\n\n"; + return "
\n
\n
\n
Username
\n \n
Password
\n \n \n
\n
\n\n"; },"useData":true}); var ApiKeyButton, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, @@ -566,15 +586,15 @@ this["Handlebars"]["templates"]["main"] = Handlebars.template({"1":function(dept var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression; return "
Terms of service
"; + + "\" data-swTarnslate='1'>Terms of service"; },"4":function(depth0,helpers,partials,data) { var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression; - return "
Created by " + return "
Created by " + escapeExpression(lambda(((stack1 = ((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.contact : stack1)) != null ? stack1.name : stack1), depth0)) + "
"; },"6":function(depth0,helpers,partials,data) { var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression; - return ""; + + "\" data-swTarnslate='1'>Contact the developer
"; },"10":function(depth0,helpers,partials,data) { var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression; return "
api version: " + escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.version : stack1), depth0)) + "\n "; },"14":function(depth0,helpers,partials,data) { @@ -613,7 +633,7 @@ this["Handlebars"]["templates"]["main"] = Handlebars.template({"1":function(dept var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "
\n"; stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.info : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.noop,"data":data}); if (stack1 != null) { buffer += stack1; } - buffer += "
\n
\n
    \n\n
    \n
    \n
    \n

    [ base url: " + buffer += "

    \n
    \n
      \n\n
      \n
      \n
      \n

      [ base url: " + escapeExpression(((helper = (helper = helpers.basePath || (depth0 != null ? depth0.basePath : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"basePath","hash":{},"data":data}) : helper))) + "\n"; stack1 = helpers['if'].call(depth0, ((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.version : stack1), {"name":"if","hash":{},"fn":this.program(12, data),"inverse":this.noop,"data":data}); @@ -655,9 +675,9 @@ ContentTypeView = (function(_super) { this["Handlebars"]["templates"]["operation"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { return "deprecated"; },"3":function(depth0,helpers,partials,data) { - return "

      Warning: Deprecated

      \n"; + return "

      Warning: Deprecated

      \n"; },"5":function(depth0,helpers,partials,data) { - var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, buffer = "

      Implementation Notes

      \n

      "; + var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, buffer = "

      Implementation Notes

      \n

      "; stack1 = ((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper)); if (stack1 != null) { buffer += stack1; } return buffer + "

      \n"; @@ -681,17 +701,17 @@ this["Handlebars"]["templates"]["operation"] = Handlebars.template({"1":function return "
      \n \n
      \n"; },"16":function(depth0,helpers,partials,data) { var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return "

      Response Class (Status " + return "

      Response Class (Status " + escapeExpression(((helper = (helper = helpers.successCode || (depth0 != null ? depth0.successCode : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"successCode","hash":{},"data":data}) : helper))) + ")

      \n

      \n
      \n
      \n \n \n"; + return buffer + " \n \n
      \n \n \n"; },"useData":true}); var HeaderView, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; }, @@ -1561,7 +1581,7 @@ OperationView = (function(_super) { json = JSON.stringify(JSON.parse(content), null, " "); } catch (_error) { e = _error; - json = "can't parse JSON. Raw result:\n\n" + content; + json = "can't parse JSON. Raw result:\n\n" + content; } code = $('').text(json); pre = $('
      ').append(code);
      @@ -1918,6 +1938,7 @@ ResourceView = (function(_super) {
         };
       
         ResourceView.prototype.addOperation = function(operation) {
      +      console.log(operation)
           var operationView;
           operation.number = this.number;
           operationView = new OperationView({
      @@ -2064,7 +2085,7 @@ this["Handlebars"]["templates"]["resource"] = Handlebars.template({"1":function(
         var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
         return "
    • \n Raw\n
    • "; + + "' data-swTarnslate='1'>Raw\n "; },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { var stack1, helper, options, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, blockHelperMissing=helpers.blockHelperMissing, buffer = "
      \n

      \n Show/Hide\n \n
    • \n Show/Hide\n
    • \n
    • \n \n List Operations\n \n
    • \n
    • \n \n List Operations\n \n
    • \n
    • \n \n Expand Operations\n \n
    • \n "; + + "\">\n Expand Operations\n \n \n "; stack1 = ((helper = (helper = helpers.url || (depth0 != null ? depth0.url : depth0)) != null ? helper : helperMissing),(options={"name":"url","hash":{},"fn":this.program(3, data),"inverse":this.noop,"data":data}),(typeof helper === functionType ? helper.call(depth0, options) : helper)); if (!helpers.url) { stack1 = blockHelperMissing.call(depth0, stack1, options); } if (stack1 != null) { buffer += stack1; } @@ -2184,7 +2205,7 @@ this["Handlebars"]["templates"]["response_content_type"] = Handlebars.template({ },"4":function(depth0,helpers,partials,data) { return " \n"; },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { - var stack1, buffer = "\n\n"; stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(4, data),"data":data}); if (stack1 != null) { buffer += stack1; } return buffer + "\n"; @@ -2232,7 +2253,7 @@ StatusCodeView = (function(_super) { })(Backbone.View); this["Handlebars"]["templates"]["signature"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { - var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "
      \n\n
      \n\n
      \n
      \n "; + var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "
      \n\n
      \n\n
      \n
      \n "; stack1 = ((helper = (helper = helpers.signature || (depth0 != null ? depth0.signature : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"signature","hash":{},"data":data}) : helper)); if (stack1 != null) { buffer += stack1; } return buffer + "\n
      \n\n
      \n
      "