merged with swagger.js-2.0-develop

This commit is contained in:
Tony Tam
2013-07-07 00:53:30 -07:00
parent 7334079535
commit 09be20c97d
13 changed files with 926 additions and 678 deletions

122
dist/index.html vendored
View File

@@ -1,74 +1,80 @@
<!DOCTYPE html>
<html>
<head>
<title>Swagger UI</title>
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
<link href='css/hightlight.default.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
<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>
<script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
<script src='lib/handlebars-1.0.rc.1.js' type='text/javascript'></script>
<script src='lib/underscore-min.js' type='text/javascript'></script>
<script src='lib/backbone-min.js' type='text/javascript'></script>
<script src='lib/swagger.js' type='text/javascript'></script>
<script src='swagger-ui.js' type='text/javascript'></script>
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
<title>Swagger UI</title>
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
<link href='css/hightlight.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 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>
<script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
<script src='lib/handlebars-1.0.rc.1.js' type='text/javascript'></script>
<script src='lib/underscore-min.js' type='text/javascript'></script>
<script src='lib/backbone-min.js' type='text/javascript'></script>
<script src='lib/swagger.js' type='text/javascript'></script>
<script src='swagger-ui.js' type='text/javascript'></script>
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
discoveryUrl:"http://localhost:8002/api/api-docs",
dom_id:"swagger-ui-container",
supportHeaderParams: false,
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
onComplete: function(swaggerApi, swaggerUi){
if(console) {
console.log("Loaded SwaggerUI")
console.log(swaggerApi);
console.log(swaggerUi);
}
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
},
onFailure: function(data) {
if(console) {
console.log("Unable to Load SwaggerUI");
console.log(data);
}
},
docExpansion: "none"
});
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
discoveryUrl:"http://localhost:8002/api/api-docs",
apiKey:"special-key",
dom_id:"swagger-ui-container",
supportHeaderParams: false,
supportedSubmitMethods: ['get', 'post', 'put'],
onComplete: function(swaggerApi, swaggerUi){
if(console) {
console.log("Loaded SwaggerUI")
console.log(swaggerApi);
console.log(swaggerUi);
}
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
},
onFailure: function(data) {
if(console) {
console.log("Unable to Load SwaggerUI");
console.log(data);
}
},
docExpansion: "none"
});
$('#input_apiKey').change(function() {
var key = $('#input_apiKey')[0].value;
console.log("key: " + key);
if(key && key.trim() != "") {
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "query"));
}
})
window.swaggerUi.load();
});
window.swaggerUi.load();
});
</script>
</script>
</head>
<body>
<div id='header'>
<div class="swagger-ui-wrap">
<a id="logo" href="http://swagger.wordnik.com">swagger</a>
<div class="swagger-ui-wrap">
<a id="logo" href="http://swagger.wordnik.com">swagger</a>
<form id='api_selector'>
<div class='input icon-btn'>
<img id="show-pet-store-icon" src="images/pet_store_api.png" title="Show Swagger Petstore Example Apis">
</div>
<div class='input icon-btn'>
<img id="show-wordnik-dev-icon" src="images/wordnik_api.png" title="Show Wordnik Developer Apis">
</div>
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl"
type="text"/></div>
<div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
<div class='input'><a id="explore" href="#">Explore</a></div>
</form>
</div>
<form id='api_selector'>
<div class='input icon-btn'>
<img id="show-pet-store-icon" src="images/pet_store_api.png" title="Show Swagger Petstore Example Apis">
</div>
<div class='input icon-btn'>
<img id="show-wordnik-dev-icon" src="images/wordnik_api.png" title="Show Wordnik Developer Apis">
</div>
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
<div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
<div class='input'><a id="explore" href="#">Explore</a></div>
</form>
</div>
</div>
<div id="message-bar" class="swagger-ui-wrap">
&nbsp;
&nbsp;
</div>
<div id="swagger-ui-container" class="swagger-ui-wrap">

634
dist/lib/swagger.js vendored
View File

