diff --git a/dist/css/print.css b/dist/css/print.css index 54d6bb5b..f0d90689 100644 --- a/dist/css/print.css +++ b/dist/css/print.css @@ -124,11 +124,11 @@ display: block; overflow-x: auto; padding: 0.5em; - background: #f0f0f0; + background: #F0F0F0; } .swagger-section .hljs, .swagger-section .hljs-subst { - color: #444444; + color: #444; } .swagger-section .hljs-keyword, .swagger-section .hljs-attribute, @@ -143,7 +143,7 @@ .swagger-section .hljs-bullet, .swagger-section .hljs-code, .swagger-section .hljs-addition { - color: #1f811f; + color: #1F811F; } .swagger-section .hljs-regexp, .swagger-section .hljs-symbol, @@ -152,7 +152,7 @@ .swagger-section .hljs-link, .swagger-section .hljs-selector-attr, .swagger-section .hljs-selector-pseudo { - color: #bc6060; + color: #BC6060; } .swagger-section .hljs-type, .swagger-section .hljs-string, @@ -173,7 +173,7 @@ color: #888888; } .swagger-section .hljs-meta { - color: #2b6ea1; + color: #2B6EA1; } .swagger-section .hljs-emphasis { font-style: italic; @@ -1181,6 +1181,10 @@ .swagger-section .oauth_submit { text-align: center; } +.swagger-section .authorize__btn:hover { + text-decoration: underline; + cursor: pointer; +} .swagger-section .auth_container .basic_auth__title { color: #547f00; font-size: 1.2em; diff --git a/dist/css/screen.css b/dist/css/screen.css index bcdb0c20..3235151e 100644 --- a/dist/css/screen.css +++ b/dist/css/screen.css @@ -124,11 +124,11 @@ display: block; overflow-x: auto; padding: 0.5em; - background: #f0f0f0; + background: #F0F0F0; } .swagger-section .hljs, .swagger-section .hljs-subst { - color: #444444; + color: #444; } .swagger-section .hljs-keyword, .swagger-section .hljs-attribute, @@ -143,7 +143,7 @@ .swagger-section .hljs-bullet, .swagger-section .hljs-code, .swagger-section .hljs-addition { - color: #1f811f; + color: #1F811F; } .swagger-section .hljs-regexp, .swagger-section .hljs-symbol, @@ -152,7 +152,7 @@ .swagger-section .hljs-link, .swagger-section .hljs-selector-attr, .swagger-section .hljs-selector-pseudo { - color: #bc6060; + color: #BC6060; } .swagger-section .hljs-type, .swagger-section .hljs-string, @@ -173,7 +173,7 @@ color: #888888; } .swagger-section .hljs-meta { - color: #2b6ea1; + color: #2B6EA1; } .swagger-section .hljs-emphasis { font-style: italic; @@ -1181,6 +1181,10 @@ .swagger-section .oauth_submit { text-align: center; } +.swagger-section .authorize__btn:hover { + text-decoration: underline; + cursor: pointer; +} .swagger-section .auth_container .basic_auth__title { color: #547f00; font-size: 1.2em; diff --git a/dist/swagger-ui.js b/dist/swagger-ui.js index 520e4493..02336054 100644 --- a/dist/swagger-ui.js +++ b/dist/swagger-ui.js @@ -12,6 +12,9 @@ this["Handlebars"]["templates"]["apikey_button_view"] = Handlebars.template({"co + 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
apply
\n \n\n"; },"useData":true}); +this["Handlebars"]["templates"]["auth_button"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { + return "Authorize\n"; + },"useData":true}); this["Handlebars"]["templates"]["basic_auth_button_view"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; return "
\n

Basic authentication

