Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b336076a19 | ||
|
|
b8943665a2 | ||
|
|
0c0ffc569f | ||
|
|
18ce470f12 | ||
|
|
53593b796e | ||
|
|
2378b176f5 | ||
|
|
7dd5142df2 | ||
|
|
6b400b22fe | ||
|
|
c22d94b940 | ||
|
|
e7b9525911 | ||
|
|
ede80844a5 | ||
|
|
eea0d72a85 | ||
|
|
15acb15af6 | ||
|
|
54d0a8ec09 | ||
|
|
105c516f5f | ||
|
|
542d4fe478 | ||
|
|
97e96ba3d9 | ||
|
|
73eaf9f564 | ||
|
|
fc0ccd4486 | ||
|
|
7f68c35742 | ||
|
|
dc1bc43a19 | ||
|
|
c32f6e836d | ||
|
|
34bd474bff | ||
|
|
4601f62702 | ||
|
|
2bddfb688a | ||
|
|
b7458010f1 | ||
|
|
49f480440b | ||
|
|
e4d01c57bf | ||
|
|
187517dfe3 | ||
|
|
846628f1f3 | ||
|
|
355380a5c4 | ||
|
|
6db63006a6 | ||
|
|
0505d6cadf | ||
|
|
fcb82bdac4 |
@@ -1,6 +1,7 @@
|
||||
fs = require 'fs'
|
||||
path = require 'path'
|
||||
{exec} = require 'child_process'
|
||||
less = require 'less'
|
||||
|
||||
sourceFiles = [
|
||||
'SwaggerUi'
|
||||
@@ -71,13 +72,25 @@ task 'dist', 'Build a distribution', ->
|
||||
console.log ' : Minifying all...'
|
||||
exec 'java -jar "./bin/yuicompressor-2.4.7.jar" --type js -o ' + 'dist/swagger-ui.min.js ' + 'dist/swagger-ui.js', (err, stdout, stderr) ->
|
||||
throw err if err
|
||||
pack()
|
||||
lessc()
|
||||
|
||||
lessc = ->
|
||||
# Someone who knows CoffeeScript should make this more Coffee-licious
|
||||
console.log ' : Compiling LESS...'
|
||||
|
||||
less.render fs.readFileSync("src/main/less/screen.less", 'utf8'), (err, css) ->
|
||||
console.log err
|
||||
fs.writeFileSync("src/main/html/css/screen.css", css)
|
||||
pack()
|
||||
|
||||
pack = ->
|
||||
console.log ' : Packaging...'
|
||||
exec 'cp -r lib dist'
|
||||
console.log ' : Copied swagger-ui libs'
|
||||
exec 'cp -r node_modules/swagger-client/lib/swagger.js dist/lib'
|
||||
console.log ' : Copied swagger dependencies'
|
||||
exec 'cp -r src/main/html/* dist'
|
||||
console.log ' : Copied html dependencies'
|
||||
console.log ' !'
|
||||
|
||||
task 'spec', "Run the test suite", ->
|
||||
@@ -107,6 +120,7 @@ task 'watch', 'Watch source files for changes and autocompile', ->
|
||||
watchFiles("src/main/template")
|
||||
watchFiles("src/main/javascript")
|
||||
watchFiles("src/main/html")
|
||||
watchFiles("src/main/less")
|
||||
watchFiles("src/test")
|
||||
|
||||
notify = (message) ->
|
||||
@@ -115,4 +129,4 @@ notify = (message) ->
|
||||
# options =
|
||||
# title: 'CoffeeScript'
|
||||
# image: 'bin/CoffeeScript.png'
|
||||
# try require('growl') message, options
|
||||
# try require('growl') message, options
|
||||
|
||||
@@ -92,6 +92,8 @@ Create your own fork of [wordnik/swagger-ui](https://github.com/wordnik/swagger-
|
||||
|
||||
To share your changes, [submit a pull request](https://github.com/wordnik/swagger-ui/pull/new/master).
|
||||
|
||||
Since the javascript files are compiled from coffeescript, please submit changes in the *.coffee files! We have to reject changes only in the .js files as they will be lost on each build of the ui.
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
|
||||
Vendored
+1043
-1755
File diff suppressed because it is too large
Load Diff
Vendored
+6
-11
@@ -2,10 +2,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Swagger UI</title>
|
||||
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
|
||||
<link href='https://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
|
||||
<link href='css/highlight.default.css' media='screen' rel='stylesheet' type='text/css'/>
|
||||
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
|
||||
<script type="text/javascript" src="lib/shred.bundle.js" /></script>
|
||||
<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>
|
||||
<script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
|
||||
@@ -23,25 +23,20 @@
|
||||
dom_id: "swagger-ui-container",
|
||||
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
|
||||
onComplete: function(swaggerApi, swaggerUi){
|
||||
if(console) {
|
||||
console.log("Loaded SwaggerUI")
|
||||
}
|
||||
log("Loaded SwaggerUI")
|
||||
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
|
||||
},
|
||||
onFailure: function(data) {
|
||||
if(console) {
|
||||
console.log("Unable to Load SwaggerUI");
|
||||
console.log(data);
|
||||
}
|
||||
log("Unable to Load SwaggerUI");
|
||||
},
|
||||
docExpansion: "none"
|
||||
});
|
||||
|
||||
$('#input_apiKey').change(function() {
|
||||
var key = $('#input_apiKey')[0].value;
|
||||
console.log("key: " + key);
|
||||
log("key: " + key);
|
||||
if(key && key.trim() != "") {
|
||||
console.log("added key " + key);
|
||||
log("added key " + key);
|
||||
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "query"));
|
||||
}
|
||||
})
|
||||
|
||||
Vendored
+296
-55
@@ -1,7 +1,14 @@
|
||||
// Generated by CoffeeScript 1.6.3
|
||||
(function() {
|
||||
var ApiKeyAuthorization, PasswordAuthorization, SwaggerApi, SwaggerAuthorizations, SwaggerHttp, SwaggerModel, SwaggerModelProperty, SwaggerOperation, SwaggerRequest, SwaggerResource,
|
||||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
||||
var ApiKeyAuthorization, PasswordAuthorization, SwaggerApi, SwaggerAuthorizations, SwaggerHttp, SwaggerModel, SwaggerModelProperty, SwaggerOperation, SwaggerRequest, SwaggerResource, log,
|
||||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
|
||||
__indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
|
||||
|
||||
log = function() {
|
||||
if (window.console) {
|
||||
return console.log.apply(console, arguments);
|
||||
}
|
||||
};
|
||||
|
||||
SwaggerApi = (function() {
|
||||
SwaggerApi.prototype.url = "http://api.wordnik.com/v4/resources.json";
|
||||
@@ -16,6 +23,8 @@
|
||||
|
||||
SwaggerApi.prototype.info = null;
|
||||
|
||||
SwaggerApi.prototype.useJQuery = null;
|
||||
|
||||
function SwaggerApi(url, options) {
|
||||
if (options == null) {
|
||||
options = {};
|
||||
@@ -47,9 +56,12 @@
|
||||
_this = this;
|
||||
this.progress('fetching resource list: ' + this.url);
|
||||
obj = {
|
||||
useJQuery: this.useJQuery,
|
||||
url: this.url,
|
||||
method: "get",
|
||||
headers: {},
|
||||
headers: {
|
||||
accept: "application/json"
|
||||
},
|
||||
on: {
|
||||
error: function(response) {
|
||||
if (_this.url.substring(0, 4) !== 'http') {
|
||||
@@ -62,14 +74,14 @@
|
||||
return _this.fail(response.status + ' : ' + response.statusText + ' ' + _this.url);
|
||||
}
|
||||
},
|
||||
response: function(rawResponse) {
|
||||
var response;
|
||||
response = JSON.parse(rawResponse.content.data);
|
||||
_this.swaggerVersion = response.swaggerVersion;
|
||||
response: function(response) {
|
||||
var responseObj;
|
||||
responseObj = JSON.parse(response.data);
|
||||
_this.swaggerVersion = responseObj.swaggerVersion;
|
||||
if (_this.swaggerVersion === "1.2") {
|
||||
return _this.buildFromSpec(response);
|
||||
return _this.buildFromSpec(responseObj);
|
||||
} else {
|
||||
return _this.buildFrom1_1Spec(response);
|
||||
return _this.buildFrom1_1Spec(responseObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -139,7 +151,7 @@
|
||||
|
||||
SwaggerApi.prototype.buildFrom1_1Spec = function(response) {
|
||||
var api, isApi, newName, operation, res, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
|
||||
console.log("This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info");
|
||||
log("This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info");
|
||||
if (response.apiVersion != null) {
|
||||
this.apiVersion = response.apiVersion;
|
||||
}
|
||||
@@ -241,15 +253,15 @@
|
||||
_ref = this.apis;
|
||||
for (resource_name in _ref) {
|
||||
resource = _ref[resource_name];
|
||||
console.log(resource_name);
|
||||
log(resource_name);
|
||||
_ref1 = resource.operations;
|
||||
for (operation_name in _ref1) {
|
||||
operation = _ref1[operation_name];
|
||||
console.log(" " + operation.nickname);
|
||||
log(" " + operation.nickname);
|
||||
_ref2 = operation.parameters;
|
||||
for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
|
||||
parameter = _ref2[_i];
|
||||
console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
|
||||
log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -283,6 +295,7 @@
|
||||
this.operationsArray = [];
|
||||
this.modelsArray = [];
|
||||
this.models = {};
|
||||
this.rawModels = {};
|
||||
if ((resourceObj.apis != null) && (this.api.resourcePath != null)) {
|
||||
this.addApiDeclaration(resourceObj);
|
||||
} else {
|
||||
@@ -298,15 +311,18 @@
|
||||
obj = {
|
||||
url: this.url,
|
||||
method: "get",
|
||||
headers: {},
|
||||
useJQuery: this.useJQuery,
|
||||
headers: {
|
||||
accept: "application/json"
|
||||
},
|
||||
on: {
|
||||
error: function(response) {
|
||||
return _this.api.fail("Unable to read api '" + _this.name + "' from path " + _this.url + " (server returned " + response.statusText + ")");
|
||||
},
|
||||
response: function(rawResponse) {
|
||||
var response;
|
||||
response = JSON.parse(rawResponse.content.data);
|
||||
return _this.addApiDeclaration(response);
|
||||
response: function(response) {
|
||||
var responseObj;
|
||||
responseObj = JSON.parse(response.data);
|
||||
return _this.addApiDeclaration(responseObj);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -321,6 +337,25 @@
|
||||
}
|
||||
}
|
||||
|
||||
SwaggerResource.prototype.getAbsoluteBasePath = function(relativeBasePath) {
|
||||
var parts, 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;
|
||||
}
|
||||
};
|
||||
|
||||
SwaggerResource.prototype.addApiDeclaration = function(response) {
|
||||
var endpoint, _i, _len, _ref;
|
||||
if (response.produces != null) {
|
||||
@@ -330,7 +365,7 @@
|
||||
this.consumes = response.consumes;
|
||||
}
|
||||
if ((response.basePath != null) && response.basePath.replace(/\s/g, '').length > 0) {
|
||||
this.basePath = response.basePath;
|
||||
this.basePath = response.basePath.indexOf("http") === -1 ? this.getAbsoluteBasePath(response.basePath) : response.basePath;
|
||||
}
|
||||
this.addModels(response.models);
|
||||
if (response.apis) {
|
||||
@@ -353,6 +388,7 @@
|
||||
swaggerModel = new SwaggerModel(modelName, models[modelName]);
|
||||
this.modelsArray.push(swaggerModel);
|
||||
this.models[modelName] = swaggerModel;
|
||||
this.rawModels[modelName] = models[modelName];
|
||||
}
|
||||
}
|
||||
_ref = this.modelsArray;
|
||||
@@ -366,7 +402,7 @@
|
||||
};
|
||||
|
||||
SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes, produces) {
|
||||
var method, o, op, ref, responseMessages, type, _i, _len, _results;
|
||||
var method, o, op, r, ref, responseMessages, type, _i, _j, _len, _len1, _results;
|
||||
if (ops) {
|
||||
_results = [];
|
||||
for (_i = 0, _len = ops.length; _i < _len; _i++) {
|
||||
@@ -401,9 +437,14 @@
|
||||
}
|
||||
if (o.errorResponses) {
|
||||
responseMessages = o.errorResponses;
|
||||
for (_j = 0, _len1 = responseMessages.length; _j < _len1; _j++) {
|
||||
r = responseMessages[_j];
|
||||
r.message = r.reason;
|
||||
r.reason = null;
|
||||
}
|
||||
}
|
||||
o.nickname = this.sanitize(o.nickname);
|
||||
op = new SwaggerOperation(o.nickname, resource_path, method, o.parameters, o.summary, o.notes, type, responseMessages, this, consumes, produces);
|
||||
op = new SwaggerOperation(o.nickname, resource_path, method, o.parameters, o.summary, o.notes, type, responseMessages, this, consumes, produces, o.authorizations);
|
||||
this.operations[op.nickname] = op;
|
||||
_results.push(this.operationsArray.push(op));
|
||||
}
|
||||
@@ -498,7 +539,7 @@
|
||||
_ref1 = this.properties;
|
||||
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
|
||||
prop = _ref1[_j];
|
||||
if ((prop.refModel != null) && (modelsToIgnore.indexOf(prop.refModel)) === -1) {
|
||||
if ((prop.refModel != null) && modelsToIgnore.indexOf(prop.refModel) === -1) {
|
||||
returnVal = returnVal + ('<br>' + prop.refModel.getMockSignature(modelsToIgnore));
|
||||
}
|
||||
}
|
||||
@@ -557,13 +598,13 @@
|
||||
|
||||
SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
|
||||
var result;
|
||||
if ((this.refModel != null) && (modelsToIgnore.indexOf(this.refModel.name) === -1)) {
|
||||
if ((this.refModel != null) && (modelsToIgnore[this.refModel.name] === 'undefined')) {
|
||||
result = this.refModel.createJSONSample(modelsToIgnore);
|
||||
} else {
|
||||
if (this.isCollection) {
|
||||
result = this.refDataType;
|
||||
result = this.toSampleValue(this.refDataType);
|
||||
} else {
|
||||
result = this.dataType;
|
||||
result = this.toSampleValue(this.dataType);
|
||||
}
|
||||
}
|
||||
if (this.isCollection) {
|
||||
@@ -573,6 +614,22 @@
|
||||
}
|
||||
};
|
||||
|
||||
SwaggerModelProperty.prototype.toSampleValue = function(value) {
|
||||
var result;
|
||||
if (value === "integer") {
|
||||
result = 0;
|
||||
} else if (value === "boolean") {
|
||||
result = false;
|
||||
} else if (value === "double") {
|
||||
result = 0.0;
|
||||
} else if (value === "string") {
|
||||
result = "";
|
||||
} else {
|
||||
result = value;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
SwaggerModelProperty.prototype.toString = function() {
|
||||
var req, str;
|
||||
req = this.required ? 'propReq' : 'propOpt';
|
||||
@@ -595,7 +652,7 @@
|
||||
})();
|
||||
|
||||
SwaggerOperation = (function() {
|
||||
function SwaggerOperation(nickname, path, method, parameters, summary, notes, type, responseMessages, resource, consumes, produces) {
|
||||
function SwaggerOperation(nickname, path, method, parameters, summary, notes, type, responseMessages, resource, consumes, produces, authorizations) {
|
||||
var parameter, v, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3,
|
||||
_this = this;
|
||||
this.nickname = nickname;
|
||||
@@ -609,6 +666,7 @@
|
||||
this.resource = resource;
|
||||
this.consumes = consumes;
|
||||
this.produces = produces;
|
||||
this.authorizations = authorizations;
|
||||
this["do"] = __bind(this["do"], this);
|
||||
if (this.nickname == null) {
|
||||
this.resource.api.fail("SwaggerOperations must have a nickname.");
|
||||
@@ -651,12 +709,12 @@
|
||||
v = _ref2[_j];
|
||||
if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
|
||||
parameter.allowableValues.descriptiveValues.push({
|
||||
value: v,
|
||||
value: String(v),
|
||||
isDefault: true
|
||||
});
|
||||
} else {
|
||||
parameter.allowableValues.descriptiveValues.push({
|
||||
value: v,
|
||||
value: String(v),
|
||||
isDefault: false
|
||||
});
|
||||
}
|
||||
@@ -751,19 +809,19 @@
|
||||
}
|
||||
if (error == null) {
|
||||
error = function(xhr, textStatus, error) {
|
||||
return console.log(xhr, textStatus, error);
|
||||
return log(xhr, textStatus, error);
|
||||
};
|
||||
}
|
||||
if (callback == null) {
|
||||
callback = function(data) {
|
||||
callback = function(response) {
|
||||
var content;
|
||||
content = null;
|
||||
if (data.content != null) {
|
||||
content = data.content.data;
|
||||
if (response != null) {
|
||||
content = response.data;
|
||||
} else {
|
||||
content = "no data";
|
||||
}
|
||||
return console.log("default callback: " + content);
|
||||
return log("default callback: " + content);
|
||||
};
|
||||
}
|
||||
params = {};
|
||||
@@ -910,7 +968,7 @@
|
||||
|
||||
SwaggerRequest = (function() {
|
||||
function SwaggerRequest(type, url, params, opts, successCallback, errorCallback, operation, execution) {
|
||||
var body, e, fields, headers, key, myHeaders, name, obj, param, parent, possibleParams, requestContentType, responseContentType, urlEncoded, value, values,
|
||||
var body, e, fields, headers, key, myHeaders, name, obj, param, parent, possibleParams, requestContentType, responseContentType, status, urlEncoded, value, values,
|
||||
_this = this;
|
||||
this.type = type;
|
||||
this.url = url;
|
||||
@@ -965,7 +1023,7 @@
|
||||
_results = [];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
param = _ref[_i];
|
||||
if (type.toLowerCase() === "file") {
|
||||
if (typeof type !== 'undefined' && type.toLowerCase() === "file") {
|
||||
_results.push(param);
|
||||
}
|
||||
}
|
||||
@@ -980,8 +1038,8 @@
|
||||
}
|
||||
}
|
||||
if (requestContentType && this.operation.consumes) {
|
||||
if (this.operation.consumes.indexOf(requestContentType) === -1) {
|
||||
console.log("server doesn't consume " + requestContentType + ", try " + JSON.stringify(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];
|
||||
}
|
||||
@@ -998,8 +1056,8 @@
|
||||
responseContentType = null;
|
||||
}
|
||||
if (responseContentType && this.operation.produces) {
|
||||
if (this.operation.produces.indexOf(responseContentType) === -1) {
|
||||
console.log("server can't produce " + responseContentType);
|
||||
if (this.operation.produces[responseContentType] === 'undefined') {
|
||||
log("server can't produce " + responseContentType);
|
||||
}
|
||||
}
|
||||
if (requestContentType && requestContentType.indexOf("application/x-www-form-urlencoded") === 0) {
|
||||
@@ -1048,6 +1106,7 @@
|
||||
method: this.type,
|
||||
headers: myHeaders,
|
||||
body: body,
|
||||
useJQuery: this.useJQuery,
|
||||
on: {
|
||||
error: function(response) {
|
||||
return _this.errorCallback(response, _this.opts.parent);
|
||||
@@ -1069,11 +1128,14 @@
|
||||
} else {
|
||||
e = exports;
|
||||
}
|
||||
e.authorizations.apply(obj);
|
||||
status = e.authorizations.apply(obj, this.operation.authorizations);
|
||||
if (opts.mock == null) {
|
||||
new SwaggerHttp().execute(obj);
|
||||
if (status !== false) {
|
||||
new SwaggerHttp().execute(obj);
|
||||
} else {
|
||||
obj.canceled = true;
|
||||
}
|
||||
} else {
|
||||
console.log(obj);
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -1099,13 +1161,15 @@
|
||||
})();
|
||||
|
||||
SwaggerHttp = (function() {
|
||||
function SwaggerHttp() {}
|
||||
|
||||
SwaggerHttp.prototype.Shred = null;
|
||||
|
||||
SwaggerHttp.prototype.shred = null;
|
||||
|
||||
SwaggerHttp.prototype.content = null;
|
||||
|
||||
function SwaggerHttp() {
|
||||
SwaggerHttp.prototype.initShred = function() {
|
||||
var identity, toString,
|
||||
_this = this;
|
||||
if (typeof window !== 'undefined') {
|
||||
@@ -1122,22 +1186,174 @@
|
||||
};
|
||||
if (typeof window !== 'undefined') {
|
||||
this.content = require("./shred/content");
|
||||
this.content.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
|
||||
return this.content.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
|
||||
parser: identity,
|
||||
stringify: toString
|
||||
});
|
||||
} else {
|
||||
this.Shred.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
|
||||
return this.Shred.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
|
||||
parser: identity,
|
||||
stringify: toString
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
SwaggerHttp.prototype.execute = function(obj) {
|
||||
if (this.isIE() || obj.useJQuery) {
|
||||
return this.executeWithJQuery(obj);
|
||||
} else {
|
||||
return this.executeWithShred(obj);
|
||||
}
|
||||
};
|
||||
|
||||
SwaggerHttp.prototype.executeWithShred = function(obj) {
|
||||
var cb, res,
|
||||
_this = this;
|
||||
if (!this.Shred) {
|
||||
this.initShred();
|
||||
}
|
||||
cb = obj.on;
|
||||
res = {
|
||||
error: function(raw) {
|
||||
var headers, out;
|
||||
if (obj) {
|
||||
headers = raw._headers;
|
||||
out = {
|
||||
headers: headers,
|
||||
url: raw.request.url,
|
||||
method: raw.request.method,
|
||||
status: raw.status,
|
||||
data: raw.content.data
|
||||
};
|
||||
return cb.error(out);
|
||||
}
|
||||
},
|
||||
redirect: function(raw) {
|
||||
var headers, out;
|
||||
if (obj) {
|
||||
headers = raw._headers;
|
||||
out = {
|
||||
headers: headers,
|
||||
url: raw.request.url,
|
||||
method: raw.request.method,
|
||||
status: raw.status,
|
||||
data: raw.content.data
|
||||
};
|
||||
return cb.redirect(out);
|
||||
}
|
||||
},
|
||||
307: function(raw) {
|
||||
var headers, out;
|
||||
if (obj) {
|
||||
headers = raw._headers;
|
||||
out = {
|
||||
headers: headers,
|
||||
url: raw.request.url,
|
||||
method: raw.request.method,
|
||||
status: raw.status,
|
||||
data: raw.content.data
|
||||
};
|
||||
return cb.redirect(out);
|
||||
}
|
||||
},
|
||||
response: function(raw) {
|
||||
var headers, out;
|
||||
if (obj) {
|
||||
headers = raw._headers;
|
||||
out = {
|
||||
headers: headers,
|
||||
url: raw.request.url,
|
||||
method: raw.request.method,
|
||||
status: raw.status,
|
||||
data: raw.content.data
|
||||
};
|
||||
return cb.response(out);
|
||||
}
|
||||
}
|
||||
};
|
||||
if (obj) {
|
||||
obj.on = res;
|
||||
}
|
||||
return this.shred.request(obj);
|
||||
};
|
||||
|
||||
SwaggerHttp.prototype.executeWithJQuery = function(obj) {
|
||||
var beforeSend, cb, request,
|
||||
_this = this;
|
||||
cb = obj.on;
|
||||
request = obj;
|
||||
obj.type = obj.method;
|
||||
obj.cache = false;
|
||||
beforeSend = function(xhr) {
|
||||
var key, _results;
|
||||
if (obj.headers) {
|
||||
_results = [];
|
||||
for (key in obj.headers) {
|
||||
if (key.toLowerCase() === "content-type") {
|
||||
_results.push(obj.contentType = obj.headers[key]);
|
||||
} else if (key.toLowerCase() === "accept") {
|
||||
_results.push(obj.accepts = obj.headers[key]);
|
||||
} else {
|
||||
_results.push(xhr.setRequestHeader(key, obj.headers[key]));
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
}
|
||||
};
|
||||
obj.beforeSend = beforeSend;
|
||||
obj.data = obj.body;
|
||||
obj.complete = function(response, textStatus, opts) {
|
||||
var headerArray, headers, i, out, _i, _j, _k, _ref, _ref1, _ref2, _ref3, _results, _results1;
|
||||
headers = {};
|
||||
headerArray = response.getAllResponseHeaders().split(":");
|
||||
for (i = _i = 0, _ref = headerArray.length / 2, _ref1 = 2.; _ref1 > 0 ? _i <= _ref : _i >= _ref; i = _i += _ref1) {
|
||||
headers[headerArray[i]] = headerArray[i + 1];
|
||||
}
|
||||
out = {
|
||||
headers: headers,
|
||||
url: request.url,
|
||||
method: request.method,
|
||||
status: response.status,
|
||||
data: response.responseText,
|
||||
headers: headers
|
||||
};
|
||||
if (_ref2 = response.status, __indexOf.call((function() {
|
||||
_results = [];
|
||||
for (_j = 200; _j <= 299; _j++){ _results.push(_j); }
|
||||
return _results;
|
||||
}).apply(this), _ref2) >= 0) {
|
||||
cb.response(out);
|
||||
}
|
||||
if ((_ref3 = response.status, __indexOf.call((function() {
|
||||
_results1 = [];
|
||||
for (_k = 400; _k <= 599; _k++){ _results1.push(_k); }
|
||||
return _results1;
|
||||
}).apply(this), _ref3) >= 0) || response.status === 0) {
|
||||
cb.error(out);
|
||||
}
|
||||
return cb.response(out);
|
||||
};
|
||||
$.support.cors = true;
|
||||
return $.ajax(obj);
|
||||
};
|
||||
|
||||
SwaggerHttp.prototype.isIE = function() {
|
||||
var isIE, nav, version;
|
||||
({
|
||||
isIE: false
|
||||
});
|
||||
if (typeof navigator !== 'undefined' && navigator.userAgent) {
|
||||
nav = navigator.userAgent.toLowerCase();
|
||||
if (nav.indexOf('msie') !== -1) {
|
||||
version = parseInt(nav.split('msie')[1]);
|
||||
if (version <= 8) {
|
||||
isIE = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return isIE;
|
||||
};
|
||||
|
||||
return SwaggerHttp;
|
||||
|
||||
})();
|
||||
@@ -1154,15 +1370,25 @@
|
||||
return auth;
|
||||
};
|
||||
|
||||
SwaggerAuthorizations.prototype.apply = function(obj) {
|
||||
var key, value, _ref, _results;
|
||||
SwaggerAuthorizations.prototype.remove = function(name) {
|
||||
return delete this.authz[name];
|
||||
};
|
||||
|
||||
SwaggerAuthorizations.prototype.apply = function(obj, authorizations) {
|
||||
var key, result, status, value, _ref;
|
||||
status = null;
|
||||
_ref = this.authz;
|
||||
_results = [];
|
||||
for (key in _ref) {
|
||||
value = _ref[key];
|
||||
_results.push(value.apply(obj));
|
||||
result = value.apply(obj, authorizations);
|
||||
if (result === false) {
|
||||
status = false;
|
||||
}
|
||||
if (result === true) {
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
return _results;
|
||||
return status;
|
||||
};
|
||||
|
||||
return SwaggerAuthorizations;
|
||||
@@ -1182,7 +1408,7 @@
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
ApiKeyAuthorization.prototype.apply = function(obj) {
|
||||
ApiKeyAuthorization.prototype.apply = function(obj, authorizations) {
|
||||
if (this.type === "query") {
|
||||
if (obj.url.indexOf('?') > 0) {
|
||||
obj.url = obj.url + "&" + this.name + "=" + this.value;
|
||||
@@ -1191,7 +1417,8 @@
|
||||
}
|
||||
return true;
|
||||
} else if (this.type === "header") {
|
||||
return obj.headers[this.name] = this.value;
|
||||
obj.headers[this.name] = this.value;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1200,6 +1427,8 @@
|
||||
})();
|
||||
|
||||
PasswordAuthorization = (function() {
|
||||
PasswordAuthorization._btoa = null;
|
||||
|
||||
PasswordAuthorization.prototype.name = null;
|
||||
|
||||
PasswordAuthorization.prototype.username = null;
|
||||
@@ -1210,10 +1439,20 @@
|
||||
this.name = name;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
PasswordAuthorization._ensureBtoa();
|
||||
}
|
||||
|
||||
PasswordAuthorization.prototype.apply = function(obj) {
|
||||
return obj.headers["Authorization"] = "Basic " + btoa(this.username + ":" + this.password);
|
||||
PasswordAuthorization.prototype.apply = function(obj, authorizations) {
|
||||
obj.headers["Authorization"] = "Basic " + PasswordAuthorization._btoa(this.username + ":" + this.password);
|
||||
return true;
|
||||
};
|
||||
|
||||
PasswordAuthorization._ensureBtoa = function() {
|
||||
if (typeof window !== 'undefined') {
|
||||
return this._btoa = btoa;
|
||||
} else {
|
||||
return this._btoa = require("btoa");
|
||||
}
|
||||
};
|
||||
|
||||
return PasswordAuthorization;
|
||||
@@ -1234,6 +1473,8 @@
|
||||
|
||||
this.PasswordAuthorization = PasswordAuthorization;
|
||||
|
||||
this.SwaggerHttp = SwaggerHttp;
|
||||
|
||||
this.authorizations = new SwaggerAuthorizations();
|
||||
|
||||
}).call(this);
|
||||
|
||||
Vendored
+120
-20
@@ -1281,13 +1281,24 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
};
|
||||
|
||||
SwaggerUi.prototype.buildUrl = function(base, url) {
|
||||
var parts;
|
||||
console.log("base is " + base);
|
||||
parts = base.split("/");
|
||||
base = parts[0] + "//" + parts[2];
|
||||
var endOfPath, parts;
|
||||
log("base is " + base);
|
||||
if (url.indexOf("/") === 0) {
|
||||
parts = base.split("/");
|
||||
base = parts[0] + "//" + parts[2];
|
||||
return base + url;
|
||||
} else {
|
||||
endOfPath = base.length;
|
||||
if (base.indexOf("?") > -1) {
|
||||
endOfPath = Math.min(endOfPath, base.indexOf("?"));
|
||||
}
|
||||
if (base.indexOf("#") > -1) {
|
||||
endOfPath = Math.min(endOfPath, base.indexOf("#"));
|
||||
}
|
||||
base = base.substring(0, endOfPath);
|
||||
if (base.indexOf("/", base.length - 1) !== -1) {
|
||||
return base + url;
|
||||
}
|
||||
return base + "/" + url;
|
||||
}
|
||||
};
|
||||
@@ -1435,7 +1446,6 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
|
||||
ResourceView.prototype.render = function() {
|
||||
var operation, _i, _len, _ref4;
|
||||
console.log(this.model.description);
|
||||
$(this.el).html(Handlebars.templates.resource(this.model));
|
||||
this.number = 0;
|
||||
_ref4 = this.model.operationsArray;
|
||||
@@ -1470,6 +1480,8 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
return _ref4;
|
||||
}
|
||||
|
||||
OperationView.prototype.invocationUrl = null;
|
||||
|
||||
OperationView.prototype.events = {
|
||||
'submit .sandbox': 'submitOperation',
|
||||
'click .submit': 'submitOperation',
|
||||
@@ -1511,7 +1523,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
type = param.type || param.dataType;
|
||||
if (type.toLowerCase() === 'file') {
|
||||
if (!contentTypeModel.consumes) {
|
||||
console.log("set content type ");
|
||||
log("set content type ");
|
||||
contentTypeModel.consumes = 'multipart/form-data';
|
||||
}
|
||||
}
|
||||
@@ -1554,7 +1566,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
};
|
||||
|
||||
OperationView.prototype.submitOperation = function(e) {
|
||||
var error_free, form, map, o, opts, val, _i, _j, _k, _len, _len1, _len2, _ref5, _ref6, _ref7;
|
||||
var error_free, form, isFileUpload, map, o, opts, val, _i, _j, _k, _len, _len1, _len2, _ref5, _ref6, _ref7;
|
||||
if (e != null) {
|
||||
e.preventDefault();
|
||||
}
|
||||
@@ -1578,12 +1590,16 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
opts = {
|
||||
parent: this
|
||||
};
|
||||
isFileUpload = false;
|
||||
_ref5 = form.find("input");
|
||||
for (_i = 0, _len = _ref5.length; _i < _len; _i++) {
|
||||
o = _ref5[_i];
|
||||
if ((o.value != null) && jQuery.trim(o.value).length > 0) {
|
||||
map[o.name] = o.value;
|
||||
}
|
||||
if (o.type === "file") {
|
||||
isFileUpload = true;
|
||||
}
|
||||
}
|
||||
_ref6 = form.find("textarea");
|
||||
for (_j = 0, _len1 = _ref6.length; _j < _len1; _j++) {
|
||||
@@ -1603,7 +1619,11 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
opts.responseContentType = $("div select[name=responseContentType]", $(this.el)).val();
|
||||
opts.requestContentType = $("div select[name=parameterContentType]", $(this.el)).val();
|
||||
$(".response_throbber", $(this.el)).show();
|
||||
return this.model["do"](map, opts, this.showCompleteStatus, this.showErrorStatus, this);
|
||||
if (isFileUpload) {
|
||||
return this.handleFileUpload(map, form);
|
||||
} else {
|
||||
return this.model["do"](map, opts, this.showCompleteStatus, this.showErrorStatus, this);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1611,6 +1631,84 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
return parent.showCompleteStatus(response);
|
||||
};
|
||||
|
||||
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,
|
||||
_this = this;
|
||||
log("it's a file upload");
|
||||
_ref5 = form.serializeArray();
|
||||
for (_i = 0, _len = _ref5.length; _i < _len; _i++) {
|
||||
o = _ref5[_i];
|
||||
if ((o.value != null) && jQuery.trim(o.value).length > 0) {
|
||||
map[o.name] = o.value;
|
||||
}
|
||||
}
|
||||
bodyParam = new FormData();
|
||||
_ref6 = this.model.parameters;
|
||||
for (_j = 0, _len1 = _ref6.length; _j < _len1; _j++) {
|
||||
param = _ref6[_j];
|
||||
if (param.paramType === 'form') {
|
||||
bodyParam.append(param.name, map[param.name]);
|
||||
}
|
||||
}
|
||||
headerParams = {};
|
||||
_ref7 = this.model.parameters;
|
||||
for (_k = 0, _len2 = _ref7.length; _k < _len2; _k++) {
|
||||
param = _ref7[_k];
|
||||
if (param.paramType === 'header') {
|
||||
headerParams[param.name] = map[param.name];
|
||||
}
|
||||
}
|
||||
log(headerParams);
|
||||
_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]);
|
||||
}
|
||||
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 = {
|
||||
type: this.model.method,
|
||||
url: this.invocationUrl,
|
||||
headers: headerParams,
|
||||
data: bodyParam,
|
||||
dataType: 'json',
|
||||
contentType: false,
|
||||
processData: false,
|
||||
error: function(data, textStatus, error) {
|
||||
return _this.showErrorStatus(_this.wrap(data), _this);
|
||||
},
|
||||
success: function(data) {
|
||||
return _this.showResponse(data, _this);
|
||||
},
|
||||
complete: function(data) {
|
||||
return _this.showCompleteStatus(_this.wrap(data), _this);
|
||||
}
|
||||
};
|
||||
if (window.authorizations) {
|
||||
window.authorizations.apply(obj);
|
||||
}
|
||||
jQuery.ajax(obj);
|
||||
return false;
|
||||
};
|
||||
|
||||
OperationView.prototype.wrap = function(data) {
|
||||
var headerArray, headers, i, o, _i, _ref5, _ref6;
|
||||
headers = {};
|
||||
headerArray = data.getAllResponseHeaders().split(":");
|
||||
for (i = _i = 0, _ref5 = headerArray.length / 2, _ref6 = 2.; _ref6 > 0 ? _i <= _ref5 : _i >= _ref5; i = _i += _ref6) {
|
||||
headers[headerArray[i]] = headerArray[i + 1];
|
||||
}
|
||||
o = {};
|
||||
o.content = {};
|
||||
o.content.data = data.responseText;
|
||||
o.headers = headers;
|
||||
o.request = {};
|
||||
o.request.url = this.invocationUrl;
|
||||
o.status = data.status;
|
||||
return o;
|
||||
};
|
||||
|
||||
OperationView.prototype.getSelectedValue = function(select) {
|
||||
var opt, options, _i, _len, _ref5;
|
||||
if (!select.multiple) {
|
||||
@@ -1727,32 +1825,34 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {};
|
||||
return formatted;
|
||||
};
|
||||
|
||||
OperationView.prototype.showStatus = function(data) {
|
||||
OperationView.prototype.showStatus = function(response) {
|
||||
var code, content, contentType, headers, pre, response_body;
|
||||
content = data.content.data;
|
||||
headers = data.getHeaders();
|
||||
contentType = headers["Content-Type"];
|
||||
if (content === void 0) {
|
||||
content = response.data;
|
||||
headers = response.headers;
|
||||
contentType = headers && headers["Content-Type"] ? headers["Content-Type"].split(";")[0].trim() : null;
|
||||
if (!content) {
|
||||
code = $('<code />').text("no content");
|
||||
pre = $('<pre class="json" />').append(code);
|
||||
} else if (contentType.indexOf("application/json") === 0 || contentType.indexOf("application/hal+json") === 0) {
|
||||
code = $('<code />').text(JSON.stringify(JSON.parse(content), null, 2));
|
||||
} else if (contentType === "application/json" || /\+json$/.test(contentType)) {
|
||||
code = $('<code />').text(JSON.stringify(JSON.parse(content), null, " "));
|
||||
pre = $('<pre class="json" />').append(code);
|
||||
} else if (contentType.indexOf("application/xml") === 0) {
|
||||
} else if (contentType === "application/xml" || /\+xml$/.test(contentType)) {
|
||||
code = $('<code />').text(this.formatXml(content));
|
||||
pre = $('<pre class="xml" />').append(code);
|
||||
} else if (contentType.indexOf("text/html") === 0) {
|
||||
} else if (contentType === "text/html") {
|
||||
code = $('<code />').html(content);
|
||||
pre = $('<pre class="xml" />').append(code);
|
||||
} else if (/^image\//.test(contentType)) {
|
||||
pre = $('<img>').attr('src', response.url);
|
||||
} else {
|
||||
code = $('<code />').text(content);
|
||||
pre = $('<pre class="json" />').append(code);
|
||||
}
|
||||
response_body = pre;
|
||||
$(".request_url").html("<pre>" + data.request.url + "</pre>");
|
||||
$(".response_code", $(this.el)).html("<pre>" + data.status + "</pre>");
|
||||
$(".request_url", $(this.el)).html("<pre>" + response.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(data.getHeaders()) + "</pre>");
|
||||
$(".response_headers", $(this.el)).html("<pre>" + JSON.stringify(response.headers, null, " ").replace(/\n/g, "<br>") + "</pre>");
|
||||
$(".response", $(this.el)).slideDown();
|
||||
$(".response_hider", $(this.el)).show();
|
||||
$(".response_throbber", $(this.el)).hide();
|
||||
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+1251
-1185
File diff suppressed because it is too large
Load Diff
+4
-2
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "swagger-ui",
|
||||
"version": "2.0.2",
|
||||
"version": "2.0.7",
|
||||
"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",
|
||||
@@ -19,6 +19,8 @@
|
||||
"readmeFilename": "README.md",
|
||||
"dependencies": {
|
||||
"coffee-script": "~1.5.0",
|
||||
"handlebars": "~1.0.10"
|
||||
"swagger-client": "2.0.13",
|
||||
"handlebars": "~1.0.10",
|
||||
"less": "~1.4.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,14 +68,21 @@ class SwaggerUi extends Backbone.Router
|
||||
)
|
||||
|
||||
buildUrl: (base, url) ->
|
||||
console.log "base is " + base
|
||||
parts = base.split("/")
|
||||
base = parts[0] + "//" + parts[2]
|
||||
log "base is " + base
|
||||
if url.indexOf("/") is 0
|
||||
parts = base.split("/")
|
||||
base = parts[0] + "//" + parts[2]
|
||||
base + url
|
||||
else
|
||||
base + "/" + url
|
||||
|
||||
endOfPath = base.length
|
||||
if base.indexOf("?") > -1
|
||||
endOfPath = Math.min(endOfPath, base.indexOf("?"))
|
||||
if base.indexOf("#") > -1
|
||||
endOfPath = Math.min(endOfPath, base.indexOf("#"))
|
||||
base = base.substring(0, endOfPath);
|
||||
if base.indexOf( "/", base.length - 1 ) isnt -1
|
||||
return base + url
|
||||
return base + "/" + url
|
||||
|
||||
# Shows message on topbar of the ui
|
||||
showMessage: (data = '') ->
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
class OperationView extends Backbone.View
|
||||
invocationUrl: null
|
||||
|
||||
events: {
|
||||
'submit .sandbox' : 'submitOperation'
|
||||
'click .submit' : 'submitOperation'
|
||||
@@ -35,7 +37,7 @@ class OperationView extends Backbone.View
|
||||
type = param.type || param.dataType
|
||||
if type.toLowerCase() == 'file'
|
||||
if !contentTypeModel.consumes
|
||||
console.log "set content type "
|
||||
log "set content type "
|
||||
contentTypeModel.consumes = 'multipart/form-data'
|
||||
|
||||
responseContentTypeView = new ResponseContentTypeView({model: contentTypeModel})
|
||||
@@ -77,13 +79,14 @@ class OperationView extends Backbone.View
|
||||
if error_free
|
||||
map = {}
|
||||
opts = {parent: @}
|
||||
#for o in form.serializeArray()
|
||||
#if(o.value? && jQuery.trim(o.value).length > 0)
|
||||
#map[o.name] = o.value
|
||||
|
||||
isFileUpload = false
|
||||
|
||||
for o in form.find("input")
|
||||
if(o.value? && jQuery.trim(o.value).length > 0)
|
||||
map[o.name] = o.value
|
||||
if o.type is "file"
|
||||
isFileUpload = true
|
||||
|
||||
for o in form.find("textarea")
|
||||
if(o.value? && jQuery.trim(o.value).length > 0)
|
||||
@@ -98,12 +101,91 @@ class OperationView extends Backbone.View
|
||||
opts.requestContentType = $("div select[name=parameterContentType]", $(@el)).val()
|
||||
|
||||
$(".response_throbber", $(@el)).show()
|
||||
|
||||
@model.do(map, opts, @showCompleteStatus, @showErrorStatus, @)
|
||||
if isFileUpload
|
||||
@handleFileUpload map, form
|
||||
else
|
||||
@model.do(map, opts, @showCompleteStatus, @showErrorStatus, @)
|
||||
|
||||
success: (response, parent) ->
|
||||
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()
|
||||
|
||||
# add params
|
||||
for param in @model.parameters
|
||||
if param.paramType is 'form'
|
||||
bodyParam.append(param.name, map[param.name])
|
||||
|
||||
# headers in operation
|
||||
headerParams = {}
|
||||
for param in @model.parameters
|
||||
if param.paramType is 'header'
|
||||
headerParams[param.name] = map[param.name]
|
||||
|
||||
log headerParams
|
||||
|
||||
# add files
|
||||
for el in form.find('input[type~="file"]')
|
||||
bodyParam.append($(el).attr('name'), el.files[0])
|
||||
|
||||
log(bodyParam)
|
||||
|
||||
@invocationUrl =
|
||||
if @model.supportHeaderParams()
|
||||
headerParams = @model.getHeaderParams(map)
|
||||
@model.urlify(map, false)
|
||||
else
|
||||
@model.urlify(map, true)
|
||||
|
||||
$(".request_url", $(@el)).html "<pre>" + @invocationUrl + "</pre>"
|
||||
|
||||
obj =
|
||||
type: @model.method
|
||||
url: @invocationUrl
|
||||
headers: headerParams
|
||||
data: bodyParam
|
||||
dataType: 'json'
|
||||
contentType: false
|
||||
processData: false
|
||||
error: (data, textStatus, error) =>
|
||||
@showErrorStatus(@wrap(data), @)
|
||||
success: (data) =>
|
||||
@showResponse(data, @)
|
||||
complete: (data) =>
|
||||
@showCompleteStatus(@wrap(data), @)
|
||||
|
||||
# apply authorizations
|
||||
if window.authorizations
|
||||
window.authorizations.apply obj
|
||||
|
||||
jQuery.ajax(obj)
|
||||
false
|
||||
# end of file-upload nastiness
|
||||
|
||||
# wraps a jquery response as a shred response
|
||||
|
||||
wrap: (data) ->
|
||||
headers = {}
|
||||
headerArray = data.getAllResponseHeaders().split(":")
|
||||
for i in [0..headerArray.length/2] by (2)
|
||||
headers[headerArray[i]] = headerArray[i+1]
|
||||
|
||||
o = {}
|
||||
o.content = {}
|
||||
o.content.data = data.responseText
|
||||
o.headers = headers
|
||||
o.request = {}
|
||||
o.request.url = @invocationUrl
|
||||
o.status = data.status
|
||||
o
|
||||
|
||||
getSelectedValue: (select) ->
|
||||
if !select.multiple
|
||||
select.value
|
||||
@@ -195,35 +277,37 @@ class OperationView extends Backbone.View
|
||||
|
||||
|
||||
# puts the response data in UI
|
||||
showStatus: (data) ->
|
||||
content = data.content.data
|
||||
headers = data.getHeaders()
|
||||
showStatus: (response) ->
|
||||
content = response.data
|
||||
headers = response.headers
|
||||
|
||||
# if server is nice, and sends content-type back, we can use it
|
||||
contentType = headers["Content-Type"]
|
||||
contentType = if headers && headers["Content-Type"] then headers["Content-Type"].split(";")[0].trim() else null
|
||||
|
||||
if content == undefined
|
||||
if !content
|
||||
code = $('<code />').text("no content")
|
||||
pre = $('<pre class="json" />').append(code)
|
||||
else if contentType.indexOf("application/json") == 0 || contentType.indexOf("application/hal+json") == 0
|
||||
code = $('<code />').text(JSON.stringify(JSON.parse(content), null, 2))
|
||||
else if contentType is "application/json" || /\+json$/.test(contentType)
|
||||
code = $('<code />').text(JSON.stringify(JSON.parse(content), null, " "))
|
||||
pre = $('<pre class="json" />').append(code)
|
||||
else if contentType.indexOf("application/xml") == 0
|
||||
else if contentType is "application/xml" || /\+xml$/.test(contentType)
|
||||
code = $('<code />').text(@formatXml(content))
|
||||
pre = $('<pre class="xml" />').append(code)
|
||||
else if contentType.indexOf("text/html") == 0
|
||||
else if contentType is "text/html"
|
||||
code = $('<code />').html(content)
|
||||
pre = $('<pre class="xml" />').append(code)
|
||||
else if /^image\//.test(contentType)
|
||||
pre = $('<img>').attr('src',response.url)
|
||||
else
|
||||
# don't know what to render!
|
||||
code = $('<code />').text(content)
|
||||
pre = $('<pre class="json" />').append(code)
|
||||
|
||||
response_body = pre
|
||||
$(".request_url").html "<pre>" + data.request.url + "</pre>"
|
||||
$(".response_code", $(@el)).html "<pre>" + data.status + "</pre>"
|
||||
$(".request_url", $(@el)).html "<pre>" + response.url + "</pre>"
|
||||
$(".response_code", $(@el)).html "<pre>" + response.status + "</pre>"
|
||||
$(".response_body", $(@el)).html response_body
|
||||
$(".response_headers", $(@el)).html "<pre>" + JSON.stringify(data.getHeaders()) + "</pre>"
|
||||
$(".response_headers", $(@el)).html "<pre>" + JSON.stringify(response.headers, null, " ").replace(/\n/g, "<br>") + "</pre>"
|
||||
$(".response", $(@el)).slideDown()
|
||||
$(".response_hider", $(@el)).show()
|
||||
$(".response_throbber", $(@el)).hide()
|
||||
|
||||
@@ -2,7 +2,6 @@ class ResourceView extends Backbone.View
|
||||
initialize: ->
|
||||
|
||||
render: ->
|
||||
console.log @model.description
|
||||
$(@el).html(Handlebars.templates.resource(@model))
|
||||
|
||||
@number = 0
|
||||
|
||||
+1043
-1755
File diff suppressed because it is too large
Load Diff
@@ -2,10 +2,10 @@
|
||||
<html>
|
||||
<head>
|
||||
<title>Swagger UI</title>
|
||||
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
|
||||
<link href='https://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
|
||||
<link href='css/highlight.default.css' media='screen' rel='stylesheet' type='text/css'/>
|
||||
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
|
||||
<script type="text/javascript" src="lib/shred.bundle.js" /></script>
|
||||
<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>
|
||||
<script src='lib/jquery.wiggle.min.js' type='text/javascript'></script>
|
||||
@@ -23,25 +23,20 @@
|
||||
dom_id: "swagger-ui-container",
|
||||
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
|
||||
onComplete: function(swaggerApi, swaggerUi){
|
||||
if(console) {
|
||||
console.log("Loaded SwaggerUI")
|
||||
}
|
||||
log("Loaded SwaggerUI")
|
||||
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
|
||||
},
|
||||
onFailure: function(data) {
|
||||
if(console) {
|
||||
console.log("Unable to Load SwaggerUI");
|
||||
console.log(data);
|
||||
}
|
||||
log("Unable to Load SwaggerUI");
|
||||
},
|
||||
docExpansion: "none"
|
||||
});
|
||||
|
||||
$('#input_apiKey').change(function() {
|
||||
var key = $('#input_apiKey')[0].value;
|
||||
console.log("key: " + key);
|
||||
log("key: " + key);
|
||||
if(key && key.trim() != "") {
|
||||
console.log("added key " + key);
|
||||
log("added key " + key);
|
||||
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "query"));
|
||||
}
|
||||
})
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/* http://meyerweb.com/eric/tools/css/reset/ v2.0 | 20110126 */
|
||||
html, body, div, span, applet, object, iframe,
|
||||
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
||||
a, abbr, acronym, address, big, cite, code,
|
||||
del, dfn, em, img, ins, kbd, q, s, samp,
|
||||
small, strike, strong, sub, sup, tt, var,
|
||||
b, u, i, center,
|
||||
dl, dt, dd, ol, ul, li,
|
||||
fieldset, form, label, legend,
|
||||
table, caption, tbody, tfoot, thead, tr, th, td,
|
||||
article, aside, canvas, details, embed,
|
||||
figure, figcaption, footer, header, hgroup,
|
||||
menu, nav, output, ruby, section, summary,
|
||||
time, mark, audio, video {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
font-size: 100%;
|
||||
font: inherit;
|
||||
vertical-align: baseline;
|
||||
}
|
||||
|
||||
/* HTML5 display-role reset for older browsers */
|
||||
article, aside, details, figcaption, figure,
|
||||
footer, header, hgroup, menu, nav, section {
|
||||
display: block;
|
||||
}
|
||||
|
||||
body {
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
ol, ul {
|
||||
list-style: none;
|
||||
}
|
||||
|
||||
blockquote, q {
|
||||
quotes: none;
|
||||
}
|
||||
|
||||
blockquote:before, blockquote:after,
|
||||
q:before, q:after {
|
||||
content: '';
|
||||
content: none;
|
||||
}
|
||||
|
||||
table {
|
||||
border-collapse: collapse;
|
||||
border-spacing: 0;
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
@import 'src/main/less/reset.less';
|
||||
@import 'src/main/less/specs.less';
|
||||
|
||||
#header {
|
||||
background-color: #89bf04;
|
||||
padding: 14px;
|
||||
a#logo {
|
||||
font-size: 1.5em;
|
||||
font-weight: bold;
|
||||
text-decoration: none;
|
||||
background: transparent url(../images/logo_small.png) no-repeat left center;
|
||||
padding: 20px 0 20px 40px;
|
||||
color: white;
|
||||
}
|
||||
form#api_selector {
|
||||
display: block;
|
||||
clear: none;
|
||||
float: right;
|
||||
.input {
|
||||
display: block;
|
||||
clear: none;
|
||||
float: left;
|
||||
margin: 0 10px 0 0;
|
||||
input#input_apiKey {
|
||||
width: 200px;
|
||||
}
|
||||
input#input_baseUrl {
|
||||
width: 400px;
|
||||
}
|
||||
a#explore {
|
||||
display: block;
|
||||
text-decoration: none;
|
||||
font-weight: bold;
|
||||
padding: 6px 8px;
|
||||
font-size: 0.9em;
|
||||
color: white;
|
||||
background-color: #547f00;
|
||||
-moz-border-radius: 4px;
|
||||
-webkit-border-radius: 4px;
|
||||
-o-border-radius: 4px;
|
||||
-ms-border-radius: 4px;
|
||||
-khtml-border-radius: 4px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
a#explore:hover {
|
||||
background-color: #547f00;
|
||||
}
|
||||
input {
|
||||
font-size: 0.9em;
|
||||
padding: 3px;
|
||||
margin: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#content_message {
|
||||
margin: 10px 15px;
|
||||
font-style: italic;
|
||||
color: #999999;
|
||||
}
|
||||
|
||||
#message-bar {
|
||||
min-height: 30px;
|
||||
text-align: center;
|
||||
padding-top: 10px;
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user