diff --git a/dist/index.html b/dist/index.html index 809749a7..daff2810 100644 --- a/dist/index.html +++ b/dist/index.html @@ -67,9 +67,7 @@ } } - $('#input_apiKey').change(function() { - addApiKeyAuthorization(); - }); + $('#input_apiKey').change(addApiKeyAuthorization); // if you have an apiKey you would like to pre-populate on the page for demonstration purposes... /* diff --git a/dist/swagger-ui.js b/dist/swagger-ui.js index 7e71b706..83fc179a 100644 --- a/dist/swagger-ui.js +++ b/dist/swagger-ui.js @@ -1014,7 +1014,10 @@ SwaggerUi.Views.ApiKeyButton = Backbone.View.extend({ // TODO: append this to gl 'click #apply_api_key' : 'applyApiKey' }, - initialize: function(){}, + initialize: function(opts){ + this.options = opts || {}; + this.router = this.options.router; + }, render: function(){ var template = this.template(); @@ -1030,13 +1033,13 @@ SwaggerUi.Views.ApiKeyButton = Backbone.View.extend({ // TODO: append this to gl $('#input_apiKey_entry').val(), this.model.in ); - window.authorizations.add(this.model.name, keyAuth); - window.swaggerUi.load(); + this.router.api.clientAuthorizations.add(this.model.name, keyAuth); + this.router.load(); $('#apikey_container').show(); }, toggleApiKeyContainer: function(){ - if ($('#apikey_container').length > 0) { + if ($('#apikey_container').length) { var elem = $('#apikey_container').first(); @@ -1061,7 +1064,10 @@ SwaggerUi.Views.ApiKeyButton = Backbone.View.extend({ // TODO: append this to gl SwaggerUi.Views.BasicAuthButton = Backbone.View.extend({ - initialize: function () {}, + initialize: function (opts) { + this.options = opts || {}; + this.router = this.options.router; + }, render: function(){ var template = this.template(); @@ -1079,13 +1085,13 @@ SwaggerUi.Views.BasicAuthButton = Backbone.View.extend({ var username = $('.input_username').val(); var password = $('.input_password').val(); var basicAuth = new SwaggerClient.PasswordAuthorization('basic', username, password); - window.authorizations.add(this.model.type, basicAuth); - window.swaggerUi.load(); + this.router.api.clientAuthorizations.add(this.model.type, basicAuth); + this.router.load(); $('#basic_auth_container').hide(); }, togglePasswordContainer: function(){ - if ($('#basic_auth_container').length > 0) { + if ($('#basic_auth_container').length) { var elem = $('#basic_auth_container').show(); if (elem.is(':visible')){ elem.slideUp(); @@ -1516,7 +1522,11 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({ addStatusCode: function(statusCode) { // Render status codes - var statusCodeView = new SwaggerUi.Views.StatusCodeView({model: statusCode, tagName: 'tr'}); + var statusCodeView = new SwaggerUi.Views.StatusCodeView({ + model: statusCode, + tagName: 'tr', + router: this.router + }); $('.operation-status', $(this.el)).append(statusCodeView.render().el); }, @@ -2173,19 +2183,19 @@ SwaggerUi.Views.SignatureView = Backbone.View.extend({ 'use strict'; SwaggerUi.Views.StatusCodeView = Backbone.View.extend({ - initialize: function () { - + initialize: function (opts) { + this.options = opts || {}; + this.router = this.options.router; }, render: function(){ $(this.el).html(Handlebars.templates.status_code(this.model)); - // TODO get rid of "swaggerUi" global dependency - if (swaggerUi.api.models.hasOwnProperty(this.model.responseModel)) { + if (this.router.api.models.hasOwnProperty(this.model.responseModel)) { var responseModel = { - sampleJSON: JSON.stringify(swaggerUi.api.models[this.model.responseModel].createJSONSample(), null, 2), + sampleJSON: JSON.stringify(this.router.api.models[this.model.responseModel].createJSONSample(), null, 2), isParam: false, - signature: swaggerUi.api.models[this.model.responseModel].getMockSignature(), + signature: this.router.api.models[this.model.responseModel].getMockSignature(), }; var responseModelView = new SwaggerUi.Views.SignatureView({model: responseModel, tagName: 'div'}); diff --git a/dist/swagger-ui.min.js b/dist/swagger-ui.min.js index f77de638..0307b457 100644 --- a/dist/swagger-ui.min.js +++ b/dist/swagger-ui.min.js @@ -1,2 +1,2 @@ -(function(){"use strict";window.SwaggerUi=Backbone.Router.extend({dom_id:"swagger_ui",options:null,api:null,headerView:null,mainView:null,initialize:function(e){e=e||{},e.dom_id&&(this.dom_id=e.dom_id,delete e.dom_id),e.supportedSubmitMethods||(e.supportedSubmitMethods=["get","put","post","delete","head","options","patch"]),$("#"+this.dom_id).length||$("body").append('
'),this.options=e,marked.setOptions({gfm:!0});var n=this;this.options.success=function(){return n.render()},this.options.progress=function(e){return n.showMessage(e)},this.options.failure=function(e){return n.onLoadFailure(e)},this.headerView=new SwaggerUi.Views.HeaderView({el:$("#header")}),this.headerView.on("update-swagger-ui",function(e){return n.updateSwaggerUi(e)})},setOption:function(e,n){this.options[e]=n},getOption:function(e){return this.options[e]},updateSwaggerUi:function(e){this.options.url=e.url,this.load()},load:function(){this.mainView&&this.mainView.clear();var e=this.options.url;e&&0!==e.indexOf("http")&&(e=this.buildUrl(window.location.href.toString(),e)),this.options.url=e,this.headerView.update(e),this.api=new SwaggerClient(this.options)},collapseAll:function(){e.collapseEndpointListForResource("")},listAll:function(){e.collapseOperationsForResource("")},expandAll:function(){e.expandOperationsForResource("")},render:function(){switch(this.showMessage("Finished Loading Resource Information. Rendering Swagger UI..."),this.mainView=new SwaggerUi.Views.MainView({model:this.api,el:$("#"+this.dom_id),swaggerOptions:this.options,router:this}).render(),this.showMessage(),this.options.docExpansion){case"full":this.expandAll();break;case"list":this.listAll()}this.renderGFM(),this.options.onComplete&&this.options.onComplete(this.api,this),setTimeout(e.shebang.bind(this),100)},buildUrl:function(e,n){if(0===n.indexOf("/")){var a=e.split("/");return e=a[0]+"//"+a[2],e+n}var t=e.length;return e.indexOf("?")>-1&&(t=Math.min(t,e.indexOf("?"))),e.indexOf("#")>-1&&(t=Math.min(t,e.indexOf("#"))),e=e.substring(0,t),-1!==e.indexOf("/",e.length-1)?e+n:e+"/"+n},showMessage:function(e){void 0===e&&(e=""),$("#message-bar").removeClass("message-fail"),$("#message-bar").addClass("message-success"),$("#message-bar").html(e)},onLoadFailure:function(e){void 0===e&&(e=""),$("#message-bar").removeClass("message-success"),$("#message-bar").addClass("message-fail");var n=$("#message-bar").html(e);return this.options.onFailure&&this.options.onFailure(e),n},renderGFM:function(){$(".markdown").each(function(){$(this).html(marked($(this).html()))})}}),window.SwaggerUi.Views={},this.Handlebars=this.Handlebars||{},this.Handlebars.templates=this.Handlebars.templates||{},this.Handlebars.templates.apikey_button_view=Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(e,n,a,t){var i,s="function",l=n.helperMissing,r=this.escapeExpression;return"\n