diff --git a/dist/swagger-ui.js b/dist/swagger-ui.js index d16532b2..12ddf755 100644 --- a/dist/swagger-ui.js +++ b/dist/swagger-ui.js @@ -39,7 +39,7 @@ window.SwaggerUi = Backbone.Router.extend({ } // Create an empty div which contains the dom_id - if (! $('#' + this.dom_id)){ + if (! $('#' + this.dom_id).length){ $('body').append('
') ; } @@ -118,7 +118,8 @@ window.SwaggerUi = Backbone.Router.extend({ this.mainView = new SwaggerUi.Views.MainView({ model: this.api, el: $('#' + this.dom_id), - swaggerOptions: this.options + swaggerOptions: this.options, + router: this }).render(); this.showMessage(); switch (this.options.docExpansion) { @@ -1181,6 +1182,9 @@ SwaggerUi.Views.MainView = Backbone.View.extend({ initialize: function(opts){ opts = opts || {}; + + this.router = opts.router; + // set up the UI for input this.model.auths = []; var key, value; @@ -1221,12 +1225,12 @@ SwaggerUi.Views.MainView = Backbone.View.extend({ var button; if (auth.type === 'apiKey' && $('#apikey_button').length === 0) { - button = new SwaggerUi.Views.ApiKeyButton({model: auth}).render().el; + button = new SwaggerUi.Views.ApiKeyButton({model: auth, router: this.router}).render().el; $('.auth_main_container').append(button); } if (auth.type === 'basicAuth' && $('#basic_auth_button').length === 0) { - button = new SwaggerUi.Views.BasicAuthButton({model: auth}).render().el; + button = new SwaggerUi.Views.BasicAuthButton({model: auth, router: this.router}).render().el; $('.auth_main_container').append(button); } } @@ -1264,6 +1268,7 @@ SwaggerUi.Views.MainView = Backbone.View.extend({ resource.id = resource.id.replace(/\s/g, '_'); var resourceView = new SwaggerUi.Views.ResourceView({ model: resource, + router: this.router, tagName: 'li', id: 'resource_' + resource.id, className: 'resource', @@ -1293,6 +1298,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({ initialize: function(opts) { opts = opts || {}; + this.router = opts.router; this.auths = opts.auths; this.parentId = this.model.parentId; this.nickname = this.model.nickname; @@ -1444,6 +1450,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({ if (signatureModel) { responseSignatureView = new SwaggerUi.Views.SignatureView({ model: signatureModel, + router: this.router, tagName: 'div' }); $('.model-signature', $(this.el)).append(responseSignatureView.render().el); @@ -1479,7 +1486,8 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({ param.type = type; } responseContentTypeView = new SwaggerUi.Views.ResponseContentTypeView({ - model: contentTypeModel + model: contentTypeModel, + router: this.router }); $('.response-content-type', $(this.el)).append(responseContentTypeView.render().el); ref4 = this.model.parameters; @@ -2021,6 +2029,7 @@ SwaggerUi.Views.ParameterView = Backbone.View.extend({ SwaggerUi.Views.ResourceView = Backbone.View.extend({ initialize: function(opts) { opts = opts || {}; + this.router = opts.router; this.auths = opts.auths; if ('' === this.model.description) { this.model.description = null; @@ -2068,6 +2077,7 @@ SwaggerUi.Views.ResourceView = Backbone.View.extend({ // Render an operation and add it to operations li var operationView = new SwaggerUi.Views.OperationView({ model: operation, + router: this.router, tagName: 'li', className: 'endpoint', swaggerOptions: this.options.swaggerOptions, diff --git a/dist/swagger-ui.min.js b/dist/swagger-ui.min.js index f4499c38..1eaf09f2 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)||$("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 this.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}).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