\n
\n
" @@ -244,6 +247,7 @@ window.Docs = { }; 'use strict'; +/*jslint eqeq: true*/ Handlebars.registerHelper('sanitize', function(html) { // Strip the script tags from the html, and return it as a Handlebars.SafeString @@ -297,6 +301,29 @@ Handlebars.registerHelper('renderTextParam', function(param) { return new Handlebars.SafeString(result); }); +Handlebars.registerHelper('ifCond', function (v1, operator, v2, options) { + + switch (operator) { + case '==': + return (v1 == v2) ? options.fn(this) : options.inverse(this); + case '===': + return (v1 === v2) ? options.fn(this) : options.inverse(this); + case '<': + return (v1 < v2) ? options.fn(this) : options.inverse(this); + case '<=': + return (v1 <= v2) ? options.fn(this) : options.inverse(this); + case '>': + return (v1 > v2) ? options.fn(this) : options.inverse(this); + case '>=': + return (v1 >= v2) ? options.fn(this) : options.inverse(this); + case '&&': + return (v1 && v2) ? options.fn(this) : options.inverse(this); + case '||': + return (v1 || v2) ? options.fn(this) : options.inverse(this); + default: + return options.inverse(this); + } +}); this["Handlebars"]["templates"]["main"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression, buffer = "
" + escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.title : stack1), depth0)) @@ -382,7 +409,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\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(14, data),"inverse":this.noop,"data":data}); @@ -822,6 +849,14 @@ this["Handlebars"]["templates"]["parameter_content_type"] = Handlebars.template( if (stack1 != null) { buffer += stack1; } return buffer + "\n"; },"useData":true}); +this["Handlebars"]["templates"]["popup"] = 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
      " + + escapeExpression(((helper = (helper = helpers.title || (depth0 != null ? depth0.title : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"title","hash":{},"data":data}) : helper))) + + "
      \n
      \n "; + stack1 = ((helper = (helper = helpers.content || (depth0 != null ? depth0.content : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"content","hash":{},"data":data}) : helper)); + if (stack1 != null) { buffer += stack1; } + return buffer + "\n
      \n

      \n
      \n \n
      \n
      "; +},"useData":true}); this["Handlebars"]["templates"]["resource"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { return " : "; },"3":function(depth0,helpers,partials,data) { @@ -884,32 +919,42 @@ this["Handlebars"]["templates"]["response_content_type"] = Handlebars.template({ return buffer + "\n"; },"useData":true}); this["Handlebars"]["templates"]["signature"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { - var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "
      \n
      "
      -    + escapeExpression(((helper = (helper = helpers.sampleJSON || (depth0 != null ? depth0.sampleJSON : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"sampleJSON","hash":{},"data":data}) : helper)))
      -    + "
      \n "; - stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isParam : depth0), {"name":"if","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data}); - if (stack1 != null) { buffer += stack1; } - return buffer + "\n
      \n"; -},"2":function(depth0,helpers,partials,data) { - return ""; - },"4":function(depth0,helpers,partials,data) { - var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "
      \n
      "
      -    + escapeExpression(((helper = (helper = helpers.sampleXML || (depth0 != null ? depth0.sampleXML : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"sampleXML","hash":{},"data":data}) : helper)))
      -    + "
      \n "; - stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isParam : depth0), {"name":"if","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data}); - if (stack1 != null) { buffer += stack1; } - return buffer + "\n
      \n"; -},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { - var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, buffer = "
      \n\n
      \n\n
      \n
      \n "; + var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, buffer = "\n
      \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; } buffer += "\n
      \n\n
      \n"; - stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.sampleJSON : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.noop,"data":data}); + stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.sampleJSON : depth0), {"name":"if","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data}); if (stack1 != null) { buffer += stack1; } - stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.sampleXML : depth0), {"name":"if","hash":{},"fn":this.program(4, data),"inverse":this.noop,"data":data}); + stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.sampleXML : depth0), {"name":"if","hash":{},"fn":this.program(5, data),"inverse":this.noop,"data":data}); if (stack1 != null) { buffer += stack1; } return buffer + "
      \n
      \n"; -},"useData":true}); +},"2":function(depth0,helpers,partials,data) { + var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "
      \n
      "
      +    + escapeExpression(((helper = (helper = helpers.sampleJSON || (depth0 != null ? depth0.sampleJSON : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"sampleJSON","hash":{},"data":data}) : helper)))
      +    + "
      \n "; + stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isParam : depth0), {"name":"if","hash":{},"fn":this.program(3, data),"inverse":this.noop,"data":data}); + if (stack1 != null) { buffer += stack1; } + return buffer + "\n
      \n"; +},"3":function(depth0,helpers,partials,data) { + return ""; + },"5":function(depth0,helpers,partials,data) { + var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "
      \n
      "
      +    + escapeExpression(((helper = (helper = helpers.sampleXML || (depth0 != null ? depth0.sampleXML : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"sampleXML","hash":{},"data":data}) : helper)))
      +    + "
      \n "; + stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isParam : depth0), {"name":"if","hash":{},"fn":this.program(3, data),"inverse":this.noop,"data":data}); + if (stack1 != null) { buffer += stack1; } + return buffer + "\n
      \n"; +},"7":function(depth0,helpers,partials,data) { + var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; + return " " + + escapeExpression(((helper = (helper = helpers.signature || (depth0 != null ? depth0.signature : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"signature","hash":{},"data":data}) : helper))) + + "\n"; +},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { + var stack1, helperMissing=helpers.helperMissing; + stack1 = ((helpers.ifCond || (depth0 && depth0.ifCond) || helperMissing).call(depth0, (depth0 != null ? depth0.sampleJSON : depth0), "||", (depth0 != null ? depth0.sampleXML : depth0), {"name":"ifCond","hash":{},"fn":this.program(1, data),"inverse":this.program(7, data),"data":data})); + if (stack1 != null) { return stack1; } + else { return ''; } + },"useData":true}); this["Handlebars"]["templates"]["status_code"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { var lambda=this.lambda, escapeExpression=this.escapeExpression; return " \n " @@ -24997,7 +25042,7 @@ SwaggerUi.Views.ApiKeyButton = Backbone.View.extend({ // TODO: append this to gl }, render: function(){ - $(this.el).html(this.template(this.model)); + this.$el.html(this.template(this.model)); return this; }, @@ -25017,6 +25062,59 @@ SwaggerUi.Views.ApiKeyButton = Backbone.View.extend({ // TODO: append this to gl }); 'use strict'; +SwaggerUi.Views.AuthView = Backbone.View.extend({ + events: { + 'click .authorize__btn': 'authorizeBtnClick' + }, + + tpls: { + popup: Handlebars.templates.popup, + authBtn: Handlebars.templates.auth_button + }, + + initialize: function(){}, + + render: function () { + this.$el.html(this.tpls.authBtn()); + + return this; + }, + + authorizeBtnClick: function (e) { + var authsModel; + e.preventDefault(); + + authsModel = {title: 'Please authorize', content: this.renderAuths()}; + + this.popup = new SwaggerUi.Views.PopupView({model: authsModel}); + this.popup.render(); + }, + + renderAuths: function () { + var name, authEl, auth; + var el = $('
      '); + + //todo refactor, copy-pasted from MainView.js + for (name in this.model) { + auth = this.model[name]; + + if (auth.type === 'apiKey') { + authEl = new SwaggerUi.Views.ApiKeyButton({model: auth, router: this.router}).render().el; + el.append(authEl); + } + + if (auth.type === 'basic' && el.find('.basic_auth_container').length === 0) { + authEl = new SwaggerUi.Views.BasicAuthButton({model: auth, router: this.router}).render().el; + el.append(authEl); + } + } + + return el.html(); + } +}); + +'use strict'; + SwaggerUi.Views.BasicAuthButton = Backbone.View.extend({ @@ -25192,24 +25290,13 @@ SwaggerUi.Views.MainView = Backbone.View.extend({ }, render: function () { - var name, authEl, auth; - // Render the outer container for resources $(this.el).html(Handlebars.templates.main(this.model)); this.model.securityDefinitions = this.model.securityDefinitions || {}; - for (name in this.model.securityDefinitions) { - auth = this.model.securityDefinitions[name]; - - if (auth.type === 'apiKey') { - authEl = new SwaggerUi.Views.ApiKeyButton({model: auth, router: this.router}).render().el; - $('.auth_main_container').append(authEl); - } - - if (auth.type === 'basic' && $('.auth_main_container .basic_auth_container').length === 0) { - authEl = new SwaggerUi.Views.BasicAuthButton({model: auth, router: this.router}).render().el; - $('.auth_main_container').append(authEl); - } + if (this.model.securityDefinitions) { + this.authView = new SwaggerUi.Views.AuthView({model: this.model.securityDefinitions}); + this.$('.authorize-wrapper').append(this.authView.render().el); } // Render each resource @@ -25305,21 +25392,21 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({ }, selectText: function(event) { - var doc = document, - text = event.target.firstChild, - range, - selection; - if (doc.body.createTextRange) { - range = document.body.createTextRange(); - range.moveToElementText(text); - range.select(); - } else if (window.getSelection) { - selection = window.getSelection(); - range = document.createRange(); - range.selectNodeContents(text); - selection.removeAllRanges(); - selection.addRange(range); - } + var doc = document, + text = event.target.firstChild, + range, + selection; + if (doc.body.createTextRange) { + range = document.body.createTextRange(); + range.moveToElementText(text); + range.select(); + } else if (window.getSelection) { + selection = window.getSelection(); + range = document.createRange(); + range.selectNodeContents(text); + selection.removeAllRanges(); + selection.addRange(range); + } }, mouseEnter: function(e) { @@ -25364,9 +25451,54 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({ this.model.isReadOnly = true; } this.model.description = this.model.description || this.model.notes; - - this.handleAuth(); - + this.model.oauth = null; + modelAuths = this.model.authorizations || this.model.security; + if (modelAuths) { + if (Array.isArray(modelAuths)) { + for (l = 0, len = modelAuths.length; l < len; l++) { + auths = modelAuths[l]; + for (key in auths) { + for (a in this.auths) { + auth = this.auths[a]; + if (key === auth.name) { + if (auth.type === 'oauth2') { + this.model.oauth = {}; + this.model.oauth.scopes = []; + ref1 = auth.value.scopes; + for (k in ref1) { + v = ref1[k]; + scopeIndex = auths[key].indexOf(k); + if (scopeIndex >= 0) { + o = { + scope: k, + description: v + }; + this.model.oauth.scopes.push(o); + } + } + } + } + } + } + } + } else { + for (k in modelAuths) { + v = modelAuths[k]; + if (k === 'oauth2') { + if (this.model.oauth === null) { + this.model.oauth = {}; + } + if (this.model.oauth.scopes === void 0) { + this.model.oauth.scopes = []; + } + for (m = 0, len1 = v.length; m < len1; m++) { + o = v[m]; + this.model.oauth.scopes.push(o); + } + } + } + } + } if (typeof this.model.responses !== 'undefined') { this.model.responseMessages = []; ref2 = this.model.responses; @@ -25411,6 +25543,10 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({ sampleXML: isXML ? SwaggerUi.partials.signature.createXMLSample(value.definition, value.models) : false, signature: SwaggerUi.partials.signature.getModelSignature(value.name, value.definition, value.models, value.modelPropertyMacro) }; + } else { + signatureModel = { + signature: SwaggerUi.partials.signature.getPrimitiveSignature(value) + }; } } } else if (this.model.responseClassSignature && this.model.responseClassSignature !== 'string') { @@ -25716,7 +25852,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({ // wraps a jquery response as a shred response wrap: function(data) { - var h, headerArray, headers, i, l, len, o; + var h, headerArray, headers, i, l, len, o; headers = {}; headerArray = data.getAllResponseHeaders().split('\r'); for (l = 0, len = headerArray.length; l < len; l++) { @@ -25893,7 +26029,7 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({ code = $('').text('no content'); pre = $('
      ').append(code);
       
      -    // JSON
      +      // JSON
           } else if (contentType === 'application/json' || /\+json$/.test(contentType)) {
             var json = null;
             try {
      @@ -25904,35 +26040,35 @@ SwaggerUi.Views.OperationView = Backbone.View.extend({
             code = $('').text(json);
             pre = $('
      ').append(code);
       
      -    // XML
      +      // XML
           } else if (contentType === 'application/xml' || /\+xml$/.test(contentType)) {
             code = $('').text(this.formatXml(content));
             pre = $('
      ').append(code);
       
      -    // HTML
      +      // HTML
           } else if (contentType === 'text/html') {
             code = $('').html(_.escape(content));
             pre = $('
      ').append(code);
       
      -    // Plain Text
      +      // Plain Text
           } else if (/text\/plain/.test(contentType)) {
             code = $('').text(content);
             pre = $('
      ').append(code);
       
       
      -    // Image
      +      // Image
           } else if (/^image\//.test(contentType)) {
             pre = $('').attr('src', url);
       
      -    // Audio
      +      // Audio
           } else if (/^audio\//.test(contentType) && supportsAudioPlayback(contentType)) {
             pre = $('