updated for #849

This commit is contained in:
Tony Tam
2015-01-29 22:16:07 -08:00
parent 8962e220f1
commit a969680904
5 changed files with 42 additions and 32 deletions

View File

@@ -1547,13 +1547,13 @@ var SwaggerClient = function(url, options) {
this.models = {}; this.models = {};
options = (options||{}); options = (options||{});
if (url)
if (url.url) options = url;
else this.url = url;
else options = url;
if (typeof options.url === 'string') if(typeof url === 'string')
this.url = url;
else if(typeof url === 'object') {
options = url;
this.url = options.url; this.url = options.url;
}
if (typeof options.success === 'function') if (typeof options.success === 'function')
this.success = options.success; this.success = options.success;
@@ -1636,9 +1636,14 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
// legacy support // legacy support
this.authSchemes = response.securityDefinitions; this.authSchemes = response.securityDefinitions;
var location = this.parseUri(this.url); var location;
if(typeof this.url === 'string') {
location = this.parseUri(this.url);
}
if(typeof this.schemes === 'undefined' || this.schemes.length === 0) { if(typeof this.schemes === 'undefined' || this.schemes.length === 0) {
this.scheme = location.scheme; this.scheme = location.scheme || 'http';
} }
else { else {
this.scheme = this.schemes[0]; this.scheme = this.schemes[0];

32
dist/swagger-ui.js vendored
View File

@@ -265,7 +265,7 @@ SwaggerUi = (function(_super) {
_ref.clear(); _ref.clear();
} }
url = this.options.url; url = this.options.url;
if (url.indexOf("http") !== 0) { if (url && url.indexOf("http") !== 0) {
url = this.buildUrl(window.location.href.toString(), url); url = this.buildUrl(window.location.href.toString(), url);
} }
this.options.url = url; this.options.url = url;
@@ -375,7 +375,7 @@ window.SwaggerUi = SwaggerUi;
this["Handlebars"] = this["Handlebars"] || {}; this["Handlebars"] = this["Handlebars"] || {};
this["Handlebars"]["templates"] = this["Handlebars"]["templates"] || {}; this["Handlebars"]["templates"] = this["Handlebars"]["templates"] || {};
this["Handlebars"]["templates"]["apikey_button_view"] = Handlebars.template(/*__DEFINING__*/{"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["apikey_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; var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
return "<div class='auth_button' id='apikey_button'><img class='auth_icon' alt='apply api key' src='images/apikey.jpeg'></div>\n<div class='auth_container' id='apikey_container'>\n <div class='key_input_container'>\n <div class='auth_label'>" return "<div class='auth_button' id='apikey_button'><img class='auth_icon' alt='apply api key' src='images/apikey.jpeg'></div>\n<div class='auth_container' id='apikey_container'>\n <div class='key_input_container'>\n <div class='auth_label'>"
+ 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))) + 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)))
@@ -434,7 +434,7 @@ ApiKeyButton = (function(_super) {
})(Backbone.View); })(Backbone.View);
this["Handlebars"]["templates"]["basic_auth_button_view"] = Handlebars.template(/*__DEFINING__*/{"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["basic_auth_button_view"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
return "<div class='auth_button' id='basic_auth_button'><img class='auth_icon' src='images/password.jpeg'></div>\n<div class='auth_container' id='basic_auth_container'>\n <div class='key_input_container'>\n <div class=\"auth_label\">Username</div>\n <input placeholder=\"username\" class=\"auth_input\" id=\"input_username\" name=\"username\" type=\"text\"/>\n <div class=\"auth_label\">Password</div>\n <input placeholder=\"password\" class=\"auth_input\" id=\"input_password\" name=\"password\" type=\"password\"/>\n <div class='auth_submit'><a class='auth_submit_button' id=\"apply_basic_auth\" href=\"#\">apply</a></div>\n </div>\n</div>\n\n"; return "<div class='auth_button' id='basic_auth_button'><img class='auth_icon' src='images/password.jpeg'></div>\n<div class='auth_container' id='basic_auth_container'>\n <div class='key_input_container'>\n <div class=\"auth_label\">Username</div>\n <input placeholder=\"username\" class=\"auth_input\" id=\"input_username\" name=\"username\" type=\"text\"/>\n <div class=\"auth_label\">Password</div>\n <input placeholder=\"password\" class=\"auth_input\" id=\"input_password\" name=\"password\" type=\"password\"/>\n <div class='auth_submit'><a class='auth_submit_button' id=\"apply_basic_auth\" href=\"#\">apply</a></div>\n </div>\n</div>\n\n";
},"useData":true}); },"useData":true});
var BasicAuthButton, var BasicAuthButton,
@@ -493,7 +493,7 @@ BasicAuthButton = (function(_super) {
})(Backbone.View); })(Backbone.View);
this["Handlebars"]["templates"]["content_type"] = Handlebars.template(/*__DEFINING__*/{"1":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["content_type"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1, buffer = ""; var stack1, buffer = "";
stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data}); stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
@@ -543,7 +543,7 @@ ContentTypeView = (function(_super) {
})(Backbone.View); })(Backbone.View);
this["Handlebars"]["templates"]["main"] = Handlebars.template(/*__DEFINING__*/{"1":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["main"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression, buffer = " <div class=\"info_title\">" var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression, buffer = " <div class=\"info_title\">"
+ escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.title : stack1), depth0)) + escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.title : stack1), depth0))
+ "</div>\n <div class=\"info_description markdown\">"; + "</div>\n <div class=\"info_description markdown\">";
@@ -671,7 +671,7 @@ HeaderView = (function(_super) {
})(Backbone.View); })(Backbone.View);
this["Handlebars"]["templates"]["operation"] = Handlebars.template(/*__DEFINING__*/{"1":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["operation"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
return "deprecated"; return "deprecated";
},"3":function(depth0,helpers,partials,data) { },"3":function(depth0,helpers,partials,data) {
return " <h4>Warning: Deprecated</h4>\n"; return " <h4>Warning: Deprecated</h4>\n";
@@ -897,7 +897,7 @@ MainView = (function(_super) {
})(Backbone.View); })(Backbone.View);
this["Handlebars"]["templates"]["param"] = Handlebars.template(/*__DEFINING__*/{"1":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["param"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1, buffer = ""; var stack1, buffer = "";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isFile : depth0), {"name":"if","hash":{},"fn":this.program(2, data),"inverse":this.program(4, data),"data":data}); stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isFile : depth0), {"name":"if","hash":{},"fn":this.program(2, data),"inverse":this.program(4, data),"data":data});
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
@@ -1551,7 +1551,7 @@ OperationView = (function(_super) {
})(Backbone.View); })(Backbone.View);
this["Handlebars"]["templates"]["param_list"] = Handlebars.template(/*__DEFINING__*/{"1":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["param_list"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
return " multiple='multiple'"; return " multiple='multiple'";
},"3":function(depth0,helpers,partials,data) { },"3":function(depth0,helpers,partials,data) {
return ""; return "";
@@ -1636,7 +1636,7 @@ ParameterContentTypeView = (function(_super) {
})(Backbone.View); })(Backbone.View);
this["Handlebars"]["templates"]["param_readonly"] = Handlebars.template(/*__DEFINING__*/{"1":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["param_readonly"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
return " <textarea class='body-textarea' readonly='readonly' name='" return " <textarea class='body-textarea' readonly='readonly' name='"
+ escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper))) + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
@@ -1778,7 +1778,7 @@ ParameterView = (function(_super) {
})(Backbone.View); })(Backbone.View);
this["Handlebars"]["templates"]["param_readonly_required"] = Handlebars.template(/*__DEFINING__*/{"1":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["param_readonly_required"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
return " <textarea class='body-textarea' readonly='readonly' placeholder='(required)' name='" return " <textarea class='body-textarea' readonly='readonly' placeholder='(required)' name='"
+ escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper))) + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper)))
@@ -1882,7 +1882,7 @@ ResourceView = (function(_super) {
})(Backbone.View); })(Backbone.View);
this["Handlebars"]["templates"]["param_required"] = Handlebars.template(/*__DEFINING__*/{"1":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["param_required"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1, buffer = ""; var stack1, buffer = "";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isFile : depth0), {"name":"if","hash":{},"fn":this.program(2, data),"inverse":this.program(4, data),"data":data}); stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isFile : depth0), {"name":"if","hash":{},"fn":this.program(2, data),"inverse":this.program(4, data),"data":data});
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
@@ -1979,7 +1979,7 @@ ResponseContentTypeView = (function(_super) {
})(Backbone.View); })(Backbone.View);
this["Handlebars"]["templates"]["parameter_content_type"] = Handlebars.template(/*__DEFINING__*/{"1":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["parameter_content_type"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1, buffer = ""; var stack1, buffer = "";
stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.consumes : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data}); stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.consumes : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
@@ -2072,7 +2072,7 @@ SignatureView = (function(_super) {
})(Backbone.View); })(Backbone.View);
this["Handlebars"]["templates"]["resource"] = Handlebars.template(/*__DEFINING__*/{"1":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["resource"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
return " : "; return " : ";
},"3":function(depth0,helpers,partials,data) { },"3":function(depth0,helpers,partials,data) {
var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
@@ -2152,7 +2152,7 @@ StatusCodeView = (function(_super) {
})(Backbone.View); })(Backbone.View);
this["Handlebars"]["templates"]["response_content_type"] = Handlebars.template(/*__DEFINING__*/{"1":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["response_content_type"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1, buffer = ""; var stack1, buffer = "";
stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data}); stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
@@ -2173,7 +2173,7 @@ this["Handlebars"]["templates"]["response_content_type"] = Handlebars.template(/
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer + "</select>\n"; return buffer + "</select>\n";
},"useData":true}); },"useData":true});
this["Handlebars"]["templates"]["signature"] = Handlebars.template(/*__DEFINING__*/{"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { 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 = "<div>\n<ul class=\"signature-nav\">\n <li><a class=\"description-link\" href=\"#\">Model</a></li>\n <li><a class=\"snippet-link\" href=\"#\">Model Schema</a></li>\n</ul>\n<div>\n\n<div class=\"signature-container\">\n <div class=\"description\">\n "; var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<div>\n<ul class=\"signature-nav\">\n <li><a class=\"description-link\" href=\"#\">Model</a></li>\n <li><a class=\"snippet-link\" href=\"#\">Model Schema</a></li>\n</ul>\n<div>\n\n<div class=\"signature-container\">\n <div class=\"description\">\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)); 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; } if (stack1 != null) { buffer += stack1; }
@@ -2181,7 +2181,7 @@ this["Handlebars"]["templates"]["signature"] = Handlebars.template(/*__DEFINING_
+ 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))) + 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)))
+ "</code></pre>\n <small class=\"notice\"></small>\n </div>\n</div>\n\n"; + "</code></pre>\n <small class=\"notice\"></small>\n </div>\n</div>\n\n";
},"useData":true}); },"useData":true});
this["Handlebars"]["templates"]["status_code"] = Handlebars.template(/*__DEFINING__*/{"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["status_code"] = 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 = "<td width='15%' class='code'>" var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<td width='15%' class='code'>"
+ escapeExpression(((helper = (helper = helpers.code || (depth0 != null ? depth0.code : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"code","hash":{},"data":data}) : helper))) + escapeExpression(((helper = (helper = helpers.code || (depth0 != null ? depth0.code : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"code","hash":{},"data":data}) : helper)))
+ "</td>\n<td>"; + "</td>\n<td>";

File diff suppressed because one or more lines are too long

View File

@@ -1547,13 +1547,13 @@ var SwaggerClient = function(url, options) {
this.models = {}; this.models = {};
options = (options||{}); options = (options||{});
if (url)
if (url.url) options = url;
else this.url = url;
else options = url;
if (typeof options.url === 'string') if(typeof url === 'string')
this.url = url;
else if(typeof url === 'object') {
options = url;
this.url = options.url; this.url = options.url;
}
if (typeof options.success === 'function') if (typeof options.success === 'function')
this.success = options.success; this.success = options.success;
@@ -1636,9 +1636,14 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
// legacy support // legacy support
this.authSchemes = response.securityDefinitions; this.authSchemes = response.securityDefinitions;
var location = this.parseUri(this.url); var location;
if(typeof this.url === 'string') {
location = this.parseUri(this.url);
}
if(typeof this.schemes === 'undefined' || this.schemes.length === 0) { if(typeof this.schemes === 'undefined' || this.schemes.length === 0) {
this.scheme = location.scheme; this.scheme = location.scheme || 'http';
} }
else { else {
this.scheme = this.schemes[0]; this.scheme = this.schemes[0];

View File

@@ -57,7 +57,7 @@ class SwaggerUi extends Backbone.Router
# Initialize the API object # Initialize the API object
@mainView?.clear() @mainView?.clear()
url = @options.url url = @options.url
if url.indexOf("http") isnt 0 if url && url.indexOf("http") isnt 0
url = @buildUrl(window.location.href.toString(), url) url = @buildUrl(window.location.href.toString(), url)
@options.url = url @options.url = url