@@ -1,6 +1,6 @@
// Generated by CoffeeScript 1.4.0
(function() {
var SwaggerApi, SwaggerModel, SwaggerModelProperty, SwaggerOperation, SwaggerRequest, SwaggerResource,
var ApiKeyAuthorization, SwaggerApi, SwaggerAuthorizations, SwaggerHttp, SwaggerModel, SwaggerModelProperty, SwaggerOperation, SwaggerRequest, SwaggerResource,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
SwaggerApi = (function() {
@@ -9,10 +9,12 @@
SwaggerApi.prototype.debug = false;
SwaggerApi.prototype.api_key = null;
SwaggerApi.prototype.basePath = null;
SwaggerApi.prototype.authorizations = null;
SwaggerApi.prototype.authorizationScheme = null;
function SwaggerApi(options) {
if (options == null) {
options = {};
@@ -20,97 +22,64 @@
if (options.discoveryUrl != null) {
this.discoveryUrl = options.discoveryUrl;
}
if (options.debug != null) {
this.debug = options.debug;
}
this.apiKeyName = options.apiKeyName != null ? options.apiKeyName : 'api_key';
if (options.apiKey != null) {
this.api_key = options.apiKey;
}
if (options.api_key != null) {
this.api_key = options.api_key;
}
if (options.verbose != null) {
this.verbose = options.verbose;
}
this.supportHeaderParams = options.supportHeaderParams != null ? options.supportHeaderParams : false;
this.supportedSubmitMethods = options.supportedSubmitMethods != null ? options.supportedSubmitMethods : ['get'];
if (options.success != null) {
this.success = options.success;
}
this.failure = options.failure != null ? options.failure : function() {};
this.progress = options.progress != null ? options.progress : function() {};
this.headers = options.headers != null ? options.headers : {};
this.booleanValues = options.booleanValues != null ? options.booleanValues : new Array('true', 'false');
this.discoveryUrl = this.suffixApiKey(this.discoveryUrl);
this.defaultHeaders = options.headers != null ? options.headers : {};
if (options.success != null) {
this.build();
}
}
SwaggerApi.prototype.build = function() {
var _this = this;
var obj,
_this = this;
this.progress('fetching resource list: ' + this.discoveryUrl);
return jQuery.getJSON(this.discoveryUrl, function(response) {
var res, resource, _i, _j, _len, _len1, _ref, _ref1;
if (response.apiVersion != null) {
_this.apiVersion = response.apiVersion;
}
if ((response.basePath != null) && jQuery.trim(response.basePath).length > 0) {
_this.basePath = response.basePath;
if (_this.basePath.match(/^HTTP/i) == null) {
_this.fail("discoveryUrl basePath must be a URL.");
}
_this.basePath = _this.basePath.replace(/\/$/, '');
} else {
if (_this.discoveryUrl.indexOf('?') > 0) {
_this.basePath = _this.discoveryUrl.substring(0, _this.discoveryUrl.lastIndexOf('?'));
} else {
_this.basePath = _this.discoveryUrl;
}
log('derived basepath from discoveryUrl as ' + _this.basePath);
}
_this.apis = {};
_this.apisArray = [];
if (response.resourcePath != null) {
_this.resourcePath = response.resourcePath;
res = null;
_ref = response.apis;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
resource = _ref[_i];
if (res === null) {
res = new SwaggerResource(resource, _this);
obj = {
url: this.discoveryUrl,
method: "get",
on: {
error: function(response) {
if (_this.discoveryUrl.substring(0, 4) !== 'http') {
return _this.fail('Please specify the protocol for ' + _this.discoveryUrl);
} else if (error.status === 0) {
return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
} else if (error.status === 404) {
return _this.fail('Can\'t read swagger JSON from ' + _this.discoveryUrl);
} else {
res.addOperations(resource.path, resource.operations);
return _this.fail(error.status + ' : ' + error.statusText + ' ' + _this.discoveryUrl);
}
}
if (res != null) {
_this.apis[res.name] = res;
_this.apisArray.push(res);
res.ready = true;
_this.selfReflect();
}
} else {
_ref1 = response.apis;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
resource = _ref1[_j];
res = new SwaggerResource(resource, _this);
_this.apis[res.name] = res;
_this.apisArray.push(res);
},
response: function(rawResponse) {
var res, resource, response, _i, _len, _ref;
response = JSON.parse(rawResponse.content.data);
if (response.apiVersion != null) {
_this.apiVersion = response.apiVersion;
}
_this.apis = {};
_this.apisArray = [];
if (response.basePath) {
_this.basePath = response.basePath;
} else if (_this.discoveryUrl.indexOf('?') > 0) {
_this.basePath = _this.discoveryUrl.substring(0, _this.discoveryUrl.lastIndexOf('?'));
} else {
_this.basePath = _this.discoveryUrl;
}
_ref = response.apis;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
resource = _ref[_i];
res = new SwaggerResource(resource, _this);
_this.apis[res.name] = res;
_this.apisArray.push(res);
}
return _this;
}
}
return _this;
}).error(function(error) {
if (_this.discoveryUrl.substring(0, 4) !== 'http') {
return _this.fail('Please specify the protocol for ' + _this.discoveryUrl);
} else if (error.status === 0) {
return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
} else if (error.status === 404) {
return _this.fail('Can\'t read swagger JSON from ' + _this.discoveryUrl);
} else {
return _this.fail(error.status + ' : ' + error.statusText + ' ' + _this.discoveryUrl);
}
});
};
return new SwaggerHttp().execute(obj);
};
SwaggerApi.prototype.selfReflect = function() {
@@ -160,16 +129,6 @@
return _results;
};
SwaggerApi.prototype.suffixApiKey = function(url) {
var sep;
if ((this.api_key != null) && jQuery.trim(this.api_key).length > 0 && (url != null)) {
sep = url.indexOf('?') > 0 ? '&' : '?';
return url + sep + this.apiKeyName + '=' + this.api_key;
} else {
return url;
}
};
SwaggerApi.prototype.help = function() {
var operation, operation_name, parameter, resource, resource_name, _i, _len, _ref, _ref1, _ref2;
_ref = this.apis;
@@ -196,16 +155,24 @@
SwaggerResource = (function() {
SwaggerResource.prototype.api = null;
SwaggerResource.prototype.produces = null;
SwaggerResource.prototype.consumes = null;
function SwaggerResource(resourceObj, api) {
var parts,
var consumes, obj, parts, produces,
_this = this;
this.api = api;
this.api = this.api;
produces = [];
consumes = [];
this.path = this.api.resourcePath != null ? this.api.resourcePath : resourceObj.path;
this.description = resourceObj.description;
parts = this.path.split("/");
this.name = parts[parts.length - 1].replace('.{format}', '');
this.basePath = this.api.basePath;
console.log('bp: ' + this.basePath);
this.operations = {};
this.operationsArray = [];
this.modelsArray = [];
@@ -219,30 +186,42 @@
if (this.path == null) {
this.api.fail("SwaggerResources must have a path.");
}
this.url = this.api.suffixApiKey(this.api.basePath + this.path.replace('{format}', 'json'));
console.log('basePath: ' + this.api.basePath);
console.log('url: ' + this.url);
this.url = this.api.basePath + this.path.replace('{format}', 'json');
this.api.progress('fetching resource ' + this.name + ': ' + this.url);
jQuery.getJSON(this.url, function(response) {
var endpoint, _i, _len, _ref;
if ((response.basePath != null) && jQuery.trim(response.basePath).length > 0) {
_this.basePath = response.basePath;
_this.basePath = _this.basePath.replace(/\/$/, '');
}
_this.addModels(response.models);
if (response.apis) {
_ref = response.apis;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
endpoint = _ref[_i];
_this.addOperations(endpoint.path, endpoint.operations);
obj = {
url: this.url,
method: "get",
on: {
error: function(response) {
return _this.api.fail("Unable to read api '" + _this.name + "' from path " + _this.url + " (server returned " + error.statusText + ")");
},
response: function(rawResponse) {
var endpoint, response, _i, _len, _ref;
response = JSON.parse(rawResponse.content._body);
if (response.produces != null) {
_this.produces = response.produces;
}
if (response.consumes != null) {
_this.consumes = response.consumes;
}
if ((response.basePath != null) && response.basePath.replace(/\s/g, '').length > 0) {
_this.basePath = response.basePath;
}
_this.addModels(response.models);
if (response.apis) {
_ref = response.apis;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
endpoint = _ref[_i];
_this.addOperations(endpoint.path, endpoint.operations);
}
}
_this.api[_this.name] = _this;
_this.ready = true;
return _this.api.selfReflect();
}
}
_this.api[_this.name] = _this;
_this.ready = true;
return _this.api.selfReflect();
}).error(function(error) {
return _this.api.fail("Unable to read api '" + _this.name + "' from path " + _this.url + " (server returned " + error.statusText + ")");
});
};
new SwaggerHttp().execute(obj);
}
}
@@ -267,29 +246,35 @@
};
SwaggerResource.prototype.addOperations = function(resource_path, ops) {
var consumes, err, errorResponses, o, op, _i, _j, _len, _len1, _results;
var consumes, method, o, op, produces, responseMessages, _i, _len, _results;
if (ops) {
_results = [];
for (_i = 0, _len = ops.length; _i < _len; _i++) {
o = ops[_i];
consumes = o.consumes;
consumes = null;
produces = null;
if (o.consumes != null) {
consumes = o.consumes;
} else {
consumes = this.consumes;
}
if (o.produces != null) {
produces = o.produces;
} else {
produces = this.produces;
}
responseMessages = o.responseMessages;
method = o.method;
if (o.httpMethod) {
method = o.httpMethod;
}
if (o.supportedContentTypes) {
consumes = o.supportedContentTypes;
}
errorResponses = o.responseMessages;
if (errorResponses) {
for (_j = 0, _len1 = errorResponses.length; _j < _len1; _j++) {
err = errorResponses[_j];
err.reason = err.message;
}
}
if (o.errorResponses) {
errorResponses = o.errorResponses;
responseMessages = o.errorResponses;
}
if (o.method) {
o.httpMethod = o.method;
}
op = new SwaggerOperation(o.nickname, resource_path, o.httpMethod, o.parameters, o.summary, o.notes, o.responseClass, errorResponses, this, o.consumes, o.produces);
op = new SwaggerOperation(o.nickname, resource_path, method, o.parameters, o.summary, o.notes, o.responseClass, responseMessages, this, consumes, produces);
this.operations[op.nickname] = op;
_results.push(this.operationsArray.push(op));
}
@@ -298,18 +283,20 @@
};
SwaggerResource.prototype.help = function() {
var operation, operation_name, parameter, _i, _len, _ref, _ref1;
var msg, operation, operation_name, parameter, _i, _len, _ref, _ref1, _results;
_ref = this.operations;
_results = [];
for (operation_name in _ref) {
operation = _ref[operation_name];
console.log(" " + operation.nickname);
msg = " " + operation.nickname;
_ref1 = operation.parameters;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
parameter = _ref1[_i];
console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
msg.concat(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
}
_results.push(msg);
}
return this;
return _results;
};
return SwaggerResource;
@@ -456,17 +443,17 @@
SwaggerOperation = (function() {
function SwaggerOperation(nickname, path, httpMethod, parameters, summary, notes, responseClass, errorResponses, resource, consumes, produces) {
function SwaggerOperation(nickname, path, method, parameters, summary, notes, responseClass, responseMessages, resource, consumes, produces) {
var parameter, v, _i, _j, _len, _len1, _ref, _ref1, _ref2,
_this = this;
this.nickname = nickname;
this.path = path;
this.httpMethod = httpMethod;
this.method = method;
this.parameters = parameters != null ? parameters : [];
this.summary = summary;
this.notes = notes;
this.responseClass = responseClass;
this.errorResponses = errorResponses;
this.responseMessages = responseMessages;
this.resource = resource;
this.consumes = consumes;
this.produces = produces;
@@ -478,12 +465,12 @@
if (this.path == null) {
this.resource.api.fail("SwaggerOperation " + nickname + " is missing path.");
}
if (this.httpMethod == null) {
this.resource.api.fail("SwaggerOperation " + nickname + " is missing httpMethod.");
if (this.method == null) {
this.resource.api.fail("SwaggerOperation " + nickname + " is missing method.");
}
this.path = this.path.replace('{format}', 'json');
this.httpMethod = this.httpMethod.toLowerCase();
this.isGetMethod = this.httpMethod === "get";
this.method = this.method.toLowerCase();
this.isGetMethod = this.method === "get";
this.resourceName = this.resource.name;
if (((_ref = this.responseClass) != null ? _ref.toLowerCase() : void 0) === 'void') {
this.responseClass = void 0;
@@ -492,7 +479,7 @@
this.responseClassSignature = this.getSignature(this.responseClass, this.resource.models);
this.responseSampleJSON = this.getSampleJSON(this.responseClass, this.resource.models);
}
this.errorResponses = this.errorResponses || [];
this.responseMessages = this.responseMessages || [];
_ref1 = this.parameters;
for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
parameter = _ref1[_i];
@@ -569,10 +556,12 @@
};
SwaggerOperation.prototype["do"] = function(args, callback, error) {
var body, headers;
var key, param, params, possibleParams, requestContentType, responseContentType, value;
if (args == null) {
args = {};
}
requestContentType = null;
responseContentType = null;
if ((typeof args) === "function") {
error = callback;
callback = args;
@@ -585,18 +574,49 @@
}
if (callback == null) {
callback = function(data) {
return console.log(data);
return console.log("default callback: " + data);
};
}
params = {};
if (args.requestContentType) {
requestContentType = args.requestContentType;
}
if (args.responseContentType) {
responseContentType = args.responseContentType;
}
if (args.headers != null) {
headers = args.headers;
params.headers = args.headers;
delete args.headers;
}
if (args.body != null) {
body = args.body;
params.body = args.body;
delete args.body;
}
return new SwaggerRequest(this.httpMethod, this.urlify(args), headers, body, callback, error, this);
possibleParams = (function() {
var _i, _len, _ref, _results;
_ref = this.parameters;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
param = _ref[_i];
if (param.paramType === "form") {
_results.push(param);
}
}
return _results;
}).call(this);
if (possibleParams) {
for (key in possibleParams) {
value = possibleParams[key];
if (args[value.name]) {
params[value.name] = args[value.name];
}
}
}
if (args.mock != null) {
params.mock = args["mock"];
}
params["parent"] = args["parent"];
return new SwaggerRequest(this.method, this.urlify(args), params, requestContentType, responseContentType, callback, error, this);
};
SwaggerOperation.prototype.pathJson = function() {
@@ -607,11 +627,8 @@
return this.path.replace("{format}", "xml");
};
SwaggerOperation.prototype.urlify = function(args, includeApiKey) {
var param, queryParams, reg, url, _i, _len, _ref;
if (includeApiKey == null) {
includeApiKey = true;
}
SwaggerOperation.prototype.urlify = function(args) {
var param, queryParams, reg, url, _i, _j, _len, _len1, _ref, _ref1;
url = this.resource.basePath + this.pathJson();
_ref = this.parameters;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
@@ -626,13 +643,18 @@
}
}
}
if (includeApiKey && (this.resource.api.api_key != null) && this.resource.api.api_key.length > 0) {
args[this.apiKeyName] = this.resource.api.api_key;
}
if (this.supportHeaderParams()) {
queryParams = jQuery.param(this.getQueryParams(args, includeApiKey));
} else {
queryParams = jQuery.param(this.getQueryAndHeaderParams(args, includeApiKey));
queryParams = "";
_ref1 = this.parameters;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
param = _ref1[_j];
if (param.paramType === 'query') {
if (args[param.name]) {
if (queryParams !== "") {
queryParams += "&";
}
queryParams += encodeURIComponent(param.name) + '=' + encodeURIComponent(args[param.name]);
}
}
}
if ((queryParams != null) && queryParams.length > 0) {
url += "?" + queryParams;
@@ -648,58 +670,44 @@
return this.resource.api.supportedSubmitMethods;
};
SwaggerOperation.prototype.getQueryAndHeaderParams = function(args, includeApiKey) {
if (includeApiKey == null) {
includeApiKey = true;
}
return this.getMatchingParams(['query', 'header'], args, includeApiKey);
SwaggerOperation.prototype.getQueryParams = function(args) {
return this.getMatchingParams(['query'], args);
};
SwaggerOperation.prototype.getQueryParams = function(args, includeApiKey) {
if (includeApiKey == null) {
includeApiKey = true;
}
return this.getMatchingParams(['query'], args, includeApiKey);
SwaggerOperation.prototype.getHeaderParams = function(args) {
return this.getMatchingParams(['header'], args);
};
SwaggerOperation.prototype.getHeaderParams = function(args, includeApiKey) {
if (includeApiKey == null) {
includeApiKey = true;
}
return this.getMatchingParams(['header'], args, includeApiKey);
};
SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args, includeApiKey) {
SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args) {
var matchingParams, name, param, value, _i, _len, _ref, _ref1;
matchingParams = {};
_ref = this.parameters;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
param = _ref[_i];
if ((jQuery.inArray(param.paramType, paramTypes) >= 0) && args[param.name]) {
if (args && args[param.name]) {
matchingParams[param.name] = args[param.name];
}
}
if (includeApiKey && (this.resource.api.api_key != null) && this.resource.api.api_key.length > 0) {
matchingParams[this.resource.api.apiKeyName] = this.resource.api.api_key;
}
if (jQuery.inArray('header', paramTypes) >= 0) {
_ref1 = this.resource.api.headers;
for (name in _ref1) {
value = _ref1[name];
matchingParams[name] = value;
}
_ref1 = this.resource.api.headers;
for (name in _ref1) {
value = _ref1[name];
matchingParams[name] = value;
}
return matchingParams;
};
SwaggerOperation.prototype.help = function() {
var parameter, _i, _len, _ref;
var msg, parameter, _i, _len, _ref;
msg = "";
_ref = this.parameters;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
parameter = _ref[_i];
console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
if (msg !== "") {
msg += "\n";
}
msg += "* " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description;
}
return this;
return msg;
};
return SwaggerOperation;
@@ -708,16 +716,18 @@
SwaggerRequest = (function() {
function SwaggerRequest(type, url, headers, body, successCallback, errorCallback, operation) {
var obj,
function SwaggerRequest(type, url, params, requestContentType, responseContentType, successCallback, errorCallback, operation, execution) {
var body, e, fields, headers, key, myHeaders, obj, param, parent, possibleParams, urlEncoded, value, values,
_this = this;
this.type = type;
this.url = url;
this.headers = headers;
this.body = body;
this.params = params;
this.requestContentType = requestContentType;
this.responseContentType = responseContentType;
this.successCallback = successCallback;
this.errorCallback = errorCallback;
this.operation = operation;
this.execution = execution;
if (this.type == null) {
throw "SwaggerRequest type is required (get/post/put/delete).";
}
@@ -733,30 +743,133 @@
if (this.operation == null) {
throw "SwaggerRequest operation is required.";
}
if (this.operation.resource.api.verbose) {
console.log(this.asCurl());
this.type = this.type.toUpperCase();
headers = params.headers;
myHeaders = {};
body = params.body;
parent = params["parent"];
requestContentType = "application/json";
if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH")) {
if (this.requestContentType) {
requestContentType = this.requestContentType;
}
} else {
if (((function() {
var _i, _len, _ref, _results;
_ref = this.operation.parameters;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
param = _ref[_i];
if (param.paramType === "form") {
_results.push(param);
}
}
return _results;
}).call(this)).length > 0) {
requestContentType = "application/x-www-form-urlencoded";
} else if (this.type !== "DELETE") {
requestContentType = null;
}
}
this.headers || (this.headers = {});
if (this.operation.resource.api.api_key != null) {
this.headers[this.apiKeyName] = this.operation.resource.api.api_key;
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.requestContentType === null) {
requestContentType = this.operation.consumes[0];
}
} else {
console.log("it's ok to send " + requestContentType);
}
}
if (this.headers.mock == null) {
responseContentType = null;
if (this.type === "POST" || this.type === "GET") {
if (this.responseContentType) {
responseContentType = this.responseContentType;
} else {
responseContentType = "application/json";
}
} else {
responseContentType = null;
}
if (responseContentType && this.operation.produces) {
if (this.operation.produces.indexOf(responseContentType) === -1) {
console.log("server can't produce " + responseContentType);
} else {
console.log("get ready for " + responseContentType);
}
}
if (requestContentType && requestContentType.indexOf("application/x-www-form-urlencoded") === 0) {
console.log("pulling fields");
fields = {};
possibleParams = (function() {
var _i, _len, _ref, _results;
_ref = this.operation.parameters;
_results = [];
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
param = _ref[_i];
if (param.paramType === "form") {
_results.push(param);
}
}
return _results;
}).call(this);
console.log(possibleParams);
values = {};
for (key in possibleParams) {
value = possibleParams[key];
if (this.params[value.name]) {
values[value.name] = this.params[value.name];
}
}
urlEncoded = "";
for (key in values) {
value = values[key];
if (urlEncoded !== "") {
urlEncoded += "&";
}
urlEncoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
}
body = urlEncoded;
}
if (requestContentType) {
myHeaders["Content-Type"] = requestContentType;
}
if (responseContentType) {
myHeaders["Accept"] = responseContentType;
}
if (!((headers != null) && (headers.mock != null))) {
obj = {
type: this.type,
url: this.url,
data: JSON.stringify(this.body),
dataType: 'json',
error: function(xhr, textStatus, error) {
return _this.errorCallback(xhr, textStatus, error);
},
success: function(data) {
return _this.successCallback(data);
method: this.type,
headers: myHeaders,
body: body,
on: {
error: function(response) {
return _this.errorCallback(response, _this.params["parent"]);
},
redirect: function(response) {
return _this.successCallback(response, _this.params["parent"]);
},
307: function(response) {
return _this.successCallback(response, _this.params["parent"]);
},
response: function(response) {
return _this.successCallback(response, _this.params["parent"]);
}
}
};
if (obj.type.toLowerCase() === "post" || obj.type.toLowerCase() === "put") {
obj.contentType = "application/json";
e = {};
if (typeof window !== 'undefined') {
e = window;
} else {
e = exports;
}
e.authorizations.apply(obj);
if (params.mock == null) {
new SwaggerHttp().execute(obj);
} else {
return obj;
}
jQuery.ajax(obj);
}
}
@@ -779,14 +892,115 @@
})();
window.SwaggerApi = SwaggerApi;
SwaggerHttp = (function() {
window.SwaggerResource = SwaggerResource;
SwaggerHttp.prototype.shred = null;
window.SwaggerOperation = SwaggerOperation;
function SwaggerHttp() {
var Shred;
Shred = null;
if (typeof window !== 'undefined') {
Shred = require("./shred");
} else {
Shred = require("shred");
}
this.shred = new Shred();
}
window.SwaggerRequest = SwaggerRequest;
SwaggerHttp.prototype.execute = function(obj) {
var Content, identity, toString,
_this = this;
Content = require("./shred/content");
identity = function(x) {
return x;
};
toString = function(x) {
return x.toString;
};
Content.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
parser: identity,
stringify: toString
});
return this.shred.request(obj);
};
window.SwaggerModelProperty = SwaggerModelProperty;
return SwaggerHttp;
})();
SwaggerAuthorizations = (function() {
SwaggerAuthorizations.prototype.authz = null;
function SwaggerAuthorizations() {
this.authz = {};
}
SwaggerAuthorizations.prototype.add = function(name, auth) {
this.authz[name] = auth;
return auth;
};
SwaggerAuthorizations.prototype.apply = function(obj) {
var key, value, _ref, _results;
_ref = this.authz;
_results = [];
for (key in _ref) {
value = _ref[key];
_results.push(value.apply(obj));
}
return _results;
};
return SwaggerAuthorizations;
})();
ApiKeyAuthorization = (function() {
ApiKeyAuthorization.prototype.type = null;
ApiKeyAuthorization.prototype.name = null;
ApiKeyAuthorization.prototype.value = null;
function ApiKeyAuthorization(name, value, type) {
this.name = name;
this.value = value;
this.type = type;
}
ApiKeyAuthorization.prototype.apply = function(obj) {
if (this.type === "query") {
if (obj.url.indexOf('?') > 0) {
obj.url = obj.url + "&" + this.name + "=" + this.value;
} else {
obj.url = obj.url + "?" + this.name + "=" + this.value;
}
return true;
} else if (this.type === "header") {
return obj.headers[this.name] = this.value;
}
};
return ApiKeyAuthorization;
})();
this.SwaggerApi = SwaggerApi;
this.SwaggerResource = SwaggerResource;
this.SwaggerOperation = SwaggerOperation;
this.SwaggerRequest = SwaggerRequest;
this.SwaggerModelProperty = SwaggerModelProperty;
this.SwaggerAuthorizations = new SwaggerAuthorizations();
this.ApiKeyAuthorization = ApiKeyAuthorization;
this.authorizations = new SwaggerAuthorizations();
}).call(this);

438
dist/swagger-ui.js vendored
View File

@@ -191,7 +191,7 @@ templates['content_type'] = template(function (Handlebars,depth0,helpers,partial
function program1(depth0,data) {
var buffer = "", stack1, stack2;
buffer += "\n ";
buffer += "\n ";
foundHelper = helpers.produces;
stack1 = foundHelper || depth0.produces;
stack2 = helpers.each;
@@ -222,7 +222,7 @@ function program2(depth0,data) {
function program4(depth0,data) {
return "\n <option value=\"application/json\">application/json</option>\n";}
return "\n <option value=\"application/json\">application/json</option>\n";}
buffer += "<label for=\"contentType\"></label>\n<select name=\"contentType\">\n";
foundHelper = helpers.produces;
@@ -295,12 +295,12 @@ function program1(depth0,data) {
function program3(depth0,data) {
return "\n <h4>Response Class</h4>\n <p><span class=\"model-signature\" /></p>\n <br/>\n <div class=\"content-type\" />\n ";}
return "\n <h4>Response Class</h4>\n <p><span class=\"model-signature\" /></p>\n <br/>\n <div class=\"response-content-type\" />\n ";}
function program5(depth0,data) {
return "\n <h4>Parameters</h4>\n <table class='fullwidth'>\n <thead>\n <tr>\n <th style=\"width: 100px; max-width: 100px\">Parameter</th>\n <th style=\"width: 310px; max-width: 310px\">Value</th>\n <th style=\"width: 200px; max-width: 200px\">Description</th>\n <th style=\"width: 100px; max-width: 100px\">Parameter Type</th>\n <th style=\"width: 220px; max-width: 230px\">Data Type</th>\n </tr>\n </thead>\n <tbody class=\"operation-params\">\n\n </tbody>\n </table>\n ";}
return "\n <h4>Parameters</h4>\n <table class='fullwidth'>\n <thead>\n <tr>\n <th style=\"width: 100px; max-width: 100px\">Parameter</th>\n <th style=\"width: 310px; max-width: 310px\">Value</th>\n <th style=\"width: 200px; max-width: 200px\">Description</th>\n <th style=\"width: 100px; max-width: 100px\">Parameter Type</th>\n <th style=\"width: 220px; max-width: 230px\">Data Type</th>\n </tr>\n </thead>\n <tbody class=\"operation-params\">\n\n </tbody>\n </table>\n ";}
function program7(depth0,data) {
@@ -318,10 +318,10 @@ function program11(depth0,data) {
return "\n <div class='sandbox_header'>\n <input class='submit' name='commit' type='button' value='Try it out!' />\n <a href='#' class='response_hider' style='display:none'>Hide Response</a>\n <img alt='Throbber' class='response_throbber' src='images/throbber.gif' style='display:none' />\n </div>\n ";}
buffer += "\n <ul class='operations' >\n <li class='";
foundHelper = helpers.httpMethod;
stack1 = foundHelper || depth0.httpMethod;
foundHelper = helpers.method;
stack1 = foundHelper || depth0.method;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "httpMethod", { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "method", { hash: {} }); }
buffer += escapeExpression(stack1) + " operation' id='";
foundHelper = helpers.resourceName;
stack1 = foundHelper || depth0.resourceName;
@@ -333,10 +333,10 @@ function program11(depth0,data) {
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "nickname", { hash: {} }); }
buffer += escapeExpression(stack1) + "_";
foundHelper = helpers.httpMethod;
stack1 = foundHelper || depth0.httpMethod;
foundHelper = helpers.method;
stack1 = foundHelper || depth0.method;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "httpMethod", { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "method", { hash: {} }); }
buffer += escapeExpression(stack1) + "_";
foundHelper = helpers.number;
stack1 = foundHelper || depth0.number;
@@ -353,20 +353,20 @@ function program11(depth0,data) {
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "nickname", { hash: {} }); }
buffer += escapeExpression(stack1) + "_";
foundHelper = helpers.httpMethod;
stack1 = foundHelper || depth0.httpMethod;
foundHelper = helpers.method;
stack1 = foundHelper || depth0.method;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "httpMethod", { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "method", { hash: {} }); }
buffer += escapeExpression(stack1) + "_";
foundHelper = helpers.number;
stack1 = foundHelper || depth0.number;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "number", { hash: {} }); }
buffer += escapeExpression(stack1) + "' class=\"toggleOperation\">";
foundHelper = helpers.httpMethod;
stack1 = foundHelper || depth0.httpMethod;
foundHelper = helpers.method;
stack1 = foundHelper || depth0.method;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "httpMethod", { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "method", { hash: {} }); }
buffer += escapeExpression(stack1) + "</a>\n </span>\n <span class='path'>\n <a href='#!/";
foundHelper = helpers.resourceName;
stack1 = foundHelper || depth0.resourceName;
@@ -378,10 +378,10 @@ function program11(depth0,data) {
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "nickname", { hash: {} }); }
buffer += escapeExpression(stack1) + "_";
foundHelper = helpers.httpMethod;
stack1 = foundHelper || depth0.httpMethod;
foundHelper = helpers.method;
stack1 = foundHelper || depth0.method;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "httpMethod", { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "method", { hash: {} }); }
buffer += escapeExpression(stack1) + "_";
foundHelper = helpers.number;
stack1 = foundHelper || depth0.number;
@@ -403,10 +403,10 @@ function program11(depth0,data) {
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "nickname", { hash: {} }); }
buffer += escapeExpression(stack1) + "_";
foundHelper = helpers.httpMethod;
stack1 = foundHelper || depth0.httpMethod;
foundHelper = helpers.method;
stack1 = foundHelper || depth0.method;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "httpMethod", { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "method", { hash: {} }); }
buffer += escapeExpression(stack1) + "_";
foundHelper = helpers.number;
stack1 = foundHelper || depth0.number;
@@ -429,10 +429,10 @@ function program11(depth0,data) {
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "nickname", { hash: {} }); }
buffer += escapeExpression(stack1) + "_";
foundHelper = helpers.httpMethod;
stack1 = foundHelper || depth0.httpMethod;
foundHelper = helpers.method;
stack1 = foundHelper || depth0.method;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "httpMethod", { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "method", { hash: {} }); }
buffer += escapeExpression(stack1) + "_";
foundHelper = helpers.number;
stack1 = foundHelper || depth0.number;
@@ -458,7 +458,7 @@ function program11(depth0,data) {
tmp1.inverse = self.noop;
stack1 = stack2.call(depth0, stack1, tmp1);
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n <form accept-charset='UTF-8' class='sandbox'>\n <div style='margin:0;padding:0;display:inline'></div>\n ";
buffer += "\n <form accept-charset='UTF-8' class='sandbox'>\n <div style='margin:0;padding:0;display:inline'></div>\n ";
foundHelper = helpers.parameters;
stack1 = foundHelper || depth0.parameters;
stack2 = helpers['if'];
@@ -563,7 +563,7 @@ function program7(depth0,data) {
stack1 = foundHelper || depth0.name;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "name", { hash: {} }); }
buffer += escapeExpression(stack1) + "'></textarea>\n <br />\n <div class=\"content-type\" />\n ";
buffer += escapeExpression(stack1) + "'></textarea>\n <br />\n <div class=\"parameter-content-type\" />\n ";
return buffer;}
function program9(depth0,data) {
@@ -635,7 +635,7 @@ function program12(depth0,data) {
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "paramType", { hash: {} }); }
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "</td>\n<td>\n <span class=\"model-signature\"></span>\n</td>\n\n";
buffer += "</td>\n<td>\n <span class=\"model-signature\"></span>\n</td>\n";
return buffer;});
})();
@@ -1008,7 +1008,7 @@ function program7(depth0,data) {
stack1 = foundHelper || depth0.name;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "name", { hash: {} }); }
buffer += escapeExpression(stack1) + "'></textarea>\n <br />\n <div class=\"content-type\" />\n ";
buffer += escapeExpression(stack1) + "'></textarea>\n <br />\n <div class=\"parameter-content-type\" />\n ";
return buffer;}
function program9(depth0,data) {
@@ -1110,6 +1110,62 @@ function program15(depth0,data) {
return buffer;});
})();
(function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['parameter_content_type'] = template(function (Handlebars,depth0,helpers,partials,data) {
helpers = helpers || Handlebars.helpers;
var buffer = "", stack1, stack2, foundHelper, tmp1, self=this, functionType="function", helperMissing=helpers.helperMissing, undef=void 0;
function program1(depth0,data) {
var buffer = "", stack1, stack2;
buffer += "\n ";
foundHelper = helpers.consumes;
stack1 = foundHelper || depth0.consumes;
stack2 = helpers.each;
tmp1 = self.program(2, program2, data);
tmp1.hash = {};
tmp1.fn = tmp1;
tmp1.inverse = self.noop;
stack1 = stack2.call(depth0, stack1, tmp1);
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n";
return buffer;}
function program2(depth0,data) {
var buffer = "", stack1;
buffer += "\n <option value=\"";
stack1 = depth0;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "this", { hash: {} }); }
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\">";
stack1 = depth0;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "this", { hash: {} }); }
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "</option>\n ";
return buffer;}
function program4(depth0,data) {
return "\n <option value=\"application/json\">application/json</option>\n";}
buffer += "<label for=\"parameterContentType\"></label>\n<select name=\"parameterContentType\">\n";
foundHelper = helpers.consumes;
stack1 = foundHelper || depth0.consumes;
stack2 = helpers['if'];
tmp1 = self.program(1, program1, data);
tmp1.hash = {};
tmp1.fn = tmp1;
tmp1.inverse = self.program(4, program4, data);
stack1 = stack2.call(depth0, stack1, tmp1);
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n</select>\n";
return buffer;});
})();
(function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['resource'] = template(function (Handlebars,depth0,helpers,partials,data) {
@@ -1117,7 +1173,7 @@ templates['resource'] = template(function (Handlebars,depth0,helpers,partials,da
var buffer = "", stack1, foundHelper, self=this, functionType="function", helperMissing=helpers.helperMissing, undef=void 0, escapeExpression=this.escapeExpression;
buffer += "<div class='heading'>\n <h2>\n <a href='#!/";
buffer += "<div class='heading'>\n <h2>\n <a href='#!/";
foundHelper = helpers.name;
stack1 = foundHelper || depth0.name;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
@@ -1132,7 +1188,7 @@ templates['resource'] = template(function (Handlebars,depth0,helpers,partials,da
stack1 = foundHelper || depth0.name;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "name", { hash: {} }); }
buffer += escapeExpression(stack1) + "</a>\n </h2>\n <ul class='options'>\n <li>\n <a href='#!/";
buffer += escapeExpression(stack1) + "</a>\n </h2>\n <ul class='options'>\n <li>\n <a href='#!/";
foundHelper = helpers.name;
stack1 = foundHelper || depth0.name;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
@@ -1142,27 +1198,27 @@ templates['resource'] = template(function (Handlebars,depth0,helpers,partials,da
stack1 = foundHelper || depth0.name;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "name", { hash: {} }); }
buffer += escapeExpression(stack1) + "'\n onclick=\"Docs.toggleEndpointListForResource('";
buffer += escapeExpression(stack1) + "'\n onclick=\"Docs.toggleEndpointListForResource('";
foundHelper = helpers.name;
stack1 = foundHelper || depth0.name;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "name", { hash: {} }); }
buffer += escapeExpression(stack1) + "');\">Show/Hide</a>\n </li>\n <li>\n <a href='#' onclick=\"Docs.collapseOperationsForResource('";
buffer += escapeExpression(stack1) + "');\">Show/Hide</a>\n </li>\n <li>\n <a href='#' onclick=\"Docs.collapseOperationsForResource('";
foundHelper = helpers.name;
stack1 = foundHelper || depth0.name;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "name", { hash: {} }); }
buffer += escapeExpression(stack1) + "'); return false;\">\n List Operations\n </a>\n </li>\n <li>\n <a href='#' onclick=\"Docs.expandOperationsForResource('";
buffer += escapeExpression(stack1) + "'); return false;\">\n List Operations\n </a>\n </li>\n <li>\n <a href='#' onclick=\"Docs.expandOperationsForResource('";
foundHelper = helpers.name;
stack1 = foundHelper || depth0.name;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "name", { hash: {} }); }
buffer += escapeExpression(stack1) + "'); return false;\">\n Expand Operations\n </a>\n </li>\n <li>\n <a href='";
buffer += escapeExpression(stack1) + "'); return false;\">\n Expand Operations\n </a>\n </li>\n <li>\n <a href='";
foundHelper = helpers.url;
stack1 = foundHelper || depth0.url;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "url", { hash: {} }); }
buffer += escapeExpression(stack1) + "'>Raw</a>\n </li>\n </ul>\n</div>\n<ul class='endpoints' id='";
buffer += escapeExpression(stack1) + "'>Raw</a>\n </li>\n </ul>\n</div>\n<ul class='endpoints' id='";
foundHelper = helpers.name;
stack1 = foundHelper || depth0.name;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
@@ -1171,6 +1227,62 @@ templates['resource'] = template(function (Handlebars,depth0,helpers,partials,da
return buffer;});
})();
(function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['response_content_type'] = template(function (Handlebars,depth0,helpers,partials,data) {
helpers = helpers || Handlebars.helpers;
var buffer = "", stack1, stack2, foundHelper, tmp1, self=this, functionType="function", helperMissing=helpers.helperMissing, undef=void 0;
function program1(depth0,data) {
var buffer = "", stack1, stack2;
buffer += "\n ";
foundHelper = helpers.produces;
stack1 = foundHelper || depth0.produces;
stack2 = helpers.each;
tmp1 = self.program(2, program2, data);
tmp1.hash = {};
tmp1.fn = tmp1;
tmp1.inverse = self.noop;
stack1 = stack2.call(depth0, stack1, tmp1);
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n";
return buffer;}
function program2(depth0,data) {
var buffer = "", stack1;
buffer += "\n <option value=\"";
stack1 = depth0;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "this", { hash: {} }); }
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\">";
stack1 = depth0;
if(typeof stack1 === functionType) { stack1 = stack1.call(depth0, { hash: {} }); }
else if(stack1=== undef) { stack1 = helperMissing.call(depth0, "this", { hash: {} }); }
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "</option>\n ";
return buffer;}
function program4(depth0,data) {
return "\n <option value=\"application/json\">application/json</option>\n";}
buffer += "<label for=\"responseContentType\"></label>\n<select name=\"responseContentType\">\n";
foundHelper = helpers.produces;
stack1 = foundHelper || depth0.produces;
stack2 = helpers['if'];
tmp1 = self.program(1, program1, data);
tmp1.hash = {};
tmp1.fn = tmp1;
tmp1.inverse = self.program(4, program4, data);
stack1 = stack2.call(depth0, stack1, tmp1);
if(stack1 || stack1 === 0) { buffer += stack1; }
buffer += "\n</select>\n";
return buffer;});
})();
(function() {
var template = Handlebars.template, templates = Handlebars.templates = Handlebars.templates || {};
templates['signature'] = template(function (Handlebars,depth0,helpers,partials,data) {
@@ -1219,7 +1331,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
// Generated by CoffeeScript 1.4.0
(function() {
var ContentTypeView, HeaderView, MainView, OperationView, ParameterView, ResourceView, SignatureView, StatusCodeView, SwaggerUi,
var ContentTypeView, HeaderView, MainView, OperationView, ParameterContentTypeView, ParameterView, ResourceView, ResponseContentTypeView, SignatureView, StatusCodeView, SwaggerUi,
__hasProp = {}.hasOwnProperty,
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
@@ -1500,8 +1612,8 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
OperationView.prototype.initialize = function() {};
OperationView.prototype.render = function() {
var contentTypeModel, contentTypeView, isMethodSubmissionSupported, param, responseSignatureView, signatureModel, statusCode, _i, _j, _len, _len1, _ref, _ref1;
isMethodSubmissionSupported = jQuery.inArray(this.model.httpMethod, this.model.supportedSubmitMethods()) >= 0;
var contentTypeModel, isMethodSubmissionSupported, param, responseContentTypeView, responseSignatureView, signatureModel, statusCode, _i, _j, _len, _len1, _ref, _ref1;
isMethodSubmissionSupported = true;
if (!isMethodSubmissionSupported) {
this.model.isReadOnly = true;
}
@@ -1523,22 +1635,18 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
contentTypeModel = {
isParam: false
};
if (this.model.supportedContentTypes) {
contentTypeModel.produces = this.model.supportedContentTypes;
}
if (this.model.produces) {
contentTypeModel.produces = this.model.produces;
}
contentTypeView = new ContentTypeView({
contentTypeModel.consumes = this.model.consumes;
contentTypeModel.produces = this.model.produces;
responseContentTypeView = new ResponseContentTypeView({
model: contentTypeModel
});
$('.content-type', $(this.el)).append(contentTypeView.render().el);
$('.response-content-type', $(this.el)).append(responseContentTypeView.render().el);
_ref = this.model.parameters;
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
param = _ref[_i];
this.addParameter(param);
this.addParameter(param, contentTypeModel.consumes);
}
_ref1 = this.model.errorResponses;
_ref1 = this.model.responseMessages;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
statusCode = _ref1[_j];
this.addStatusCode(statusCode);
@@ -1546,8 +1654,9 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
return this;
};
OperationView.prototype.addParameter = function(param) {
OperationView.prototype.addParameter = function(param, consumes) {
var paramView;
param.consumes = consumes;
paramView = new ParameterView({
model: param,
tagName: 'tr',
@@ -1566,8 +1675,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
};
OperationView.prototype.submitOperation = function(e) {
var bodyParam, consumes, error_free, form, headerParams, invocationUrl, isFileUpload, isFormPost, map, o, obj, param, paramContentTypeField, responseContentTypeField, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4,
_this = this;
var error_free, form, map, o, _i, _len, _ref;
if (e != null) {
e.preventDefault();
}
@@ -1587,7 +1695,9 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
}
});
if (error_free) {
map = {};
map = {
parent: this
};
_ref = form.serializeArray();
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
o = _ref[_i];
@@ -1595,101 +1705,17 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
map[o.name] = o.value;
}
}
isFileUpload = form.children().find('input[type~="file"]').size() !== 0;
isFormPost = false;
consumes = "application/json";
if (this.model.consumes && this.model.consumes.length > 0) {
consumes = this.model.consumes[0];
} else {
_ref1 = this.model.parameters;
for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
o = _ref1[_j];
if (o.paramType === 'form') {
isFormPost = true;
consumes = false;
}
}
if (isFileUpload) {
consumes = false;
} else if (this.model.httpMethod.toLowerCase() === "post" && isFormPost === false) {
consumes = "application/json";
}
}
if (isFileUpload) {
bodyParam = new FormData();
_ref2 = this.model.parameters;
for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
param = _ref2[_k];
if ((param.paramType === 'body' || 'form') && param.name !== 'file' && param.name !== 'File' && (map[param.name] != null)) {
bodyParam.append(param.name, map[param.name]);
}
}
$.each(form.children().find('input[type~="file"]'), function(i, el) {
return bodyParam.append($(el).attr('name'), el.files[0]);
});
console.log(bodyParam);
} else if (isFormPost) {
bodyParam = new FormData();
_ref3 = this.model.parameters;
for (_l = 0, _len3 = _ref3.length; _l < _len3; _l++) {
param = _ref3[_l];
if (map[param.name] != null) {
bodyParam.append(param.name, map[param.name]);
}
}
} else {
bodyParam = null;
_ref4 = this.model.parameters;
for (_m = 0, _len4 = _ref4.length; _m < _len4; _m++) {
param = _ref4[_m];
if (param.paramType === 'body') {
bodyParam = map[param.name];
}
}
}
log("bodyParam = " + bodyParam);
headerParams = null;
invocationUrl = this.model.supportHeaderParams() ? (headerParams = this.model.getHeaderParams(map), this.model.urlify(map, false)) : this.model.urlify(map, true);
log('submitting ' + invocationUrl);
$(".request_url", $(this.el)).html("<pre>" + invocationUrl + "</pre>");
$(".response_throbber", $(this.el)).show();
obj = {
type: this.model.httpMethod,
url: invocationUrl,
headers: headerParams,
data: bodyParam,
contentType: consumes,
dataType: 'json',
processData: false,
error: function(xhr, textStatus, error) {
return _this.showErrorStatus(xhr, textStatus, error);
},
success: function(data) {
return _this.showResponse(data);
},
complete: function(data) {
return _this.showCompleteStatus(data);
}
};
paramContentTypeField = $("td select[name=contentType]", $(this.el)).val();
if (paramContentTypeField) {
obj.contentType = paramContentTypeField;
}
log('content type = ' + obj.contentType);
if (!(obj.data || (obj.type === 'GET' || obj.type === 'DELETE')) && obj.contentType === !"application/x-www-form-urlencoded") {
obj.contentType = false;
}
log('content type is now = ' + obj.contentType);
responseContentTypeField = $('.content > .content-type > div > select[name=contentType]', $(this.el)).val();
if (responseContentTypeField) {
obj.headers = obj.headers != null ? obj.headers : {};
obj.headers.accept = responseContentTypeField;
}
jQuery.ajax(obj);
return false;
console.log(map);
map["responseContentType"] = $("div select[name=responseContentType]", $(this.el)).val();
map["requestContentType"] = $("div select[name=parameterContentType]", $(this.el)).val();
return this.model["do"](map, this.showCompleteStatus, this.showErrorStatus, this);
}
};
OperationView.prototype.success = function(response, parent) {
return parent.showCompleteStatus(response);
};
OperationView.prototype.hideResponse = function(e) {
if (e != null) {
e.preventDefault();
@@ -1704,12 +1730,12 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
return $(".response_body", $(this.el)).html(escape(prettyJson));
};
OperationView.prototype.showErrorStatus = function(data) {
return this.showStatus(data);
OperationView.prototype.showErrorStatus = function(data, parent) {
return parent.showStatus(data);
};
OperationView.prototype.showCompleteStatus = function(data) {
return this.showStatus(data);
OperationView.prototype.showCompleteStatus = function(data, parent) {
return parent.showStatus(data);
};
OperationView.prototype.formatXml = function(xml) {
@@ -1786,18 +1812,31 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
};
OperationView.prototype.showStatus = function(data) {
var code, pre, response_body;
try {
code = $('<code />').text(JSON.stringify(JSON.parse(data.responseText), null, 2));
var code, content, contentType, headers, pre, response_body;
content = data.content.data;
headers = data.getHeaders();
contentType = headers["Content-Type"];
if (content === void 0) {
code = $('<code />').text("no content");
pre = $('<pre class="json" />').append(code);
} catch (error) {
code = $('<code />').text(this.formatXml(data.responseText));
} else if (contentType.indexOf("application/json") === 0) {
code = $('<code />').text(JSON.stringify(JSON.parse(content), null, 2));
pre = $('<pre class="json" />').append(code);
} else if (contentType.indexOf("application/xml") === 0) {
code = $('<code />').text(this.formatXml(content));
pre = $('<pre class="xml" />').append(code);
} else if (contentType.indexOf("text/html") === 0) {
code = $('<code />').html(content);
pre = $('<pre class="xml" />').append(code);
} 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>");
$(".response_body", $(this.el)).html(response_body);
$(".response_headers", $(this.el)).html("<pre>" + data.getAllResponseHeaders() + "</pre>");
$(".response_headers", $(this.el)).html("<pre>" + JSON.stringify(data.getHeaders()) + "</pre>");
$(".response", $(this.el)).slideDown();
$(".response_hider", $(this.el)).show();
$(".response_throbber", $(this.el)).hide();
@@ -1806,7 +1845,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
OperationView.prototype.toggleOperationContent = function() {
var elem;
elem = $('#' + Docs.escapeResourceName(this.model.resourceName) + "_" + this.model.nickname + "_" + this.model.httpMethod + "_" + this.model.number + "_content");
elem = $('#' + Docs.escapeResourceName(this.model.resourceName) + "_" + this.model.nickname + "_" + this.model.method + "_" + this.model.number + "_content");
if (elem.is(':visible')) {
return Docs.collapseOperation(elem);
} else {
@@ -1854,7 +1893,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
ParameterView.prototype.initialize = function() {};
ParameterView.prototype.render = function() {
var contentTypeModel, contentTypeView, signatureModel, signatureView, template;
var contentTypeModel, isParam, parameterContentTypeView, responseContentTypeView, signatureModel, signatureView, template;
if (this.model.paramType === 'body') {
this.model.isBody = true;
}
@@ -1877,19 +1916,25 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
} else {
$('.model-signature', $(this.el)).html(this.model.signature);
}
isParam = false;
if (this.model.isBody) {
isParam = true;
}
contentTypeModel = {
isParam: false
isParam: isParam
};
if (this.model.supportedContentTypes) {
contentTypeModel.produces = this.model.supportedContentTypes;
contentTypeModel.consumes = this.model.consumes;
if (isParam) {
parameterContentTypeView = new ParameterContentTypeView({
model: contentTypeModel
});
$('.parameter-content-type', $(this.el)).append(parameterContentTypeView.render().el);
} else {
responseContentTypeView = new ResponseContentTypeView({
model: contentTypeModel
});
$('.response-content-type', $(this.el)).append(responseContentTypeView.render().el);
}
if (this.model.produces) {
contentTypeModel.produces = this.model.produces;
}
contentTypeView = new ContentTypeView({
model: contentTypeModel
});
$('.content-type', $(this.el)).append(contentTypeView.render().el);
return this;
};
@@ -2000,12 +2045,7 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
var template;
template = this.template();
$(this.el).html(template(this.model));
this.isParam = this.model.isParam;
if (this.isParam) {
$('label[for=contentType]', $(this.el)).text('Parameter content type:');
} else {
$('label[for=contentType]', $(this.el)).text('Response Content Type');
}
$('label[for=contentType]', $(this.el)).text('Response Content Type');
return this;
};
@@ -2017,4 +2057,56 @@ templates['status_code'] = template(function (Handlebars,depth0,helpers,partials
})(Backbone.View);
ResponseContentTypeView = (function(_super) {
__extends(ResponseContentTypeView, _super);
function ResponseContentTypeView() {
return ResponseContentTypeView.__super__.constructor.apply(this, arguments);
}
ResponseContentTypeView.prototype.initialize = function() {};
ResponseContentTypeView.prototype.render = function() {
var template;
template = this.template();
$(this.el).html(template(this.model));
$('label[for=responseContentType]', $(this.el)).text('Response Content Type');
return this;
};
ResponseContentTypeView.prototype.template = function() {
return Handlebars.templates.response_content_type;
};
return ResponseContentTypeView;
})(Backbone.View);
ParameterContentTypeView = (function(_super) {
__extends(ParameterContentTypeView, _super);
function ParameterContentTypeView() {
return ParameterContentTypeView.__super__.constructor.apply(this, arguments);
}
ParameterContentTypeView.prototype.initialize = function() {};
ParameterContentTypeView.prototype.render = function() {
var template;
template = this.template();
$(this.el).html(template(this.model));
$('label[for=parameterContentType]', $(this.el)).text('Parameter content type:');
return this;
};
ParameterContentTypeView.prototype.template = function() {
return Handlebars.templates.parameter_content_type;
};
return ParameterContentTypeView;
})(Backbone.View);
}).call(this);

File diff suppressed because one or more lines are too long

View File

@@ -5,12 +5,7 @@ class ContentTypeView extends Backbone.View
template = @template()
$(@el).html(template(@model))
@isParam = @model.isParam
if @isParam
$('label[for=contentType]', $(@el)).text('Parameter content type:')
else
$('label[for=contentType]', $(@el)).text('Response Content Type')
$('label[for=contentType]', $(@el)).text('Response Content Type')
@

View File

@@ -9,7 +9,7 @@ class OperationView extends Backbone.View
initialize: ->
render: ->
isMethodSubmissionSupported = jQuery.inArray(@model.httpMethod, @model.supportedSubmitMethods()) >= 0
isMethodSubmissionSupported = true #jQuery.inArray(@model.method, @model.supportedSubmitMethods) >= 0
@model.isReadOnly = true unless isMethodSubmissionSupported
$(@el).html(Handlebars.templates.operation(@model))
@@ -28,26 +28,23 @@ class OperationView extends Backbone.View
contentTypeModel =
isParam: false
# support old syntax
if @model.supportedContentTypes
contentTypeModel.produces = @model.supportedContentTypes
contentTypeModel.consumes = @model.consumes
contentTypeModel.produces = @model.produces
if @model.produces
contentTypeModel.produces = @model.produces
contentTypeView = new ContentTypeView({model: contentTypeModel})
$('.content-type', $(@el)).append contentTypeView.render().el
responseContentTypeView = new ResponseContentTypeView({model: contentTypeModel})
$('.response-content-type', $(@el)).append responseContentTypeView.render().el
# Render each parameter
@addParameter param for param in @model.parameters
@addParameter param, contentTypeModel.consumes for param in @model.parameters
# Render each response code
@addStatusCode statusCode for statusCode in @model.errorResponses
@addStatusCode statusCode for statusCode in @model.responseMessages
@
addParameter: (param) ->
addParameter: (param, consumes) ->
# Render a parameter
param.consumes = consumes
paramView = new ParameterView({model: param, tagName: 'tr', readOnly: @model.isReadOnly})
$('.operation-params', $(@el)).append paramView.render().el
@@ -71,104 +68,21 @@ class OperationView extends Backbone.View
# if error free submit it
if error_free
map = {}
map = {parent: @}
for o in form.serializeArray()
if(o.value? && jQuery.trim(o.value).length > 0)
map[o.name] = o.value
isFileUpload = form.children().find('input[type~="file"]').size() != 0
console.log map
isFormPost = false
consumes = "application/json"
if @model.consumes and @model.consumes.length > 0
# honor the consumes setting above everything else
consumes = @model.consumes[0]
else
for o in @model.parameters
if o.paramType == 'form'
isFormPost = true
consumes = false
map["responseContentType"] = $("div select[name=responseContentType]", $(@el)).val()
map["requestContentType"] = $("div select[name=parameterContentType]", $(@el)).val()
if isFileUpload
consumes = false
else if @model.httpMethod.toLowerCase() == "post" and isFormPost is false
consumes = "application/json"
@model.do(map, @showCompleteStatus, @showErrorStatus, @)
if isFileUpload
# requires HTML5 compatible browser
bodyParam = new FormData()
success: (response, parent) ->
parent.showCompleteStatus response
# add params except file
for param in @model.parameters
if (param.paramType is 'body' or 'form') and param.name isnt 'file' and param.name isnt 'File' and map[param.name]?
bodyParam.append(param.name, map[param.name])
# add files
$.each form.children().find('input[type~="file"]'), (i, el) ->
bodyParam.append($(el).attr('name'), el.files[0])
console.log(bodyParam)
else if isFormPost
bodyParam = new FormData()
for param in @model.parameters
if map[param.name]?
bodyParam.append(param.name, map[param.name])
else
bodyParam = null
for param in @model.parameters
if param.paramType is 'body'
bodyParam = map[param.name]
log "bodyParam = " + bodyParam
headerParams = null
invocationUrl =
if @model.supportHeaderParams()
headerParams = @model.getHeaderParams(map)
@model.urlify(map, false)
else
@model.urlify(map, true)
log 'submitting ' + invocationUrl
$(".request_url", $(@el)).html "<pre>" + invocationUrl + "</pre>"
$(".response_throbber", $(@el)).show()
obj =
type: @model.httpMethod
url: invocationUrl
headers: headerParams
data: bodyParam
contentType: consumes
dataType: 'json'
processData: false
error: (xhr, textStatus, error) =>
@showErrorStatus(xhr, textStatus, error)
success: (data) =>
@showResponse(data)
complete: (data) =>
@showCompleteStatus(data)
paramContentTypeField = $("td select[name=contentType]", $(@el)).val()
if paramContentTypeField
obj.contentType = paramContentTypeField
log 'content type = ' + obj.contentType
if not (obj.data or (obj.type is 'GET' or obj.type is 'DELETE')) and obj.contentType is not "application/x-www-form-urlencoded"
obj.contentType = false
log 'content type is now = ' + obj.contentType
responseContentTypeField = $('.content > .content-type > div > select[name=contentType]', $(@el)).val()
if responseContentTypeField
obj.headers = if obj.headers? then obj.headers else {}
obj.headers.accept = responseContentTypeField
jQuery.ajax(obj)
false
# $.getJSON(invocationUrl, (r) => @showResponse(r)).complete((r) => @showCompleteStatus(r)).error (r) => @showErrorStatus(r)
# handler for hide response link
hideResponse: (e) ->
@@ -182,14 +96,13 @@ class OperationView extends Backbone.View
prettyJson = JSON.stringify(response, null, "\t").replace(/\n/g, "<br>")
$(".response_body", $(@el)).html escape(prettyJson)
# Show error from server
showErrorStatus: (data) ->
@showStatus data
showErrorStatus: (data, parent) ->
parent.showStatus data
# show the status codes
showCompleteStatus: (data) ->
@showStatus data
showCompleteStatus: (data, parent) ->
parent.showStatus data
# Adapted from http://stackoverflow.com/a/2893259/454004
formatXml: (xml) ->
@@ -252,21 +165,39 @@ class OperationView extends Backbone.View
# puts the response data in UI
showStatus: (data) ->
try
code = $('<code />').text(JSON.stringify(JSON.parse(data.responseText), null, 2))
content = data.content.data
headers = data.getHeaders()
# if server is nice, and sends content-type back, we can use it
contentType = headers["Content-Type"]
if content == undefined
code = $('<code />').text("no content")
pre = $('<pre class="json" />').append(code)
catch error
code = $('<code />').text(@formatXml(data.responseText))
else if contentType.indexOf("application/json") == 0
code = $('<code />').text(JSON.stringify(JSON.parse(content), null, 2))
pre = $('<pre class="json" />').append(code)
else if contentType.indexOf("application/xml") == 0
code = $('<code />').text(@formatXml(content))
pre = $('<pre class="xml" />').append(code)
else if contentType.indexOf("text/html") == 0
code = $('<code />').html(content)
pre = $('<pre class="xml" />').append(code)
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>"
$(".response_body", $(@el)).html response_body
$(".response_headers", $(@el)).html "<pre>" + data.getAllResponseHeaders() + "</pre>"
$(".response_headers", $(@el)).html "<pre>" + JSON.stringify(data.getHeaders()) + "</pre>"
$(".response", $(@el)).slideDown()
$(".response_hider", $(@el)).show()
$(".response_throbber", $(@el)).hide()
hljs.highlightBlock($('.response_body', $(@el))[0])
toggleOperationContent: ->
elem = $('#' + Docs.escapeResourceName(@model.resourceName) + "_" + @model.nickname + "_" + @model.httpMethod + "_" + @model.number + "_content")
elem = $('#' + Docs.escapeResourceName(@model.resourceName) + "_" + @model.nickname + "_" + @model.method + "_" + @model.number + "_content")
if elem.is(':visible') then Docs.collapseOperation(elem) else Docs.expandOperation(elem)

View File

@@ -19,18 +19,23 @@ class ParameterView extends Backbone.View
else
$('.model-signature', $(@el)).html(@model.signature)
isParam = false
if @model.isBody
isParam = true
contentTypeModel =
isParam: false
isParam: isParam
# support old syntax
if @model.supportedContentTypes
contentTypeModel.produces = @model.supportedContentTypes
contentTypeModel.consumes = @model.consumes
if @model.produces
contentTypeModel.produces = @model.produces
if isParam
parameterContentTypeView = new ParameterContentTypeView({model: contentTypeModel})
$('.parameter-content-type', $(@el)).append parameterContentTypeView.render().el
contentTypeView = new ContentTypeView({model: contentTypeModel})
$('.content-type', $(@el)).append contentTypeView.render().el
else
responseContentTypeView = new ResponseContentTypeView({model: contentTypeModel})
$('.response-content-type', $(@el)).append responseContentTypeView.render().el
@

View File

@@ -1,74 +1,80 @@
<!DOCTYPE html>
<html>
<head>
<title>Swagger UI</title>
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
<link href='css/hightlight.default.css' media='screen' rel='stylesheet' type='text/css'/>
<link href='css/screen.css' media='screen' rel='stylesheet' type='text/css'/>
<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>
<script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
<script src='lib/handlebars-1.0.rc.1.js' type='text/javascript'></script>
<script src='lib/underscore-min.js' type='text/javascript'></script>
<script src='lib/backbone-min.js' type='text/javascript'></script>
<script src='lib/swagger.js' type='text/javascript'></script>
<script src='swagger-ui.js' type='text/javascript'></script>
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
<title>Swagger UI</title>
<link href='//fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'/>
<link href='css/hightlight.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 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>
<script src='lib/jquery.ba-bbq.min.js' type='text/javascript'></script>
<script src='lib/handlebars-1.0.rc.1.js' type='text/javascript'></script>
<script src='lib/underscore-min.js' type='text/javascript'></script>
<script src='lib/backbone-min.js' type='text/javascript'></script>
<script src='lib/swagger.js' type='text/javascript'></script>
<script src='swagger-ui.js' type='text/javascript'></script>
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
<script src='lib/highlight.7.3.pack.js' type='text/javascript'></script>
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
discoveryUrl:"http://localhost:8002/api/api-docs",
dom_id:"swagger-ui-container",
supportHeaderParams: false,
supportedSubmitMethods: ['get', 'post', 'put', 'delete'],
onComplete: function(swaggerApi, swaggerUi){
if(console) {
console.log("Loaded SwaggerUI")
console.log(swaggerApi);
console.log(swaggerUi);
}
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
},
onFailure: function(data) {
if(console) {
console.log("Unable to Load SwaggerUI");
console.log(data);
}
},
docExpansion: "none"
});
<script type="text/javascript">
$(function () {
window.swaggerUi = new SwaggerUi({
discoveryUrl:"http://petstore.swagger.wordnik.com/api/api-docs.json",
apiKey:"special-key",
dom_id:"swagger-ui-container",
supportHeaderParams: false,
supportedSubmitMethods: ['get', 'post', 'put'],
onComplete: function(swaggerApi, swaggerUi){
if(console) {
console.log("Loaded SwaggerUI")
console.log(swaggerApi);
console.log(swaggerUi);
}
$('pre code').each(function(i, e) {hljs.highlightBlock(e)});
},
onFailure: function(data) {
if(console) {
console.log("Unable to Load SwaggerUI");
console.log(data);
}
},
docExpansion: "none"
});
$('#input_apiKey').change(function() {
var key = $('#input_apiKey')[0].value;
console.log("key: " + key);
if(key && key.trim() != "") {
window.authorizations.add("key", new ApiKeyAuthorization("api_key", key, "query"));
}
})
window.swaggerUi.load();
});
window.swaggerUi.load();
});
</script>
</script>
</head>
<body>
<div id='header'>
<div class="swagger-ui-wrap">
<a id="logo" href="http://swagger.wordnik.com">swagger</a>
<div class="swagger-ui-wrap">
<a id="logo" href="http://swagger.wordnik.com">swagger</a>
<form id='api_selector'>
<div class='input icon-btn'>
<img id="show-pet-store-icon" src="images/pet_store_api.png" title="Show Swagger Petstore Example Apis">
</div>
<div class='input icon-btn'>
<img id="show-wordnik-dev-icon" src="images/wordnik_api.png" title="Show Wordnik Developer Apis">
</div>
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl"
type="text"/></div>
<div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
<div class='input'><a id="explore" href="#">Explore</a></div>
</form>
</div>
<form id='api_selector'>
<div class='input icon-btn'>
<img id="show-pet-store-icon" src="images/pet_store_api.png" title="Show Swagger Petstore Example Apis">
</div>
<div class='input icon-btn'>
<img id="show-wordnik-dev-icon" src="images/wordnik_api.png" title="Show Wordnik Developer Apis">
</div>
<div class='input'><input placeholder="http://example.com/api" id="input_baseUrl" name="baseUrl" type="text"/></div>
<div class='input'><input placeholder="api_key" id="input_apiKey" name="apiKey" type="text"/></div>
<div class='input'><a id="explore" href="#">Explore</a></div>
</form>
</div>
</div>
<div id="message-bar" class="swagger-ui-wrap">
&nbsp;
&nbsp;
</div>
<div id="swagger-ui-container" class="swagger-ui-wrap">

View File

@@ -1,10 +1,10 @@
<label for="contentType"></label>
<select name="contentType">
{{#if produces}}
{{#each produces}}
{{#each produces}}
<option value="{{{this}}}">{{{this}}}</option>
{{/each}}
{{else}}
<option value="application/json">application/json</option>
<option value="application/json">application/json</option>
{{/if}}
</select>

View File

@@ -1,49 +1,49 @@
<ul class='operations' >
<li class='{{httpMethod}} operation' id='{{resourceName}}_{{nickname}}_{{httpMethod}}_{{number}}'>
<li class='{{method}} operation' id='{{resourceName}}_{{nickname}}_{{method}}_{{number}}'>
<div class='heading'>
<h3>
<span class='http_method'>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}_{{number}}' class="toggleOperation">{{httpMethod}}</a>
<a href='#!/{{resourceName}}/{{nickname}}_{{method}}_{{number}}' class="toggleOperation">{{method}}</a>
</span>
<span class='path'>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}_{{number}}' class="toggleOperation">{{path}}</a>
<a href='#!/{{resourceName}}/{{nickname}}_{{method}}_{{number}}' class="toggleOperation">{{path}}</a>
</span>
</h3>
<ul class='options'>
<li>
<a href='#!/{{resourceName}}/{{nickname}}_{{httpMethod}}_{{number}}' class="toggleOperation">{{{summary}}}</a>
<a href='#!/{{resourceName}}/{{nickname}}_{{method}}_{{number}}' class="toggleOperation">{{{summary}}}</a>
</li>
</ul>
</div>
<div class='content' id='{{resourceName}}_{{nickname}}_{{httpMethod}}_{{number}}_content' style='display:none'>
<div class='content' id='{{resourceName}}_{{nickname}}_{{method}}_{{number}}_content' style='display:none'>
{{#if notes}}
<h4>Implementation Notes</h4>
<p>{{{notes}}}</p>
{{/if}}
{{#if responseClass}}
<h4>Response Class</h4>
<p><span class="model-signature" /></p>
<br/>
<div class="content-type" />
<h4>Response Class</h4>
<p><span class="model-signature" /></p>
<br/>
<div class="response-content-type" />
{{/if}}
<form accept-charset='UTF-8' class='sandbox'>
<div style='margin:0;padding:0;display:inline'></div>
{{#if parameters}}
<h4>Parameters</h4>
<table class='fullwidth'>
<thead>
<tr>
<th style="width: 100px; max-width: 100px">Parameter</th>
<th style="width: 310px; max-width: 310px">Value</th>
<th style="width: 200px; max-width: 200px">Description</th>
<th style="width: 100px; max-width: 100px">Parameter Type</th>
<th style="width: 220px; max-width: 230px">Data Type</th>
</tr>
</thead>
<tbody class="operation-params">
<div style='margin:0;padding:0;display:inline'></div>
{{#if parameters}}
<h4>Parameters</h4>
<table class='fullwidth'>
<thead>
<tr>
<th style="width: 100px; max-width: 100px">Parameter</th>
<th style="width: 310px; max-width: 310px">Value</th>
<th style="width: 200px; max-width: 200px">Description</th>
<th style="width: 100px; max-width: 100px">Parameter Type</th>
<th style="width: 220px; max-width: 230px">Data Type</th>
</tr>
</thead>
<tbody class="operation-params">
</tbody>
</tbody>
</table>
{{/if}}
{{#if errorResponses}}

View File

@@ -10,7 +10,7 @@
{{else}}
<textarea class='body-textarea' name='{{name}}'></textarea>
<br />
<div class="content-type" />
<div class="parameter-content-type" />
{{/if}}
{{/if}}
{{else}}
@@ -27,4 +27,3 @@
<td>
<span class="model-signature"></span>
</td>

View File

@@ -9,7 +9,7 @@
{{else}}
<textarea class='body-textarea' placeholder='(required)' name='{{name}}'></textarea>
<br />
<div class="content-type" />
<div class="parameter-content-type" />
{{/if}}
{{/if}}
{{else}}

View File

@@ -1,26 +1,26 @@
<div class='heading'>
<h2>
<a href='#!/{{name}}' onclick="Docs.toggleEndpointListForResource('{{name}}');">/{{name}}</a>
</h2>
<ul class='options'>
<li>
<a href='#!/{{name}}' id='endpointListTogger_{{name}}'
onclick="Docs.toggleEndpointListForResource('{{name}}');">Show/Hide</a>
</li>
<li>
<a href='#' onclick="Docs.collapseOperationsForResource('{{name}}'); return false;">
List Operations
</a>
</li>
<li>
<a href='#' onclick="Docs.expandOperationsForResource('{{name}}'); return false;">
Expand Operations
</a>
</li>
<li>
<a href='{{url}}'>Raw</a>
</li>
</ul>
<h2>
<a href='#!/{{name}}' onclick="Docs.toggleEndpointListForResource('{{name}}');">/{{name}}</a>
</h2>
<ul class='options'>
<li>
<a href='#!/{{name}}' id='endpointListTogger_{{name}}'
onclick="Docs.toggleEndpointListForResource('{{name}}');">Show/Hide</a>
</li>
<li>
<a href='#' onclick="Docs.collapseOperationsForResource('{{name}}'); return false;">
List Operations
</a>
</li>
<li>
<a href='#' onclick="Docs.expandOperationsForResource('{{name}}'); return false;">
Expand Operations
</a>
</li>
<li>
<a href='{{url}}'>Raw</a>
</li>
</ul>
</div>
<ul class='endpoints' id='{{name}}_endpoint_list' style='display:none'>