Compare commits

...
17 Commits
Author SHA1 Message Date
Tony Tam 9955bcc69f updated versions 2014-08-01 17:34:15 -07:00
Tony Tam c17cc1010f rebuilt 2014-08-01 17:15:42 -07:00
Tony Tam 2de104aac9 updated templates to support file as body or form params 2014-08-01 17:13:56 -07:00
Tony Tam fbe5278928 updated logger to avoid logging arrays 2014-08-01 17:13:30 -07:00
Tony Tam b09a8e91c9 updated key name 2014-08-01 17:12:08 -07:00
Tony Tam c3904c54c8 updated key name 2014-08-01 17:11:59 -07:00
Tony Tam 26db2ce375 updated swagger-js to 2.0.34 2014-08-01 17:11:36 -07:00
Tony Tam c948b40d34 Merge pull request #496 from chatch/master
sort routes alphabetically (254)
2014-07-28 07:45:31 -07:00
Chris Hatch 5d2bed7025 provide option sorter=[alpha|method] 2014-07-27 21:18:18 +08:00
Chris Hatch 6dc12f733e Merge branch 'master' of https://github.com/wordnik/swagger-ui 2014-07-27 20:24:01 +08:00
Tony Tam dfd5e937d4 Merge pull request #500 from 3scale/patch-2
Fixed undefined variable error
2014-07-24 12:01:46 -07:00
aurelian 9d0417e7f2 fixed undefined variable errors 2014-07-24 17:42:51 +02:00
Chris Hatch 8ad46f0813 remove console.info 2014-07-20 20:21:28 +08:00
Chris Hatch db6419414c #254 alphabetical sort of apis and operations under apis
new option sortAlphabetical=true|false
2014-07-20 20:18:19 +08:00
Tony Tam 9b9b5b4551 updated distro to include #493 2014-07-14 13:42:57 -06:00
Tony Tam 50ded295d9 Merge pull request #493 from vanderlee/patch-1
Fix for issue #492; HTML in response headers
2014-07-14 13:41:46 -06:00
Martijn van der Lee 525241fcd2 Fix for issue #492; HTML in response headers
Fix for issue #492 by escaping the response headers using Underscore
2014-07-14 20:39:54 +02:00
15 changed files with 415 additions and 302 deletions
+1
View File
@@ -59,6 +59,7 @@ To use swagger-ui you should take a look at the [source of swagger-ui html page]
* *dom_id parameter* is the the id of a dom element inside which SwaggerUi will put the user interface for swagger
* *booleanValues* SwaggerUI renders boolean data types as a dropdown. By default it provides a 'true' and 'false' string as the possible choices. You can use this parameter to change the values in dropdown to be something else, for example 0 and 1 by setting booleanValues to new Array(0, 1)
* *docExpansion* controls how the API listing is displayed. It can be set to 'none' (default), 'list' (shows operations for each resource), or 'full' (fully expanded: shows operations and their details)
* *sorter* apply a sort to the API list. It can be 'alpha' (sort paths alphanumerically) or 'method' (sort operations by HTTP method). Default is the order returned by the server unchanged.
* *onComplete* is a callback function parameter which can be passed to be notified of when SwaggerUI has completed rendering successfully.
* *onFailure* is a callback function parameter which can be passed to be notified of when SwaggerUI encountered a failure was unable to render.
* All other parameters are explained in greater detail below
+2 -1
View File
@@ -47,7 +47,8 @@
onFailure: function(data) {
log("Unable to Load SwaggerUI");
},
docExpansion: "none"
docExpansion: "none",
sorter : "alpha"
});
$('#input_apiKey').change(function() {
+48 -55
View File
@@ -48,72 +48,65 @@ function handleLogin() {
str += '</label></li>';
popup.append(str);
}
}
var $win = $(window),
dw = $win.width(),
dh = $win.height(),
st = $win.scrollTop(),
dlgWd = popupDialog.outerWidth(),
dlgHt = popupDialog.outerHeight(),
top = (dh -dlgHt)/2 + st,
left = (dw - dlgWd)/2;
var $win = $(window),
dw = $win.width(),
dh = $win.height(),
st = $win.scrollTop(),
dlgWd = popupDialog.outerWidth(),
dlgHt = popupDialog.outerHeight(),
top = (dh -dlgHt)/2 + st,
left = (dw - dlgWd)/2;
popupDialog.css({
top: (top < 0? 0 : top) + 'px',
left: (left < 0? 0 : left) + 'px'
});
popupDialog.css({
top: (top < 0? 0 : top) + 'px',
left: (left < 0? 0 : left) + 'px'
});
popupDialog.find('button.api-popup-cancel').click(function() {
popupMask.hide();
popupDialog.hide();
});
popupDialog.find('button.api-popup-authbtn').click(function() {
popupMask.hide();
popupDialog.hide();
popupDialog.find('button.api-popup-cancel').click(function() {
popupMask.hide();
popupDialog.hide();
});
popupDialog.find('button.api-popup-authbtn').click(function() {
popupMask.hide();
popupDialog.hide();
var authSchemes = window.swaggerUi.api.authSchemes;
var location = window.location;
var locationUrl = location.protocol + '//' + location.host + location.pathname;
var redirectUrl = locationUrl.replace("index.html","").concat("/o2c.html").replace("//o2c.html","/o2c.html");
var url = null;
var authSchemes = window.swaggerUi.api.authSchemes;
var host = window.location;
var redirectUrl = host.protocol + '//' + host.host + "/o2c.html";
var url = null;
var p = window.swaggerUi.api.authSchemes;
for (var key in p) {
if (p.hasOwnProperty(key)) {
var o = p[key].grantTypes;
for(var t in o) {
if(o.hasOwnProperty(t) && t === 'implicit') {
var dets = o[t];
url = dets.loginEndpoint.url + "?response_type=token";
window.swaggerUi.tokenName = dets.tokenName;
}
var p = window.swaggerUi.api.authSchemes;
for (var key in p) {
if (p.hasOwnProperty(key)) {
var o = p[key].grantTypes;
for(var t in o) {
if(o.hasOwnProperty(t) && t === 'implicit') {
var dets = o[t];
url = dets.loginEndpoint.url + "?response_type=token";
window.swaggerUi.tokenName = dets.tokenName;
}
}
}
var scopes = [];
var scopeForUrl='';
var o = $('.api-popup-scopes').find('input:checked');
}
var scopes = []
var o = $('.api-popup-scopes').find('input:checked');
for(var k =0; k < o.length; k++) {
scopes.push($(o[k]).attr("scope"));
if(k > 0){
scopeForUrl+=' ';
}
scopeForUrl+=$(o[k]).attr("scope");
}
for(k =0; k < o.length; k++) {
scopes.push($(o[k]).attr("scope"));
}
window.enabledScopes=scopes;
window.enabledScopes=scopes;
url += '&redirect_uri=' + encodeURIComponent(redirectUrl);
url += '&realm=' + encodeURIComponent(realm);
url += '&client_id=' + encodeURIComponent(clientId);
url += '&scope=' + encodeURIComponent(scopeForUrl);
url += '&redirect_uri=' + encodeURIComponent(redirectUrl);
url += '&realm=' + encodeURIComponent(realm);
url += '&client_id=' + encodeURIComponent(clientId);
url += '&scope=' + encodeURIComponent(scopes);
window.open(url);
});
window.open(url);
});
}
popupMask.show();
popupDialog.show();
return;
@@ -211,7 +204,7 @@ function onOAuthComplete(token) {
}
});
window.authorizations.add("key", new ApiKeyAuthorization("Authorization", "Bearer " + b, "header"));
window.authorizations.add("oauth2", new ApiKeyAuthorization("Authorization", "Bearer " + b, "header"));
}
}
}
+115 -79
View File
@@ -1,5 +1,5 @@
// swagger.js
// version 2.0.31
// version 2.0.34
var __bind = function(fn, me){
return function(){
@@ -11,7 +11,7 @@ log = function(){
log.history = log.history || [];
log.history.push(arguments);
if(this.console){
console.log( Array.prototype.slice.call(arguments) );
console.log( Array.prototype.slice.call(arguments)[0] );
}
};
@@ -378,20 +378,22 @@ SwaggerResource.prototype.getAbsoluteBasePath = function (relativeBasePath) {
pos = url.lastIndexOf(relativeBasePath);
var parts = url.split("/");
var rootUrl = parts[0] + "//" + parts[2];
//if the relative path is '/' return the root url
if (relativeBasePath === '/'){
return rootUrl
if(relativeBasePath.indexOf("http") === 0)
return relativeBasePath;
if(relativeBasePath === "/")
return rootUrl;
if(relativeBasePath.substring(0, 1) == "/") {
// use root + relative
return rootUrl + relativeBasePath;
}
//if the relative path is not in the base path
else if (pos === -1 ) {
if (relativeBasePath.indexOf("/") === 0) {
return url + relativeBasePath;
} else {
return url + "/" + relativeBasePath;
}
//If the relative path is in the base path
} else {
return url.substring(0, pos) + relativeBasePath;
else {
var pos = this.basePath.lastIndexOf("/");
var base = this.basePath.substring(0, pos);
if(base.substring(base.length - 1) == "/")
return base + relativeBasePath;
else
return base + "/" + relativeBasePath;
}
};
@@ -1097,64 +1099,12 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
this.type = this.type.toUpperCase();
var myHeaders = {};
// set request, response content type headers
var headers = this.setHeaders(params, this.operation);
var body = params.body;
var parent = params["parent"];
var requestContentType = "application/json";
var formParams = [];
var fileParams = [];
var params = this.operation.parameters;
for(var i = 0; i < params.length; i++) {
var param = params[i];
if(param.paramType === "form")
formParams.push(param);
else if(param.paramType === "file")
fileParams.push(param);
}
if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH")) {
if (this.opts.requestContentType) {
requestContentType = this.opts.requestContentType;
}
} else {
// if any form params, content type must be set
if(formParams.length > 0) {
if(fileParams.length > 0)
requestContentType = "multipart/form-data";
else
requestContentType = "application/x-www-form-urlencoded";
}
else if (this.type == "DELETE")
body = "{}";
else if (this.type != "DELETE")
requestContentType = null;
}
if (requestContentType && this.operation.consumes) {
if (this.operation.consumes[requestContentType] === 'undefined') {
log("server doesn't consume " + requestContentType + ", try " + JSON.stringify(this.operation.consumes));
if (this.requestContentType === null) {
requestContentType = this.operation.consumes[0];
}
}
}
var responseContentType = null;
if (this.opts.responseContentType) {
responseContentType = this.opts.responseContentType;
} else {
responseContentType = "application/json";
}
if (responseContentType && this.operation.produces) {
if (this.operation.produces[responseContentType] === 'undefined') {
log("server can't produce " + responseContentType);
}
}
if (requestContentType && requestContentType.indexOf("application/x-www-form-urlencoded") === 0) {
// encode the body for form submits
if (headers["Accept"] && headers["Accept"].indexOf("application/x-www-form-urlencoded") === 0) {
var fields = {};
var possibleParams = {};
var values = {};
@@ -1176,19 +1126,12 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
}
body = encoded;
}
var name;
for (name in this.headers)
myHeaders[name] = this.headers[name];
if ((requestContentType && body !== "") || (requestContentType === "application/x-www-form-urlencoded"))
myHeaders["Content-Type"] = requestContentType;
if (responseContentType)
myHeaders["Accept"] = responseContentType;
if (!((this.headers != null) && (this.headers.mock != null))) {
obj = {
url: this.url,
method: this.type,
headers: myHeaders,
headers: headers,
body: body,
useJQuery: this.useJQuery,
on: {
@@ -1225,6 +1168,99 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
}
};
SwaggerRequest.prototype.setHeaders = function(params, operation) {
// default type
var accepts = "application/json";
var contentType = null;
var allDefinedParams = this.operation.parameters;
var definedFormParams = [];
var definedFileParams = [];
var body = params.body;
var headers = {};
// get params from the operation and set them in definedFileParams, definedFormParams, headers
var i;
for(i = 0; i < allDefinedParams.length; i++) {
var param = allDefinedParams[i];
if(param.paramType === "form")
definedFormParams.push(param);
else if(param.paramType === "file")
definedFileParams.push(param);
else if(param.paramType === "header" && this.params.headers) {
var key = param.name;
var headerValue = this.params.headers[param.name];
if(typeof this.params.headers[param.name] !== 'undefined')
headers[key] = headerValue;
}
}
// if there's a body, need to set the accepts header via requestContentType
if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH" || this.type === "DELETE")) {
if (this.opts.requestContentType)
accepts = this.opts.requestContentType;
} else {
// if any form params, content type must be set
if(definedFormParams.length > 0) {
if(definedFileParams.length > 0)
accepts = "multipart/form-data";
else
accepts = "application/x-www-form-urlencoded";
}
else if (this.type == "DELETE")
body = "{}";
else if (this.type != "DELETE")
accepts = null;
}
if (contentType && this.operation.consumes) {
if (this.operation.consumes.indexOf(contentType) === -1) {
log("server doesn't consume " + contentType + ", try " + JSON.stringify(this.operation.consumes));
contentType = this.operation.consumes[0];
}
}
if (this.opts.responseContentType) {
accepts = this.opts.responseContentType;
} else {
accepts = "application/json";
}
if (accepts && this.operation.produces) {
if (this.operation.produces.indexOf(accepts) === -1) {
log("server can't produce " + accepts);
accepts = this.operation.produces[0];
}
}
if (contentType && contentType.indexOf("application/x-www-form-urlencoded") === 0) {
var fields = {};
var possibleParams = {};
var values = {};
var key;
for(key in formParams){
var param = formParams[key];
values[param.name] = param;
}
var encoded = "";
var key;
for(key in values) {
value = this.params[key];
if(typeof value !== 'undefined'){
if(encoded !== "")
encoded += "&";
encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
}
}
body = encoded;
}
if ((contentType && body !== "") || (contentType === "application/x-www-form-urlencoded"))
headers["Content-Type"] = contentType;
if (accepts)
headers["Accept"] = accepts;
return headers;
}
SwaggerRequest.prototype.asCurl = function() {
var results = [];
if(this.headers) {
+52 -15
View File
@@ -1,5 +1,5 @@
// swagger-ui.js
// version 2.0.18
// version 2.0.19
$(function() {
// Helper function for vertically aligning DOM elements
@@ -68,7 +68,7 @@ log = function(){
log.history = log.history || [];
log.history.push(arguments);
if(this.console){
console.log( Array.prototype.slice.call(arguments) );
console.log( Array.prototype.slice.call(arguments)[0] );
}
};
@@ -562,7 +562,7 @@ function program9(depth0,data) {
var buffer = "", stack1;
buffer += "\n ";
stack1 = helpers['if'].call(depth0, depth0.defaultValue, {hash:{},inverse:self.program(12, program12, data),fn:self.program(10, program10, data),data:data});
stack1 = helpers['if'].call(depth0, depth0.isFile, {hash:{},inverse:self.program(10, program10, data),fn:self.program(2, program2, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n ";
return buffer;
@@ -570,7 +570,16 @@ function program9(depth0,data) {
function program10(depth0,data) {
var buffer = "", stack1;
buffer += "\n <input class='parameter' minlength='0' name='";
buffer += "\n ";
stack1 = helpers['if'].call(depth0, depth0.defaultValue, {hash:{},inverse:self.program(13, program13, data),fn:self.program(11, program11, data),data:data});
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n ";
return buffer;
}
function program11(depth0,data) {
var buffer = "", stack1;
buffer += "\n <input class='parameter' minlength='0' name='";
if (stack1 = helpers.name) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1)
@@ -578,18 +587,18 @@ function program10(depth0,data) {
if (stack1 = helpers.defaultValue) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.defaultValue; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1)
+ "'/>\n ";
+ "'/>\n ";
return buffer;
}
function program12(depth0,data) {
function program13(depth0,data) {
var buffer = "", stack1;
buffer += "\n <input class='parameter' minlength='0' name='";
buffer += "\n <input class='parameter' minlength='0' name='";
if (stack1 = helpers.name) { stack1 = stack1.call(depth0, {hash:{},data:data}); }
else { stack1 = depth0.name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; }
buffer += escapeExpression(stack1)
+ "' placeholder='' type='text' value=''/>\n ";
+ "' placeholder='' type='text' value=''/>\n ";
return buffer;
}
@@ -1289,7 +1298,8 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
this.showMessage('Finished Loading Resource Information. Rendering Swagger UI...');
this.mainView = new MainView({
model: this.api,
el: $('#' + this.dom_id)
el: $('#' + this.dom_id),
swaggerOptions: this.options
}).render();
this.showMessage();
switch (this.options.docExpansion) {
@@ -1422,6 +1432,8 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
})(Backbone.View);
MainView = (function(_super) {
var sorters;
__extends(MainView, _super);
function MainView() {
@@ -1429,7 +1441,33 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
return _ref2;
}
MainView.prototype.initialize = function() {};
sorters = {
'alpha': function(a, b) {
return a.path.localeCompare(b.path);
},
'method': function(a, b) {
return a.method.localeCompare(b.method);
}
};
MainView.prototype.initialize = function(opts) {
var route, sorter, sorterName, _i, _len, _ref3;
if (opts == null) {
opts = {};
}
if (opts.swaggerOptions.sorter) {
sorterName = opts.swaggerOptions.sorter;
sorter = sorters[sorterName];
_ref3 = this.model.apisArray;
for (_i = 0, _len = _ref3.length; _i < _len; _i++) {
route = _ref3[_i];
route.operationsArray.sort(sorter);
}
if (sorterName === "alpha") {
return this.model.apisArray.sort(sorter);
}
}
};
MainView.prototype.render = function() {
var counter, id, resource, resources, _i, _len, _ref3;
@@ -1541,8 +1579,8 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
OperationView.prototype.mouseEnter = function(e) {
var elem, hgh, pos, scMaxX, scMaxY, scX, scY, wd, x, y;
elem = $(e.currentTarget.parentNode).find('#api_information_panel');
x = event.pageX;
y = event.pageY;
x = e.pageX;
y = e.pageY;
scX = $(window).scrollLeft();
scY = $(window).scrollTop();
scMaxX = scX + $(window).width();
@@ -1747,7 +1785,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
for (_j = 0, _len1 = _ref6.length; _j < _len1; _j++) {
param = _ref6[_j];
if (param.paramType === 'form') {
if (map[param.name] !== void 0) {
if (param.type.toLowerCase() !== 'file' && map[param.name] !== void 0) {
bodyParam.append(param.name, map[param.name]);
}
}
@@ -1769,7 +1807,6 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
params += 1;
}
}
log(bodyParam);
this.invocationUrl = this.model.supportHeaderParams() ? (headerParams = this.model.getHeaderParams(map), this.model.urlify(map, false)) : this.model.urlify(map, true);
$(".request_url", $(this.el)).html("<pre>" + this.invocationUrl + "</pre>");
obj = {
@@ -1970,7 +2007,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
$(".request_url", $(this.el)).html("<pre>" + url + "</pre>");
$(".response_code", $(this.el)).html("<pre>" + response.status + "</pre>");
$(".response_body", $(this.el)).html(response_body);
$(".response_headers", $(this.el)).html("<pre>" + JSON.stringify(response.headers, null, " ").replace(/\n/g, "<br>") + "</pre>");
$(".response_headers", $(this.el)).html("<pre>" + _.escape(JSON.stringify(response.headers, null, " ")).replace(/\n/g, "<br>") + "</pre>");
$(".response", $(this.el)).slideDown();
$(".response_hider", $(this.el)).show();
$(".response_throbber", $(this.el)).hide();
+1 -1
View File
File diff suppressed because one or more lines are too long
+48 -55
View File
@@ -48,72 +48,65 @@ function handleLogin() {
str += '</label></li>';
popup.append(str);
}
}
var $win = $(window),
dw = $win.width(),
dh = $win.height(),
st = $win.scrollTop(),
dlgWd = popupDialog.outerWidth(),
dlgHt = popupDialog.outerHeight(),
top = (dh -dlgHt)/2 + st,
left = (dw - dlgWd)/2;
var $win = $(window),
dw = $win.width(),
dh = $win.height(),
st = $win.scrollTop(),
dlgWd = popupDialog.outerWidth(),
dlgHt = popupDialog.outerHeight(),
top = (dh -dlgHt)/2 + st,
left = (dw - dlgWd)/2;
popupDialog.css({
top: (top < 0? 0 : top) + 'px',
left: (left < 0? 0 : left) + 'px'
});
popupDialog.css({
top: (top < 0? 0 : top) + 'px',
left: (left < 0? 0 : left) + 'px'
});
popupDialog.find('button.api-popup-cancel').click(function() {
popupMask.hide();
popupDialog.hide();
});
popupDialog.find('button.api-popup-authbtn').click(function() {
popupMask.hide();
popupDialog.hide();
popupDialog.find('button.api-popup-cancel').click(function() {
popupMask.hide();
popupDialog.hide();
});
popupDialog.find('button.api-popup-authbtn').click(function() {
popupMask.hide();
popupDialog.hide();
var authSchemes = window.swaggerUi.api.authSchemes;
var location = window.location;
var locationUrl = location.protocol + '//' + location.host + location.pathname;
var redirectUrl = locationUrl.replace("index.html","").concat("/o2c.html").replace("//o2c.html","/o2c.html");
var url = null;
var authSchemes = window.swaggerUi.api.authSchemes;
var host = window.location;
var redirectUrl = host.protocol + '//' + host.host + "/o2c.html";
var url = null;
var p = window.swaggerUi.api.authSchemes;
for (var key in p) {
if (p.hasOwnProperty(key)) {
var o = p[key].grantTypes;
for(var t in o) {
if(o.hasOwnProperty(t) && t === 'implicit') {
var dets = o[t];
url = dets.loginEndpoint.url + "?response_type=token";
window.swaggerUi.tokenName = dets.tokenName;
}
var p = window.swaggerUi.api.authSchemes;
for (var key in p) {
if (p.hasOwnProperty(key)) {
var o = p[key].grantTypes;
for(var t in o) {
if(o.hasOwnProperty(t) && t === 'implicit') {
var dets = o[t];
url = dets.loginEndpoint.url + "?response_type=token";
window.swaggerUi.tokenName = dets.tokenName;
}
}
}
var scopes = [];
var scopeForUrl='';
var o = $('.api-popup-scopes').find('input:checked');
}
var scopes = []
var o = $('.api-popup-scopes').find('input:checked');
for(var k =0; k < o.length; k++) {
scopes.push($(o[k]).attr("scope"));
if(k > 0){
scopeForUrl+=' ';
}
scopeForUrl+=$(o[k]).attr("scope");
}
for(k =0; k < o.length; k++) {
scopes.push($(o[k]).attr("scope"));
}
window.enabledScopes=scopes;
window.enabledScopes=scopes;
url += '&redirect_uri=' + encodeURIComponent(redirectUrl);
url += '&realm=' + encodeURIComponent(realm);
url += '&client_id=' + encodeURIComponent(clientId);
url += '&scope=' + encodeURIComponent(scopeForUrl);
url += '&redirect_uri=' + encodeURIComponent(redirectUrl);
url += '&realm=' + encodeURIComponent(realm);
url += '&client_id=' + encodeURIComponent(clientId);
url += '&scope=' + encodeURIComponent(scopes);
window.open(url);
});
window.open(url);
});
}
popupMask.show();
popupDialog.show();
return;
@@ -211,7 +204,7 @@ function onOAuthComplete(token) {
}
});
window.authorizations.add("key", new ApiKeyAuthorization("Authorization", "Bearer " + b, "header"));
window.authorizations.add("oauth2", new ApiKeyAuthorization("Authorization", "Bearer " + b, "header"));
}
}
}
+115 -79
View File
@@ -1,5 +1,5 @@
// swagger.js
// version 2.0.31
// version 2.0.34
var __bind = function(fn, me){
return function(){
@@ -11,7 +11,7 @@ log = function(){
log.history = log.history || [];
log.history.push(arguments);
if(this.console){
console.log( Array.prototype.slice.call(arguments) );
console.log( Array.prototype.slice.call(arguments)[0] );
}
};
@@ -378,20 +378,22 @@ SwaggerResource.prototype.getAbsoluteBasePath = function (relativeBasePath) {
pos = url.lastIndexOf(relativeBasePath);
var parts = url.split("/");
var rootUrl = parts[0] + "//" + parts[2];
//if the relative path is '/' return the root url
if (relativeBasePath === '/'){
return rootUrl
if(relativeBasePath.indexOf("http") === 0)
return relativeBasePath;
if(relativeBasePath === "/")
return rootUrl;
if(relativeBasePath.substring(0, 1) == "/") {
// use root + relative
return rootUrl + relativeBasePath;
}
//if the relative path is not in the base path
else if (pos === -1 ) {
if (relativeBasePath.indexOf("/") === 0) {
return url + relativeBasePath;
} else {
return url + "/" + relativeBasePath;
}
//If the relative path is in the base path
} else {
return url.substring(0, pos) + relativeBasePath;
else {
var pos = this.basePath.lastIndexOf("/");
var base = this.basePath.substring(0, pos);
if(base.substring(base.length - 1) == "/")
return base + relativeBasePath;
else
return base + "/" + relativeBasePath;
}
};
@@ -1097,64 +1099,12 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
this.type = this.type.toUpperCase();
var myHeaders = {};
// set request, response content type headers
var headers = this.setHeaders(params, this.operation);
var body = params.body;
var parent = params["parent"];
var requestContentType = "application/json";
var formParams = [];
var fileParams = [];
var params = this.operation.parameters;
for(var i = 0; i < params.length; i++) {
var param = params[i];
if(param.paramType === "form")
formParams.push(param);
else if(param.paramType === "file")
fileParams.push(param);
}
if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH")) {
if (this.opts.requestContentType) {
requestContentType = this.opts.requestContentType;
}
} else {
// if any form params, content type must be set
if(formParams.length > 0) {
if(fileParams.length > 0)
requestContentType = "multipart/form-data";
else
requestContentType = "application/x-www-form-urlencoded";
}
else if (this.type == "DELETE")
body = "{}";
else if (this.type != "DELETE")
requestContentType = null;
}
if (requestContentType && this.operation.consumes) {
if (this.operation.consumes[requestContentType] === 'undefined') {
log("server doesn't consume " + requestContentType + ", try " + JSON.stringify(this.operation.consumes));
if (this.requestContentType === null) {
requestContentType = this.operation.consumes[0];
}
}
}
var responseContentType = null;
if (this.opts.responseContentType) {
responseContentType = this.opts.responseContentType;
} else {
responseContentType = "application/json";
}
if (responseContentType && this.operation.produces) {
if (this.operation.produces[responseContentType] === 'undefined') {
log("server can't produce " + responseContentType);
}
}
if (requestContentType && requestContentType.indexOf("application/x-www-form-urlencoded") === 0) {
// encode the body for form submits
if (headers["Accept"] && headers["Accept"].indexOf("application/x-www-form-urlencoded") === 0) {
var fields = {};
var possibleParams = {};
var values = {};
@@ -1176,19 +1126,12 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
}
body = encoded;
}
var name;
for (name in this.headers)
myHeaders[name] = this.headers[name];
if ((requestContentType && body !== "") || (requestContentType === "application/x-www-form-urlencoded"))
myHeaders["Content-Type"] = requestContentType;
if (responseContentType)
myHeaders["Accept"] = responseContentType;
if (!((this.headers != null) && (this.headers.mock != null))) {
obj = {
url: this.url,
method: this.type,
headers: myHeaders,
headers: headers,
body: body,
useJQuery: this.useJQuery,
on: {
@@ -1225,6 +1168,99 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
}
};
SwaggerRequest.prototype.setHeaders = function(params, operation) {
// default type
var accepts = "application/json";
var contentType = null;
var allDefinedParams = this.operation.parameters;
var definedFormParams = [];
var definedFileParams = [];
var body = params.body;
var headers = {};
// get params from the operation and set them in definedFileParams, definedFormParams, headers
var i;
for(i = 0; i < allDefinedParams.length; i++) {
var param = allDefinedParams[i];
if(param.paramType === "form")
definedFormParams.push(param);
else if(param.paramType === "file")
definedFileParams.push(param);
else if(param.paramType === "header" && this.params.headers) {
var key = param.name;
var headerValue = this.params.headers[param.name];
if(typeof this.params.headers[param.name] !== 'undefined')
headers[key] = headerValue;
}
}
// if there's a body, need to set the accepts header via requestContentType
if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH" || this.type === "DELETE")) {
if (this.opts.requestContentType)
accepts = this.opts.requestContentType;
} else {
// if any form params, content type must be set
if(definedFormParams.length > 0) {
if(definedFileParams.length > 0)
accepts = "multipart/form-data";
else
accepts = "application/x-www-form-urlencoded";
}
else if (this.type == "DELETE")
body = "{}";
else if (this.type != "DELETE")
accepts = null;
}
if (contentType && this.operation.consumes) {
if (this.operation.consumes.indexOf(contentType) === -1) {
log("server doesn't consume " + contentType + ", try " + JSON.stringify(this.operation.consumes));
contentType = this.operation.consumes[0];
}
}
if (this.opts.responseContentType) {
accepts = this.opts.responseContentType;
} else {
accepts = "application/json";
}
if (accepts && this.operation.produces) {
if (this.operation.produces.indexOf(accepts) === -1) {
log("server can't produce " + accepts);
accepts = this.operation.produces[0];
}
}
if (contentType && contentType.indexOf("application/x-www-form-urlencoded") === 0) {
var fields = {};
var possibleParams = {};
var values = {};
var key;
for(key in formParams){
var param = formParams[key];
values[param.name] = param;
}
var encoded = "";
var key;
for(key in values) {
value = this.params[key];
if(typeof value !== 'undefined'){
if(encoded !== "")
encoded += "&";
encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
}
}
body = encoded;
}
if ((contentType && body !== "") || (contentType === "application/x-www-form-urlencoded"))
headers["Content-Type"] = contentType;
if (accepts)
headers["Accept"] = accepts;
return headers;
}
SwaggerRequest.prototype.asCurl = function() {
var results = [];
if(this.headers) {
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "swagger-ui",
"version": "2.0.18",
"version": "2.0.19",
"description": "Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API",
"scripts": {
"build": "PATH=$PATH:./node_modules/.bin cake dist",
@@ -18,8 +18,8 @@
"license": "Apache",
"readmeFilename": "README.md",
"dependencies": {
"coffee-script": "~1.5.0",
"swagger-client": "2.0.29",
"coffee-script": "~1.6.3",
"swagger-client": "2.0.34",
"handlebars": "~1.0.10",
"less": "~1.4.2"
}
+1 -1
View File
@@ -55,7 +55,7 @@ class SwaggerUi extends Backbone.Router
# so it gets called when SwaggerApi completes loading
render:() ->
@showMessage('Finished Loading Resource Information. Rendering Swagger UI...')
@mainView = new MainView({model: @api, el: $('#' + @dom_id)}).render()
@mainView = new MainView({model: @api, el: $('#' + @dom_id), swaggerOptions: @options}).render()
@showMessage()
switch @options.docExpansion
when "full" then Docs.expandOperationsForResource('')
+14 -2
View File
@@ -1,6 +1,18 @@
class MainView extends Backbone.View
initialize: ->
sorters = {
'alpha' : (a,b) -> return a.path.localeCompare(b.path),
'method' : (a,b) -> return a.method.localeCompare(b.method),
}
initialize: (opts={}) ->
if opts.swaggerOptions.sorter
sorterName = opts.swaggerOptions.sorter
sorter = sorters[sorterName]
for route in @model.apisArray
route.operationsArray.sort sorter
if (sorterName == "alpha") # sort top level paths if alpha
@model.apisArray.sort sorter
render: ->
# Render the outer container for resources
$(@el).html(Handlebars.templates.main(@model))
@@ -25,4 +37,4 @@ class MainView extends Backbone.View
$('#resources').append resourceView.render().el
clear: ->
$(@el).html ''
$(@el).html ''
@@ -14,8 +14,8 @@ class OperationView extends Backbone.View
mouseEnter: (e) ->
elem = $(e.currentTarget.parentNode).find('#api_information_panel')
x = event.pageX
y = event.pageY
x = e.pageX
y = e.pageY
scX = $(window).scrollLeft()
scY = $(window).scrollTop()
scMaxX = scX + $(window).width()
@@ -162,7 +162,7 @@ class OperationView extends Backbone.View
# add params
for param in @model.parameters
if param.paramType is 'form'
if map[param.name] != undefined
if param.type.toLowerCase() isnt 'file' and map[param.name] != undefined
bodyParam.append(param.name, map[param.name])
# headers in operation
@@ -179,8 +179,6 @@ class OperationView extends Backbone.View
bodyParam.append($(el).attr('name'), el.files[0])
params += 1
log(bodyParam)
@invocationUrl =
if @model.supportHeaderParams()
headerParams = @model.getHeaderParams(map)
@@ -361,7 +359,7 @@ class OperationView extends Backbone.View
$(".request_url", $(@el)).html "<pre>" + url + "</pre>"
$(".response_code", $(@el)).html "<pre>" + response.status + "</pre>"
$(".response_body", $(@el)).html response_body
$(".response_headers", $(@el)).html "<pre>" + JSON.stringify(response.headers, null, " ").replace(/\n/g, "<br>") + "</pre>"
$(".response_headers", $(@el)).html "<pre>" + _.escape(JSON.stringify(response.headers, null, " ")).replace(/\n/g, "<br>") + "</pre>"
$(".response", $(@el)).slideDown()
$(".response_hider", $(@el)).show()
$(".response_throbber", $(@el)).hide()
+2 -1
View File
@@ -47,7 +47,8 @@
onFailure: function(data) {
log("Unable to Load SwaggerUI");
},
docExpansion: "none"
docExpansion: "none",
sorter : "alpha"
});
$('#input_apiKey').change(function() {
+1 -1
View File
@@ -66,7 +66,7 @@ log = function(){
log.history = log.history || [];
log.history.push(arguments);
if(this.console){
console.log( Array.prototype.slice.call(arguments) );
console.log( Array.prototype.slice.call(arguments)[0] );
}
};
+8 -3
View File
@@ -15,10 +15,15 @@
{{/if}}
{{/if}}
{{else}}
{{#if defaultValue}}
<input class='parameter' minlength='0' name='{{name}}' placeholder='' type='text' value='{{defaultValue}}'/>
{{#if isFile}}
<input type="file" name='{{name}}'/>
<div class="parameter-content-type" />
{{else}}
<input class='parameter' minlength='0' name='{{name}}' placeholder='' type='text' value=''/>
{{#if defaultValue}}
<input class='parameter' minlength='0' name='{{name}}' placeholder='' type='text' value='{{defaultValue}}'/>
{{else}}
<input class='parameter' minlength='0' name='{{name}}' placeholder='' type='text' value=''/>
{{/if}}
{{/if}}
{{/if}}