Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee199633f6 | ||
|
|
4ea20859c7 | ||
|
|
0a52e344e7 | ||
|
|
e04b756521 | ||
|
|
9955bcc69f | ||
|
|
c17cc1010f | ||
|
|
2de104aac9 | ||
|
|
fbe5278928 | ||
|
|
b09a8e91c9 | ||
|
|
c3904c54c8 | ||
|
|
26db2ce375 | ||
|
|
28c7597138 | ||
|
|
c948b40d34 | ||
|
|
5d2bed7025 | ||
|
|
6dc12f733e | ||
|
|
dfd5e937d4 | ||
|
|
9d0417e7f2 | ||
|
|
8ad46f0813 | ||
|
|
db6419414c | ||
|
|
9b9b5b4551 | ||
|
|
50ded295d9 | ||
|
|
525241fcd2 | ||
|
|
855b31d73b | ||
|
|
7945dec86c | ||
|
|
011f70935d | ||
|
|
f0a099728c | ||
|
|
d673d5d1cb | ||
|
|
8ad843fc4f | ||
|
|
1b89ab4128 | ||
|
|
bfc0c987df | ||
|
|
e250ab3e66 | ||
|
|
25c33cb472 | ||
|
|
b8e4317929 | ||
|
|
c2dd77ff3a | ||
|
|
4b535adcb7 | ||
|
|
05588bb669 | ||
|
|
f7694d8525 | ||
|
|
d96fd58016 | ||
|
|
52db742a10 |
@@ -59,8 +59,10 @@ 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.
|
||||
* *highlightSizeThreshold* any size response below this threshold will be highlighted syntactically, attempting to highlight large responses can lead to browser hangs, not including a threshold will default to highlight all returned responses
|
||||
* All other parameters are explained in greater detail below
|
||||
|
||||
|
||||
|
||||
Vendored
+5
-2
@@ -2,9 +2,11 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Swagger UI</title>
|
||||
<link href='https://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
|
||||
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
|
||||
<link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/>
|
||||
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
|
||||
<link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/>
|
||||
<link href='css/screen.css' media='print' rel='stylesheet' type='text/css'/>
|
||||
<script type="text/javascript" src="lib/shred.bundle.js"></script>
|
||||
<script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
|
||||
<script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
|
||||
@@ -45,7 +47,8 @@
|
||||
onFailure: function(data) {
|
||||
log("Unable to Load SwaggerUI");
|
||||
},
|
||||
docExpansion: "none"
|
||||
docExpansion: "none",
|
||||
sorter : "alpha"
|
||||
});
|
||||
|
||||
$('#input_apiKey').change(function() {
|
||||
|
||||
Vendored
+1
-1
@@ -204,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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+231
-155
@@ -1,5 +1,5 @@
|
||||
// swagger.js
|
||||
// version 2.0.30
|
||||
// version 2.0.37
|
||||
|
||||
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] );
|
||||
}
|
||||
};
|
||||
|
||||
@@ -45,40 +45,39 @@ if (!('map' in Array.prototype)) {
|
||||
}
|
||||
|
||||
Object.keys = Object.keys || (function () {
|
||||
var hasOwnProperty = Object.prototype.hasOwnProperty,
|
||||
hasDontEnumBug = !{toString:null}.propertyIsEnumerable("toString"),
|
||||
DontEnums = [
|
||||
'toString',
|
||||
'toLocaleString',
|
||||
'valueOf',
|
||||
'hasOwnProperty',
|
||||
'isPrototypeOf',
|
||||
'propertyIsEnumerable',
|
||||
'constructor'
|
||||
],
|
||||
DontEnumsLength = DontEnums.length;
|
||||
|
||||
return function (o) {
|
||||
if (typeof o != "object" && typeof o != "function" || o === null)
|
||||
throw new TypeError("Object.keys called on a non-object");
|
||||
|
||||
var result = [];
|
||||
for (var name in o) {
|
||||
if (hasOwnProperty.call(o, name))
|
||||
result.push(name);
|
||||
}
|
||||
|
||||
if (hasDontEnumBug) {
|
||||
for (var i = 0; i < DontEnumsLength; i++) {
|
||||
if (hasOwnProperty.call(o, DontEnums[i]))
|
||||
result.push(DontEnums[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
var hasOwnProperty = Object.prototype.hasOwnProperty,
|
||||
hasDontEnumBug = !{toString:null}.propertyIsEnumerable("toString"),
|
||||
DontEnums = [
|
||||
'toString',
|
||||
'toLocaleString',
|
||||
'valueOf',
|
||||
'hasOwnProperty',
|
||||
'isPrototypeOf',
|
||||
'propertyIsEnumerable',
|
||||
'constructor'
|
||||
],
|
||||
DontEnumsLength = DontEnums.length;
|
||||
|
||||
return function (o) {
|
||||
if (typeof o != "object" && typeof o != "function" || o === null)
|
||||
throw new TypeError("Object.keys called on a non-object");
|
||||
|
||||
var result = [];
|
||||
for (var name in o) {
|
||||
if (hasOwnProperty.call(o, name))
|
||||
result.push(name);
|
||||
}
|
||||
|
||||
if (hasDontEnumBug) {
|
||||
for (var i = 0; i < DontEnumsLength; i++) {
|
||||
if (hasOwnProperty.call(o, DontEnums[i]))
|
||||
result.push(DontEnums[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
|
||||
var SwaggerApi = function(url, options) {
|
||||
this.url = null;
|
||||
@@ -87,6 +86,7 @@ var SwaggerApi = function(url, options) {
|
||||
this.authorizations = null;
|
||||
this.authorizationScheme = null;
|
||||
this.info = null;
|
||||
this.useJQuery = false;
|
||||
|
||||
options = (options||{});
|
||||
if (url)
|
||||
@@ -103,6 +103,9 @@ var SwaggerApi = function(url, options) {
|
||||
if (options.success != null)
|
||||
this.success = options.success;
|
||||
|
||||
if (typeof options.useJQuery === 'boolean')
|
||||
this.useJQuery = options.useJQuery;
|
||||
|
||||
this.failure = options.failure != null ? options.failure : function() {};
|
||||
this.progress = options.progress != null ? options.progress : function() {};
|
||||
if (options.success != null)
|
||||
@@ -154,6 +157,7 @@ SwaggerApi.prototype.buildFromSpec = function(response) {
|
||||
}
|
||||
this.apis = {};
|
||||
this.apisArray = [];
|
||||
this.consumes = response.consumes;
|
||||
this.produces = response.produces;
|
||||
this.authSchemes = response.authorizations;
|
||||
if (response.info != null) {
|
||||
@@ -171,13 +175,13 @@ SwaggerApi.prototype.buildFromSpec = function(response) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (response.basePath) {
|
||||
if (response.basePath)
|
||||
this.basePath = response.basePath;
|
||||
} else if (this.url.indexOf('?') > 0) {
|
||||
else if (this.url.indexOf('?') > 0)
|
||||
this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
|
||||
} else {
|
||||
else
|
||||
this.basePath = this.url;
|
||||
}
|
||||
|
||||
if (isApi) {
|
||||
var newName = response.resourcePath.replace(/\//g, '');
|
||||
this.resourcePath = response.resourcePath;
|
||||
@@ -317,8 +321,8 @@ var SwaggerResource = function(resourceObj, api) {
|
||||
var _this = this;
|
||||
this.api = api;
|
||||
this.api = this.api;
|
||||
produces = [];
|
||||
consumes = [];
|
||||
consumes = (this.consumes | []);
|
||||
produces = (this.produces | []);
|
||||
this.path = this.api.resourcePath != null ? this.api.resourcePath : resourceObj.path;
|
||||
this.description = resourceObj.description;
|
||||
|
||||
@@ -368,22 +372,28 @@ var SwaggerResource = function(resourceObj, api) {
|
||||
}
|
||||
}
|
||||
|
||||
SwaggerResource.prototype.getAbsoluteBasePath = function(relativeBasePath) {
|
||||
var parts, pos, url;
|
||||
SwaggerResource.prototype.getAbsoluteBasePath = function (relativeBasePath) {
|
||||
var pos, url;
|
||||
url = this.api.basePath;
|
||||
pos = url.lastIndexOf(relativeBasePath);
|
||||
if (pos === -1) {
|
||||
parts = url.split("/");
|
||||
url = parts[0] + "//" + parts[2];
|
||||
if (relativeBasePath.indexOf("/") === 0) {
|
||||
return url + relativeBasePath;
|
||||
} else {
|
||||
return url + "/" + relativeBasePath;
|
||||
}
|
||||
} else if (relativeBasePath === "/") {
|
||||
return url.substring(0, pos);
|
||||
} else {
|
||||
return url.substring(0, pos) + relativeBasePath;
|
||||
var parts = url.split("/");
|
||||
var rootUrl = parts[0] + "//" + parts[2];
|
||||
|
||||
if(relativeBasePath.indexOf("http") === 0)
|
||||
return relativeBasePath;
|
||||
if(relativeBasePath === "/")
|
||||
return rootUrl;
|
||||
if(relativeBasePath.substring(0, 1) == "/") {
|
||||
// use root + relative
|
||||
return rootUrl + 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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -478,8 +488,7 @@ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes,
|
||||
|
||||
SwaggerResource.prototype.sanitize = function(nickname) {
|
||||
var op;
|
||||
op = nickname.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|./?,\\'""-]/g, '_');
|
||||
//'
|
||||
op = nickname.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|.\/?,\\'""-]/g, '_');
|
||||
op = op.replace(/((_){2,})/g, '_');
|
||||
op = op.replace(/^(_)*/g, '');
|
||||
op = op.replace(/([_])*$/g, '');
|
||||
@@ -812,7 +821,7 @@ SwaggerOperation.prototype.getSampleJSON = function(type, models) {
|
||||
else
|
||||
return JSON.stringify(val, null, 2);
|
||||
}
|
||||
else
|
||||
else
|
||||
return val;
|
||||
}
|
||||
};
|
||||
@@ -904,6 +913,7 @@ SwaggerOperation.prototype.pathXml = function() {
|
||||
|
||||
SwaggerOperation.prototype.encodePathParam = function(pathParam) {
|
||||
var encParts, part, parts, _i, _len;
|
||||
pathParam = pathParam.toString();
|
||||
if (pathParam.indexOf("/") === -1) {
|
||||
return encodeURIComponent(pathParam);
|
||||
} else {
|
||||
@@ -1072,7 +1082,7 @@ SwaggerOperation.prototype.formatXml = function(xml) {
|
||||
var SwaggerRequest = function(type, url, params, opts, successCallback, errorCallback, operation, execution) {
|
||||
var _this = this;
|
||||
var errors = [];
|
||||
this.useJQuery = (typeof operation.useJQuery !== 'undefined' ? operation.useJQuery : null);
|
||||
this.useJQuery = (typeof operation.resource.useJQuery !== 'undefined' ? operation.resource.useJQuery : null);
|
||||
this.type = (type||errors.push("SwaggerRequest type is required (get/post/put/delete/patch/options)."));
|
||||
this.url = (url||errors.push("SwaggerRequest url is required."));
|
||||
this.params = params;
|
||||
@@ -1089,96 +1099,59 @@ 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")
|
||||
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) {
|
||||
var fields = {};
|
||||
var possibleParams = {};
|
||||
// encode the body for form submits
|
||||
if (headers["Content-Type"]) {
|
||||
var values = {};
|
||||
var key;
|
||||
for(key in formParams){
|
||||
var param = formParams[key];
|
||||
values[param.name] = param;
|
||||
var i;
|
||||
var operationParams = this.operation.parameters;
|
||||
for(i = 0; i < operationParams.length; i++) {
|
||||
var param = operationParams[i];
|
||||
if(param.paramType === "form")
|
||||
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);
|
||||
if(headers["Content-Type"].indexOf("application/x-www-form-urlencoded") === 0) {
|
||||
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;
|
||||
}
|
||||
else if (headers["Content-Type"].indexOf("multipart/form-data") === 0) {
|
||||
// encode the body for form submits
|
||||
var data = "";
|
||||
var boundary = "----SwaggerFormBoundary" + Date.now();
|
||||
var key;
|
||||
for(key in values) {
|
||||
value = this.params[key];
|
||||
if(typeof value !== 'undefined') {
|
||||
data += '--' + boundary + '\n';
|
||||
data += 'Content-Disposition: form-data; name="' + key + '"';
|
||||
data += '\n\n';
|
||||
data += value + "\n";
|
||||
}
|
||||
}
|
||||
data += "--" + boundary + "--\n";
|
||||
headers["Content-Type"] = "multipart/form-data; boundary=" + boundary;
|
||||
body = data;
|
||||
}
|
||||
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: {
|
||||
@@ -1215,6 +1188,77 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
|
||||
}
|
||||
};
|
||||
|
||||
SwaggerRequest.prototype.setHeaders = function(params, operation) {
|
||||
// default type
|
||||
var accepts = "application/json";
|
||||
var consumes = "application/json";
|
||||
|
||||
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)
|
||||
consumes = "multipart/form-data";
|
||||
else
|
||||
consumes = "application/x-www-form-urlencoded";
|
||||
}
|
||||
else if (this.type == "DELETE")
|
||||
body = "{}";
|
||||
else if (this.type != "DELETE")
|
||||
accepts = null;
|
||||
}
|
||||
|
||||
if (consumes && this.operation.consumes) {
|
||||
if (this.operation.consumes.indexOf(consumes) === -1) {
|
||||
log("server doesn't consume " + consumes + ", try " + JSON.stringify(this.operation.consumes));
|
||||
consumes = 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 ((consumes && body !== "") || (consumes === "application/x-www-form-urlencoded"))
|
||||
headers["Content-Type"] = consumes;
|
||||
if (accepts)
|
||||
headers["Accept"] = accepts;
|
||||
return headers;
|
||||
}
|
||||
|
||||
SwaggerRequest.prototype.asCurl = function() {
|
||||
var results = [];
|
||||
if(this.headers) {
|
||||
@@ -1258,9 +1302,16 @@ SwaggerHttp.prototype.isIE8 = function() {
|
||||
};
|
||||
|
||||
/*
|
||||
* JQueryHttpClient lets a browser take advantage of JQuery's cross-browser magic
|
||||
* JQueryHttpClient lets a browser take advantage of JQuery's cross-browser magic.
|
||||
* NOTE: when jQuery is available it will export both '$' and 'jQuery' to the global space.
|
||||
* Since we are using closures here we need to alias it for internal use.
|
||||
*/
|
||||
var JQueryHttpClient = function(options) {}
|
||||
var JQueryHttpClient = function(options) {
|
||||
"use strict";
|
||||
if(!jQuery){
|
||||
var jQuery = window.jQuery;
|
||||
}
|
||||
}
|
||||
|
||||
JQueryHttpClient.prototype.execute = function(obj) {
|
||||
var cb = obj.on;
|
||||
@@ -1289,14 +1340,25 @@ JQueryHttpClient.prototype.execute = function(obj) {
|
||||
|
||||
obj.data = obj.body;
|
||||
obj.complete = function(response, textStatus, opts) {
|
||||
headers = {};
|
||||
headerArray = response.getAllResponseHeaders().split(":");
|
||||
var headers = {},
|
||||
headerArray = response.getAllResponseHeaders().split("\n");
|
||||
|
||||
for(var i = 0; i < headerArray.length / 2; i++)
|
||||
headers[headerArray[i] = headerArray[i+1]];
|
||||
for(var i = 0; i < headerArray.length; i++) {
|
||||
var toSplit = headerArray[i].trim();
|
||||
if(toSplit.length === 0)
|
||||
continue;
|
||||
var separator = toSplit.indexOf(":");
|
||||
if(separator === -1) {
|
||||
// Name but no value in the header
|
||||
headers[toSplit] = null;
|
||||
continue;
|
||||
}
|
||||
var name = toSplit.substring(0, separator).trim(),
|
||||
value = toSplit.substring(separator + 1).trim();
|
||||
headers[name] = value;
|
||||
}
|
||||
|
||||
out = {
|
||||
headers: headers,
|
||||
var out = {
|
||||
url: request.url,
|
||||
method: request.method,
|
||||
status: response.status,
|
||||
@@ -1323,8 +1385,8 @@ JQueryHttpClient.prototype.execute = function(obj) {
|
||||
return cb.response(out);
|
||||
};
|
||||
|
||||
$.support.cors = true;
|
||||
return $.ajax(obj);
|
||||
jQuery.support.cors = true;
|
||||
return jQuery.ajax(obj);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1440,16 +1502,31 @@ SwaggerAuthorizations.prototype.remove = function(name) {
|
||||
};
|
||||
|
||||
SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
|
||||
status = null;
|
||||
var status = null;
|
||||
var key;
|
||||
for (key in this.authz) {
|
||||
value = this.authz[key];
|
||||
result = value.apply(obj, authorizations);
|
||||
if (result === false)
|
||||
status = false;
|
||||
if (result === true)
|
||||
status = true;
|
||||
|
||||
// if the "authorizations" key is undefined, or has an empty array, add all keys
|
||||
if(typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) {
|
||||
for (key in this.authz) {
|
||||
value = this.authz[key];
|
||||
result = value.apply(obj, authorizations);
|
||||
if (result === true)
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(name in authorizations) {
|
||||
for (key in this.authz) {
|
||||
if(key == name) {
|
||||
value = this.authz[key];
|
||||
result = value.apply(obj, authorizations);
|
||||
if (result === true)
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
};
|
||||
|
||||
@@ -1524,4 +1601,3 @@ e.SwaggerModel = SwaggerModel;
|
||||
e.SwaggerModelProperty = SwaggerModelProperty;
|
||||
e.SwaggerResource = SwaggerResource;
|
||||
e.SwaggerApi = SwaggerApi;
|
||||
|
||||
|
||||
Vendored
+74
-23
@@ -1,5 +1,5 @@
|
||||
// swagger-ui.js
|
||||
// version 2.0.16
|
||||
// version 2.0.22
|
||||
$(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;
|
||||
@@ -1457,7 +1495,8 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
model: resource,
|
||||
tagName: 'li',
|
||||
id: 'resource_' + resource.id,
|
||||
className: 'resource'
|
||||
className: 'resource',
|
||||
swaggerOptions: this.options.swaggerOptions
|
||||
});
|
||||
return $('#resources').append(resourceView.render().el);
|
||||
};
|
||||
@@ -1507,7 +1546,8 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
operationView = new OperationView({
|
||||
model: operation,
|
||||
tagName: 'li',
|
||||
className: 'endpoint'
|
||||
className: 'endpoint',
|
||||
swaggerOptions: this.options.swaggerOptions
|
||||
});
|
||||
$('.endpoints', $(this.el)).append(operationView.render().el);
|
||||
return this.number++;
|
||||
@@ -1541,8 +1581,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();
|
||||
@@ -1732,9 +1772,8 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
};
|
||||
|
||||
OperationView.prototype.handleFileUpload = function(map, form) {
|
||||
var bodyParam, el, headerParams, o, obj, param, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref5, _ref6, _ref7, _ref8,
|
||||
var bodyParam, el, headerParams, o, obj, param, params, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref5, _ref6, _ref7, _ref8,
|
||||
_this = this;
|
||||
log("it's a file upload");
|
||||
_ref5 = form.serializeArray();
|
||||
for (_i = 0, _len = _ref5.length; _i < _len; _i++) {
|
||||
o = _ref5[_i];
|
||||
@@ -1743,11 +1782,12 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
}
|
||||
}
|
||||
bodyParam = new FormData();
|
||||
params = 0;
|
||||
_ref6 = this.model.parameters;
|
||||
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]);
|
||||
}
|
||||
}
|
||||
@@ -1764,9 +1804,11 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
_ref8 = form.find('input[type~="file"]');
|
||||
for (_l = 0, _len3 = _ref8.length; _l < _len3; _l++) {
|
||||
el = _ref8[_l];
|
||||
bodyParam.append($(el).attr('name'), el.files[0]);
|
||||
if (typeof el.files[0] !== 'undefined') {
|
||||
bodyParam.append($(el).attr('name'), el.files[0]);
|
||||
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 = {
|
||||
@@ -1790,6 +1832,9 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
if (window.authorizations) {
|
||||
window.authorizations.apply(obj);
|
||||
}
|
||||
if (params === 0) {
|
||||
obj.data.append("fake", "true");
|
||||
}
|
||||
jQuery.ajax(obj);
|
||||
return false;
|
||||
};
|
||||
@@ -1932,7 +1977,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
};
|
||||
|
||||
OperationView.prototype.showStatus = function(response) {
|
||||
var code, content, contentType, headers, pre, response_body, url;
|
||||
var code, content, contentType, headers, opts, pre, response_body, response_body_el, url;
|
||||
if (response.content === void 0) {
|
||||
content = response.data;
|
||||
url = response.url;
|
||||
@@ -1964,11 +2009,17 @@ 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();
|
||||
return hljs.highlightBlock($('.response_body', $(this.el))[0]);
|
||||
response_body_el = $('.response_body', $(this.el))[0];
|
||||
opts = this.options.swaggerOptions;
|
||||
if (opts.highlightSizeThreshold && response.data.length > opts.highlightSizeThreshold) {
|
||||
return response_body_el;
|
||||
} else {
|
||||
return hljs.highlightBlock(response_body_el);
|
||||
}
|
||||
};
|
||||
|
||||
OperationView.prototype.toggleOperationContent = function() {
|
||||
@@ -2133,7 +2184,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
var template;
|
||||
template = this.template();
|
||||
$(this.el).html(template(this.model));
|
||||
this.switchToDescription();
|
||||
this.switchToSnippet();
|
||||
this.isParam = this.model.isParam;
|
||||
if (this.isParam) {
|
||||
$('.notice', $(this.el)).text('Click to set as parameter value');
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
@@ -204,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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+231
-155
@@ -1,5 +1,5 @@
|
||||
// swagger.js
|
||||
// version 2.0.30
|
||||
// version 2.0.37
|
||||
|
||||
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] );
|
||||
}
|
||||
};
|
||||
|
||||
@@ -45,40 +45,39 @@ if (!('map' in Array.prototype)) {
|
||||
}
|
||||
|
||||
Object.keys = Object.keys || (function () {
|
||||
var hasOwnProperty = Object.prototype.hasOwnProperty,
|
||||
hasDontEnumBug = !{toString:null}.propertyIsEnumerable("toString"),
|
||||
DontEnums = [
|
||||
'toString',
|
||||
'toLocaleString',
|
||||
'valueOf',
|
||||
'hasOwnProperty',
|
||||
'isPrototypeOf',
|
||||
'propertyIsEnumerable',
|
||||
'constructor'
|
||||
],
|
||||
DontEnumsLength = DontEnums.length;
|
||||
|
||||
return function (o) {
|
||||
if (typeof o != "object" && typeof o != "function" || o === null)
|
||||
throw new TypeError("Object.keys called on a non-object");
|
||||
|
||||
var result = [];
|
||||
for (var name in o) {
|
||||
if (hasOwnProperty.call(o, name))
|
||||
result.push(name);
|
||||
}
|
||||
|
||||
if (hasDontEnumBug) {
|
||||
for (var i = 0; i < DontEnumsLength; i++) {
|
||||
if (hasOwnProperty.call(o, DontEnums[i]))
|
||||
result.push(DontEnums[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
var hasOwnProperty = Object.prototype.hasOwnProperty,
|
||||
hasDontEnumBug = !{toString:null}.propertyIsEnumerable("toString"),
|
||||
DontEnums = [
|
||||
'toString',
|
||||
'toLocaleString',
|
||||
'valueOf',
|
||||
'hasOwnProperty',
|
||||
'isPrototypeOf',
|
||||
'propertyIsEnumerable',
|
||||
'constructor'
|
||||
],
|
||||
DontEnumsLength = DontEnums.length;
|
||||
|
||||
return function (o) {
|
||||
if (typeof o != "object" && typeof o != "function" || o === null)
|
||||
throw new TypeError("Object.keys called on a non-object");
|
||||
|
||||
var result = [];
|
||||
for (var name in o) {
|
||||
if (hasOwnProperty.call(o, name))
|
||||
result.push(name);
|
||||
}
|
||||
|
||||
if (hasDontEnumBug) {
|
||||
for (var i = 0; i < DontEnumsLength; i++) {
|
||||
if (hasOwnProperty.call(o, DontEnums[i]))
|
||||
result.push(DontEnums[i]);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
|
||||
var SwaggerApi = function(url, options) {
|
||||
this.url = null;
|
||||
@@ -87,6 +86,7 @@ var SwaggerApi = function(url, options) {
|
||||
this.authorizations = null;
|
||||
this.authorizationScheme = null;
|
||||
this.info = null;
|
||||
this.useJQuery = false;
|
||||
|
||||
options = (options||{});
|
||||
if (url)
|
||||
@@ -103,6 +103,9 @@ var SwaggerApi = function(url, options) {
|
||||
if (options.success != null)
|
||||
this.success = options.success;
|
||||
|
||||
if (typeof options.useJQuery === 'boolean')
|
||||
this.useJQuery = options.useJQuery;
|
||||
|
||||
this.failure = options.failure != null ? options.failure : function() {};
|
||||
this.progress = options.progress != null ? options.progress : function() {};
|
||||
if (options.success != null)
|
||||
@@ -154,6 +157,7 @@ SwaggerApi.prototype.buildFromSpec = function(response) {
|
||||
}
|
||||
this.apis = {};
|
||||
this.apisArray = [];
|
||||
this.consumes = response.consumes;
|
||||
this.produces = response.produces;
|
||||
this.authSchemes = response.authorizations;
|
||||
if (response.info != null) {
|
||||
@@ -171,13 +175,13 @@ SwaggerApi.prototype.buildFromSpec = function(response) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (response.basePath) {
|
||||
if (response.basePath)
|
||||
this.basePath = response.basePath;
|
||||
} else if (this.url.indexOf('?') > 0) {
|
||||
else if (this.url.indexOf('?') > 0)
|
||||
this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
|
||||
} else {
|
||||
else
|
||||
this.basePath = this.url;
|
||||
}
|
||||
|
||||
if (isApi) {
|
||||
var newName = response.resourcePath.replace(/\//g, '');
|
||||
this.resourcePath = response.resourcePath;
|
||||
@@ -317,8 +321,8 @@ var SwaggerResource = function(resourceObj, api) {
|
||||
var _this = this;
|
||||
this.api = api;
|
||||
this.api = this.api;
|
||||
produces = [];
|
||||
consumes = [];
|
||||
consumes = (this.consumes | []);
|
||||
produces = (this.produces | []);
|
||||
this.path = this.api.resourcePath != null ? this.api.resourcePath : resourceObj.path;
|
||||
this.description = resourceObj.description;
|
||||
|
||||
@@ -368,22 +372,28 @@ var SwaggerResource = function(resourceObj, api) {
|
||||
}
|
||||
}
|
||||
|
||||
SwaggerResource.prototype.getAbsoluteBasePath = function(relativeBasePath) {
|
||||
var parts, pos, url;
|
||||
SwaggerResource.prototype.getAbsoluteBasePath = function (relativeBasePath) {
|
||||
var pos, url;
|
||||
url = this.api.basePath;
|
||||
pos = url.lastIndexOf(relativeBasePath);
|
||||
if (pos === -1) {
|
||||
parts = url.split("/");
|
||||
url = parts[0] + "//" + parts[2];
|
||||
if (relativeBasePath.indexOf("/") === 0) {
|
||||
return url + relativeBasePath;
|
||||
} else {
|
||||
return url + "/" + relativeBasePath;
|
||||
}
|
||||
} else if (relativeBasePath === "/") {
|
||||
return url.substring(0, pos);
|
||||
} else {
|
||||
return url.substring(0, pos) + relativeBasePath;
|
||||
var parts = url.split("/");
|
||||
var rootUrl = parts[0] + "//" + parts[2];
|
||||
|
||||
if(relativeBasePath.indexOf("http") === 0)
|
||||
return relativeBasePath;
|
||||
if(relativeBasePath === "/")
|
||||
return rootUrl;
|
||||
if(relativeBasePath.substring(0, 1) == "/") {
|
||||
// use root + relative
|
||||
return rootUrl + 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;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -478,8 +488,7 @@ SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes,
|
||||
|
||||
SwaggerResource.prototype.sanitize = function(nickname) {
|
||||
var op;
|
||||
op = nickname.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|./?,\\'""-]/g, '_');
|
||||
//'
|
||||
op = nickname.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|.\/?,\\'""-]/g, '_');
|
||||
op = op.replace(/((_){2,})/g, '_');
|
||||
op = op.replace(/^(_)*/g, '');
|
||||
op = op.replace(/([_])*$/g, '');
|
||||
@@ -812,7 +821,7 @@ SwaggerOperation.prototype.getSampleJSON = function(type, models) {
|
||||
else
|
||||
return JSON.stringify(val, null, 2);
|
||||
}
|
||||
else
|
||||
else
|
||||
return val;
|
||||
}
|
||||
};
|
||||
@@ -904,6 +913,7 @@ SwaggerOperation.prototype.pathXml = function() {
|
||||
|
||||
SwaggerOperation.prototype.encodePathParam = function(pathParam) {
|
||||
var encParts, part, parts, _i, _len;
|
||||
pathParam = pathParam.toString();
|
||||
if (pathParam.indexOf("/") === -1) {
|
||||
return encodeURIComponent(pathParam);
|
||||
} else {
|
||||
@@ -1072,7 +1082,7 @@ SwaggerOperation.prototype.formatXml = function(xml) {
|
||||
var SwaggerRequest = function(type, url, params, opts, successCallback, errorCallback, operation, execution) {
|
||||
var _this = this;
|
||||
var errors = [];
|
||||
this.useJQuery = (typeof operation.useJQuery !== 'undefined' ? operation.useJQuery : null);
|
||||
this.useJQuery = (typeof operation.resource.useJQuery !== 'undefined' ? operation.resource.useJQuery : null);
|
||||
this.type = (type||errors.push("SwaggerRequest type is required (get/post/put/delete/patch/options)."));
|
||||
this.url = (url||errors.push("SwaggerRequest url is required."));
|
||||
this.params = params;
|
||||
@@ -1089,96 +1099,59 @@ 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")
|
||||
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) {
|
||||
var fields = {};
|
||||
var possibleParams = {};
|
||||
// encode the body for form submits
|
||||
if (headers["Content-Type"]) {
|
||||
var values = {};
|
||||
var key;
|
||||
for(key in formParams){
|
||||
var param = formParams[key];
|
||||
values[param.name] = param;
|
||||
var i;
|
||||
var operationParams = this.operation.parameters;
|
||||
for(i = 0; i < operationParams.length; i++) {
|
||||
var param = operationParams[i];
|
||||
if(param.paramType === "form")
|
||||
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);
|
||||
if(headers["Content-Type"].indexOf("application/x-www-form-urlencoded") === 0) {
|
||||
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;
|
||||
}
|
||||
else if (headers["Content-Type"].indexOf("multipart/form-data") === 0) {
|
||||
// encode the body for form submits
|
||||
var data = "";
|
||||
var boundary = "----SwaggerFormBoundary" + Date.now();
|
||||
var key;
|
||||
for(key in values) {
|
||||
value = this.params[key];
|
||||
if(typeof value !== 'undefined') {
|
||||
data += '--' + boundary + '\n';
|
||||
data += 'Content-Disposition: form-data; name="' + key + '"';
|
||||
data += '\n\n';
|
||||
data += value + "\n";
|
||||
}
|
||||
}
|
||||
data += "--" + boundary + "--\n";
|
||||
headers["Content-Type"] = "multipart/form-data; boundary=" + boundary;
|
||||
body = data;
|
||||
}
|
||||
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: {
|
||||
@@ -1215,6 +1188,77 @@ var SwaggerRequest = function(type, url, params, opts, successCallback, errorCal
|
||||
}
|
||||
};
|
||||
|
||||
SwaggerRequest.prototype.setHeaders = function(params, operation) {
|
||||
// default type
|
||||
var accepts = "application/json";
|
||||
var consumes = "application/json";
|
||||
|
||||
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)
|
||||
consumes = "multipart/form-data";
|
||||
else
|
||||
consumes = "application/x-www-form-urlencoded";
|
||||
}
|
||||
else if (this.type == "DELETE")
|
||||
body = "{}";
|
||||
else if (this.type != "DELETE")
|
||||
accepts = null;
|
||||
}
|
||||
|
||||
if (consumes && this.operation.consumes) {
|
||||
if (this.operation.consumes.indexOf(consumes) === -1) {
|
||||
log("server doesn't consume " + consumes + ", try " + JSON.stringify(this.operation.consumes));
|
||||
consumes = 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 ((consumes && body !== "") || (consumes === "application/x-www-form-urlencoded"))
|
||||
headers["Content-Type"] = consumes;
|
||||
if (accepts)
|
||||
headers["Accept"] = accepts;
|
||||
return headers;
|
||||
}
|
||||
|
||||
SwaggerRequest.prototype.asCurl = function() {
|
||||
var results = [];
|
||||
if(this.headers) {
|
||||
@@ -1258,9 +1302,16 @@ SwaggerHttp.prototype.isIE8 = function() {
|
||||
};
|
||||
|
||||
/*
|
||||
* JQueryHttpClient lets a browser take advantage of JQuery's cross-browser magic
|
||||
* JQueryHttpClient lets a browser take advantage of JQuery's cross-browser magic.
|
||||
* NOTE: when jQuery is available it will export both '$' and 'jQuery' to the global space.
|
||||
* Since we are using closures here we need to alias it for internal use.
|
||||
*/
|
||||
var JQueryHttpClient = function(options) {}
|
||||
var JQueryHttpClient = function(options) {
|
||||
"use strict";
|
||||
if(!jQuery){
|
||||
var jQuery = window.jQuery;
|
||||
}
|
||||
}
|
||||
|
||||
JQueryHttpClient.prototype.execute = function(obj) {
|
||||
var cb = obj.on;
|
||||
@@ -1289,14 +1340,25 @@ JQueryHttpClient.prototype.execute = function(obj) {
|
||||
|
||||
obj.data = obj.body;
|
||||
obj.complete = function(response, textStatus, opts) {
|
||||
headers = {};
|
||||
headerArray = response.getAllResponseHeaders().split(":");
|
||||
var headers = {},
|
||||
headerArray = response.getAllResponseHeaders().split("\n");
|
||||
|
||||
for(var i = 0; i < headerArray.length / 2; i++)
|
||||
headers[headerArray[i] = headerArray[i+1]];
|
||||
for(var i = 0; i < headerArray.length; i++) {
|
||||
var toSplit = headerArray[i].trim();
|
||||
if(toSplit.length === 0)
|
||||
continue;
|
||||
var separator = toSplit.indexOf(":");
|
||||
if(separator === -1) {
|
||||
// Name but no value in the header
|
||||
headers[toSplit] = null;
|
||||
continue;
|
||||
}
|
||||
var name = toSplit.substring(0, separator).trim(),
|
||||
value = toSplit.substring(separator + 1).trim();
|
||||
headers[name] = value;
|
||||
}
|
||||
|
||||
out = {
|
||||
headers: headers,
|
||||
var out = {
|
||||
url: request.url,
|
||||
method: request.method,
|
||||
status: response.status,
|
||||
@@ -1323,8 +1385,8 @@ JQueryHttpClient.prototype.execute = function(obj) {
|
||||
return cb.response(out);
|
||||
};
|
||||
|
||||
$.support.cors = true;
|
||||
return $.ajax(obj);
|
||||
jQuery.support.cors = true;
|
||||
return jQuery.ajax(obj);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1440,16 +1502,31 @@ SwaggerAuthorizations.prototype.remove = function(name) {
|
||||
};
|
||||
|
||||
SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
|
||||
status = null;
|
||||
var status = null;
|
||||
var key;
|
||||
for (key in this.authz) {
|
||||
value = this.authz[key];
|
||||
result = value.apply(obj, authorizations);
|
||||
if (result === false)
|
||||
status = false;
|
||||
if (result === true)
|
||||
status = true;
|
||||
|
||||
// if the "authorizations" key is undefined, or has an empty array, add all keys
|
||||
if(typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) {
|
||||
for (key in this.authz) {
|
||||
value = this.authz[key];
|
||||
result = value.apply(obj, authorizations);
|
||||
if (result === true)
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(name in authorizations) {
|
||||
for (key in this.authz) {
|
||||
if(key == name) {
|
||||
value = this.authz[key];
|
||||
result = value.apply(obj, authorizations);
|
||||
if (result === true)
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return status;
|
||||
};
|
||||
|
||||
@@ -1524,4 +1601,3 @@ e.SwaggerModel = SwaggerModel;
|
||||
e.SwaggerModelProperty = SwaggerModelProperty;
|
||||
e.SwaggerResource = SwaggerResource;
|
||||
e.SwaggerApi = SwaggerApi;
|
||||
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "swagger-ui",
|
||||
"version": "2.0.16",
|
||||
"version": "2.0.22",
|
||||
"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.36",
|
||||
"handlebars": "~1.0.10",
|
||||
"less": "~1.4.2"
|
||||
}
|
||||
|
||||
@@ -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('')
|
||||
|
||||
@@ -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))
|
||||
@@ -21,8 +33,8 @@ class MainView extends Backbone.View
|
||||
|
||||
addResource: (resource) ->
|
||||
# Render a resource and add it to resources li
|
||||
resourceView = new ResourceView({model: resource, tagName: 'li', id: 'resource_' + resource.id, className: 'resource'})
|
||||
resourceView = new ResourceView({model: resource, tagName: 'li', id: 'resource_' + resource.id, className: 'resource', swaggerOptions: @options.swaggerOptions})
|
||||
$('#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()
|
||||
@@ -151,18 +151,18 @@ class OperationView extends Backbone.View
|
||||
parent.showCompleteStatus response
|
||||
|
||||
handleFileUpload: (map, form) ->
|
||||
log "it's a file upload"
|
||||
for o in form.serializeArray()
|
||||
if(o.value? && jQuery.trim(o.value).length > 0)
|
||||
map[o.name] = o.value
|
||||
|
||||
# requires HTML5 compatible browser
|
||||
bodyParam = new FormData()
|
||||
params = 0
|
||||
|
||||
# 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
|
||||
@@ -175,9 +175,9 @@ class OperationView extends Backbone.View
|
||||
|
||||
# add files
|
||||
for el in form.find('input[type~="file"]')
|
||||
bodyParam.append($(el).attr('name'), el.files[0])
|
||||
|
||||
log(bodyParam)
|
||||
if typeof el.files[0] isnt 'undefined'
|
||||
bodyParam.append($(el).attr('name'), el.files[0])
|
||||
params += 1
|
||||
|
||||
@invocationUrl =
|
||||
if @model.supportHeaderParams()
|
||||
@@ -207,6 +207,9 @@ class OperationView extends Backbone.View
|
||||
if window.authorizations
|
||||
window.authorizations.apply obj
|
||||
|
||||
if params is 0
|
||||
obj.data.append("fake", "true");
|
||||
|
||||
jQuery.ajax(obj)
|
||||
false
|
||||
# end of file-upload nastiness
|
||||
@@ -356,11 +359,14 @@ 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()
|
||||
hljs.highlightBlock($('.response_body', $(@el))[0])
|
||||
response_body_el = $('.response_body', $(@el))[0]
|
||||
# only highlight the response if response is less than threshold, default state is highlight response
|
||||
opts = @options.swaggerOptions
|
||||
if opts.highlightSizeThreshold && response.data.length > opts.highlightSizeThreshold then response_body_el else hljs.highlightBlock(response_body_el)
|
||||
|
||||
toggleOperationContent: ->
|
||||
elem = $('#' + Docs.escapeResourceName(@model.parentId) + "_" + @model.nickname + "_content")
|
||||
|
||||
@@ -27,7 +27,7 @@ class ResourceView extends Backbone.View
|
||||
operation.number = @number
|
||||
|
||||
# Render an operation and add it to operations li
|
||||
operationView = new OperationView({model: operation, tagName: 'li', className: 'endpoint'})
|
||||
operationView = new OperationView({model: operation, tagName: 'li', className: 'endpoint', swaggerOptions: @options.swaggerOptions})
|
||||
$('.endpoints', $(@el)).append operationView.render().el
|
||||
|
||||
@number++
|
||||
@@ -11,7 +11,7 @@ class SignatureView extends Backbone.View
|
||||
template = @template()
|
||||
$(@el).html(template(@model))
|
||||
|
||||
@switchToDescription()
|
||||
@switchToSnippet()
|
||||
|
||||
@isParam = @model.isParam
|
||||
|
||||
|
||||
@@ -2,9 +2,11 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Swagger UI</title>
|
||||
<link href='https://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
|
||||
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
|
||||
<link href='css/reset.css' media='screen' rel='stylesheet' type='text/css'/>
|
||||
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
|
||||
<link href='css/reset.css' media='print' rel='stylesheet' type='text/css'/>
|
||||
<link href='css/screen.css' media='print' rel='stylesheet' type='text/css'/>
|
||||
<script type="text/javascript" src="lib/shred.bundle.js"></script>
|
||||
<script src='lib/jquery-1.8.0.min.js' type='text/javascript'></script>
|
||||
<script src='lib/jquery.slideto.min.js' type='text/javascript'></script>
|
||||
@@ -45,7 +47,8 @@
|
||||
onFailure: function(data) {
|
||||
log("Unable to Load SwaggerUI");
|
||||
},
|
||||
docExpansion: "none"
|
||||
docExpansion: "none",
|
||||
sorter : "alpha"
|
||||
});
|
||||
|
||||
$('#input_apiKey').change(function() {
|
||||
|
||||
@@ -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] );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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}}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user