This commit is contained in:
Tony Tam
2014-10-17 06:21:00 -07:00
parent 7957201b61
commit f882750e5c
5 changed files with 41 additions and 6 deletions

26
dist/swagger-ui.js vendored
View File

@@ -294,11 +294,19 @@ function program8(depth0,data) {
function program10(depth0,data) { function program10(depth0,data) {
var buffer = "", stack1; var buffer = "", stack1;
buffer += "\n <span style=\"float:right\"><a href=\"http://online.swagger.io/validator/debug?url="; buffer += "\n <span style=\"float:right\"><a href=\"";
if (stack1 = helpers.validatorUrl) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.validatorUrl; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1)
+ "/debug?url=";
if (stack1 = helpers.url) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.url) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.url; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.url; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1) buffer += escapeExpression(stack1)
+ "\"><img id=\"validator\" src=\"http://online.swagger.io/validator?url="; + "\"><img id=\"validator\" src=\"";
if (stack1 = helpers.validatorUrl) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.validatorUrl; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1)
+ "?url=";
if (stack1 = helpers.url) { stack1 = stack1.call(depth0, {hash:{},data:data}); } if (stack1 = helpers.url) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.url; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } else { stack1 = depth0.url; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1) buffer += escapeExpression(stack1)
@@ -1303,6 +1311,14 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
}); });
}; };
SwaggerUi.prototype.setOption = function(option, value) {
return this.options[option] = value;
};
SwaggerUi.prototype.getOption = function(option) {
return this.options[option];
};
SwaggerUi.prototype.updateSwaggerUi = function(data) { SwaggerUi.prototype.updateSwaggerUi = function(data) {
this.options.url = data.url; this.options.url = data.url;
return this.load(); return this.load();
@@ -1512,8 +1528,12 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
if (!this.model.info.version) { if (!this.model.info.version) {
this.model.info.version = this.model.apiVersion; this.model.info.version = this.model.apiVersion;
} }
if (this.model.url.indexOf('http://localhost') === -1 && this.model.swaggerVersion === 2) { if ("validatorUrl" in opts.swaggerOptions) {
return this.model.validatorUrl = opts.swaggerOptions.validatorUrl;
} else if (this.model.url.match(/https?:\/\/localhost/) && this.model.swaggerVersion === 2) {
return this.model.validatorUrl = this.model.url; return this.model.validatorUrl = this.model.url;
} else {
return this.model.validatorUrl = "http://online.swagger.io/validator";
} }
}; };

File diff suppressed because one or more lines are too long

View File

@@ -39,6 +39,14 @@ class SwaggerUi extends Backbone.Router
# Event handler for when the baseUrl/apiKey is entered by user # Event handler for when the baseUrl/apiKey is entered by user
@headerView.on 'update-swagger-ui', (data) => @updateSwaggerUi(data) @headerView.on 'update-swagger-ui', (data) => @updateSwaggerUi(data)
# Set an option after initializing
setOption: (option,value) ->
@options[option] = value
# Get the value of a previously set option
getOption: (option) ->
@options[option]
# Event handler for when url/key is received from user # Event handler for when url/key is received from user
updateSwaggerUi: (data) -> updateSwaggerUi: (data) ->
@options.url = data.url @options.url = data.url

View File

@@ -27,8 +27,15 @@ class MainView extends Backbone.View
if !@model.info.version if !@model.info.version
@model.info.version = @model.apiVersion @model.info.version = @model.apiVersion
if @model.url.indexOf('http://localhost') is -1 and @model.swaggerVersion is 2 if "validatorUrl" of opts.swaggerOptions
# Validator URL specified explicitly
@model.validatorUrl = opts.swaggerOptions.validatorUrl
else if @model.url.match(/https?:\/\/localhost/) and @model.swaggerVersion is 2
# Localhost override
@model.validatorUrl = @model.url @model.validatorUrl = @model.url
else
# Default validator
@model.validatorUrl = "http://online.swagger.io/validator"
render: -> render: ->
# Render the outer container for resources # Render the outer container for resources

View File

@@ -19,7 +19,7 @@
, <span style="font-variant: small-caps">api version</span>: {{info.version}} , <span style="font-variant: small-caps">api version</span>: {{info.version}}
{{/if}}] {{/if}}]
{{#if validatorUrl}} {{#if validatorUrl}}
<span style="float:right"><a href="http://online.swagger.io/validator/debug?url={{url}}"><img id="validator" src="http://online.swagger.io/validator?url={{url}}"></a> <span style="float:right"><a href="{{validatorUrl}}/debug?url={{url}}"><img id="validator" src="{{validatorUrl}}?url={{url}}"></a>
</span> </span>
{{/if}} {{/if}}
</h4> </h4>