updated client

This commit is contained in:
Tony Tam
2015-02-19 21:50:56 -08:00
parent 7596ab0c9c
commit fb30579387
5 changed files with 213 additions and 139 deletions

View File

@@ -1,6 +1,6 @@
/**
* swagger-client - swagger.js is a javascript client for use with swaggering APIs.
* @version v2.1.5-M1
* @version v2.1.6-M1
* @link http://swagger.io
* @license apache 2.0
*/
@@ -502,6 +502,8 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
for(i = 0; i < tags.length; i++) {
var tag = this.tagFromLabel(tags[i]);
var operationGroup = this[tag];
if(typeof this.apis[tag] === 'undefined')
this.apis[tag] = {};
if(typeof operationGroup === 'undefined') {
this[tag] = [];
operationGroup = this[tag];
@@ -516,8 +518,16 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
this[tag].help = this.help.bind(operationGroup);
this.apisArray.push(new OperationGroup(tag, operationGroup.description, operationGroup.externalDocs, operationObject));
}
if(typeof this.apis[tag].help !== 'function')
this.apis[tag].help = this.help.bind(operationGroup);
// bind to the apis object
this.apis[tag][operationId] = operationObject.execute.bind(operationObject);
this.apis[tag][operationId].help = operationObject.help.bind(operationObject);
this.apis[tag][operationId].asCurl = operationObject.asCurl.bind(operationObject);
operationGroup[operationId] = operationObject.execute.bind(operationObject);
operationGroup[operationId].help = operationObject.help.bind(operationObject);
operationGroup[operationId].asCurl = operationObject.asCurl.bind(operationObject);
operationGroup.apis.push(operationObject);
operationGroup.operations[operationId] = operationObject;
@@ -560,12 +570,18 @@ SwaggerClient.prototype.parseUri = function(uri) {
};
};
SwaggerClient.prototype.help = function() {
SwaggerClient.prototype.help = function(dontPrint) {
var i;
log('operations for the "' + this.label + '" tag');
var output = 'operations for the "' + this.label + '" tag';
for(i = 0; i < this.apis.length; i++) {
var api = this.apis[i];
log(' * ' + api.nickname + ': ' + api.operation.summary);
output += '\n * ' + api.nickname + ': ' + api.operation.summary;
}
if(dontPrint)
return output;
else {
log(output);
return output;
}
};
@@ -1610,6 +1626,7 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
res = new SwaggerResource(response, this);
this.apis[newName] = res;
this.apisArray.push(res);
this.finish();
} else {
var k;
this.expectedResourceCount = response.apis.length;
@@ -1665,7 +1682,9 @@ SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
res = new SwaggerResource(response, this);
this.apis[newName] = res;
this.apisArray.push(res);
this.finish();
} else {
this.expectedResourceCount = response.apis.length;
for (k = 0; k < response.apis.length; k++) {
resource = response.apis[k];
res = new SwaggerResource(resource, this);
@@ -1674,9 +1693,6 @@ SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
}
}
this.isValid = true;
if (this.success) {
this.success();
}
return this;
};
@@ -1698,16 +1714,18 @@ SwaggerClient.prototype.convertInfo = function (resp) {
};
SwaggerClient.prototype.selfReflect = function () {
var resource, resource_name, ref;
var resource, tag, ref;
if (this.apis === null) {
return false;
}
ref = this.apis;
for (resource_name in ref) {
resource = ref[resource_name];
if (resource.ready === null) {
for (tag in ref) {
api = ref[tag];
if (api.ready === null) {
return false;
}
this[tag] = api;
this[tag].help = __bind(api.help, api);
}
this.setConsolidatedModels();
this.ready = true;
@@ -1743,7 +1761,6 @@ var SwaggerResource = function (resourceObj, api) {
this.description = resourceObj.description;
this.authorizations = (resourceObj.authorizations || {});
var parts = this.path.split('/');
this.name = parts[parts.length - 1].replace('.{format}', '');
this.basePath = this.api.basePath;
@@ -1792,6 +1809,21 @@ var SwaggerResource = function (resourceObj, api) {
}
};
SwaggerResource.prototype.help = function (dontPrint) {
var i;
var output = 'operations for the "' + this.name + '" tag';
for(i = 0; i < this.operationsArray.length; i++) {
var api = this.operationsArray[i];
output += '\n * ' + api.nickname + ': ' + api.description;
}
if(dontPrint)
return output;
else {
log(output);
return output;
}
};
SwaggerResource.prototype.getAbsoluteBasePath = function (relativeBasePath) {
var pos, url;
url = this.api.basePath;
@@ -2108,6 +2140,7 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
this.deprecated = deprecated;
this['do'] = __bind(this['do'], this);
if(typeof this.deprecated === 'string') {
switch(this.deprecated.toLowerCase()) {
case 'true': case 'yes': case '1': {
@@ -2225,8 +2258,8 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
return _this['do'](arg1 || {}, arg2 || {}, arg3 || defaultSuccessCallback, arg4 || defaultErrorCallback);
};
this.resource[this.nickname].help = function () {
return _this.help();
this.resource[this.nickname].help = function (dontPrint) {
return _this.help(dontPrint);
};
this.resource[this.nickname].asCurl = function (args) {
return _this.asCurl(args);
@@ -2465,16 +2498,19 @@ SwaggerOperation.prototype.getMatchingParams = function (paramTypes, args) {
return matchingParams;
};
SwaggerOperation.prototype.help = function () {
var msg = '';
SwaggerOperation.prototype.help = function (dontPrint) {
var msg = this.nickname + ': ' + this.summary;
var params = this.parameters;
for (var i = 0; i < params.length; i++) {
var param = params[i];
if (msg !== '')
msg += '\n';
msg += '* ' + param.name + (param.required ? ' (required)' : '') + " - " + param.description;
msg += '\n* ' + param.name + (param.required ? ' (required)' : '') + " - " + param.description;
}
if(dontPrint)
return msg;
else {
console.log(msg);
return msg;
}
return msg;
};
SwaggerOperation.prototype.asCurl = function (args) {
@@ -2851,6 +2887,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
url: request.url,
method: request.method,
status: response.status,
statusText: response.statusText,
data: response.responseText,
headers: headers
};

192
dist/swagger-ui.js vendored
View File

@@ -193,14 +193,6 @@ var Docs = {
}
};
this["Handlebars"] = this["Handlebars"] || {};
this["Handlebars"]["templates"] = this["Handlebars"]["templates"] || {};
this["Handlebars"]["templates"]["apikey_button_view"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
return "<!--div class='auth_button' id='apikey_button'><img class='auth_icon' alt='apply api key' src='images/apikey.jpeg'></div-->\n<div class='auth_container' id='apikey_container'>\n <div class='key_input_container'>\n <div class='auth_label'>"
+ escapeExpression(((helper = (helper = helpers.keyName || (depth0 != null ? depth0.keyName : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"keyName","hash":{},"data":data}) : helper)))
+ "</div>\n <input placeholder=\"api_key\" class=\"auth_input\" id=\"input_apiKey_entry\" name=\"apiKey\" type=\"text\"/>\n <div class='auth_submit'><a class='auth_submit_button' id=\"apply_api_key\" href=\"#\">apply</a></div>\n </div>\n</div>\n\n";
},"useData":true});
var SwaggerUi,
__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; },
__hasProp = {}.hasOwnProperty;
@@ -387,14 +379,22 @@ SwaggerUi = (function(_super) {
window.SwaggerUi = SwaggerUi;
this["Handlebars"]["templates"]["basic_auth_button_view"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
return "<div class='auth_button' id='basic_auth_button'><img class='auth_icon' src='images/password.jpeg'></div>\n<div class='auth_container' id='basic_auth_container'>\n <div class='key_input_container'>\n <div class=\"auth_label\">Username</div>\n <input placeholder=\"username\" class=\"auth_input\" id=\"input_username\" name=\"username\" type=\"text\"/>\n <div class=\"auth_label\">Password</div>\n <input placeholder=\"password\" class=\"auth_input\" id=\"input_password\" name=\"password\" type=\"password\"/>\n <div class='auth_submit'><a class='auth_submit_button' id=\"apply_basic_auth\" href=\"#\">apply</a></div>\n </div>\n</div>\n\n";
},"useData":true});
this["Handlebars"] = this["Handlebars"] || {};
this["Handlebars"]["templates"] = this["Handlebars"]["templates"] || {};
this["Handlebars"]["templates"]["apikey_button_view"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
return "<!--div class='auth_button' id='apikey_button'><img class='auth_icon' alt='apply api key' src='images/apikey.jpeg'></div-->\n<div class='auth_container' id='apikey_container'>\n <div class='key_input_container'>\n <div class='auth_label'>"
+ escapeExpression(((helper = (helper = helpers.keyName || (depth0 != null ? depth0.keyName : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"keyName","hash":{},"data":data}) : helper)))
+ "</div>\n <input placeholder=\"api_key\" class=\"auth_input\" id=\"input_apiKey_entry\" name=\"apiKey\" type=\"text\"/>\n <div class='auth_submit'><a class='auth_submit_button' id=\"apply_api_key\" href=\"#\">apply</a></div>\n </div>\n</div>\n\n";
},"useData":true});
Handlebars.registerHelper('sanitize', function(html) {
html = html.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '');
return new Handlebars.SafeString(html);
});
this["Handlebars"]["templates"]["basic_auth_button_view"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
return "<div class='auth_button' id='basic_auth_button'><img class='auth_icon' src='images/password.jpeg'></div>\n<div class='auth_container' id='basic_auth_container'>\n <div class='key_input_container'>\n <div class=\"auth_label\">Username</div>\n <input placeholder=\"username\" class=\"auth_input\" id=\"input_username\" name=\"username\" type=\"text\"/>\n <div class=\"auth_label\">Password</div>\n <input placeholder=\"password\" class=\"auth_input\" id=\"input_password\" name=\"password\" type=\"password\"/>\n <div class='auth_submit'><a class='auth_submit_button' id=\"apply_basic_auth\" href=\"#\">apply</a></div>\n </div>\n</div>\n\n";
},"useData":true});
this["Handlebars"]["templates"]["content_type"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1, buffer = "";
stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
@@ -1682,6 +1682,35 @@ OperationView = (function(_super) {
})(Backbone.View);
var ParameterContentTypeView,
__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; },
__hasProp = {}.hasOwnProperty;
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);
this["Handlebars"]["templates"]["param_readonly_required"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression;
return " <textarea class='body-textarea' readonly='readonly' placeholder='(required)' name='"
@@ -1715,35 +1744,6 @@ this["Handlebars"]["templates"]["param_readonly_required"] = Handlebars.template
if (stack1 != null) { buffer += stack1; }
return buffer + "</td>\n<td><span class=\"model-signature\"></span></td>\n";
},"useData":true});
var ParameterContentTypeView,
__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; },
__hasProp = {}.hasOwnProperty;
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);
this["Handlebars"]["templates"]["param_required"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1, buffer = "";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isFile : depth0), {"name":"if","hash":{},"fn":this.program(2, data),"inverse":this.program(4, data),"data":data});
@@ -2013,6 +2013,35 @@ ResourceView = (function(_super) {
})(Backbone.View);
var ResponseContentTypeView,
__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; },
__hasProp = {}.hasOwnProperty;
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);
this["Handlebars"]["templates"]["resource"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
return " : ";
},"3":function(depth0,helpers,partials,data) {
@@ -2051,56 +2080,6 @@ this["Handlebars"]["templates"]["resource"] = Handlebars.template({"1":function(
+ escapeExpression(((helper = (helper = helpers.id || (depth0 != null ? depth0.id : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"id","hash":{},"data":data}) : helper)))
+ "_endpoint_list' style='display:none'>\n\n</ul>\n";
},"useData":true});
var ResponseContentTypeView,
__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; },
__hasProp = {}.hasOwnProperty;
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);
this["Handlebars"]["templates"]["response_content_type"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1, buffer = "";
stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
if (stack1 != null) { buffer += stack1; }
return buffer;
},"2":function(depth0,helpers,partials,data) {
var stack1, lambda=this.lambda, buffer = " <option value=\"";
stack1 = lambda(depth0, depth0);
if (stack1 != null) { buffer += stack1; }
buffer += "\">";
stack1 = lambda(depth0, depth0);
if (stack1 != null) { buffer += stack1; }
return buffer + "</option>\n";
},"4":function(depth0,helpers,partials,data) {
return " <option value=\"application/json\">application/json</option>\n";
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, buffer = "<label for=\"responseContentType\"></label>\n<select name=\"responseContentType\">\n";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(4, data),"data":data});
if (stack1 != null) { buffer += stack1; }
return buffer + "</select>\n";
},"useData":true});
var SignatureView,
__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; },
__hasProp = {}.hasOwnProperty;
@@ -2173,13 +2152,26 @@ SignatureView = (function(_super) {
})(Backbone.View);
this["Handlebars"]["templates"]["signature"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<div>\n<ul class=\"signature-nav\">\n <li><a class=\"description-link\" href=\"#\">Model</a></li>\n <li><a class=\"snippet-link\" href=\"#\">Model Schema</a></li>\n</ul>\n<div>\n\n<div class=\"signature-container\">\n <div class=\"description\">\n ";
stack1 = ((helper = (helper = helpers.signature || (depth0 != null ? depth0.signature : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"signature","hash":{},"data":data}) : helper));
this["Handlebars"]["templates"]["response_content_type"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1, buffer = "";
stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data});
if (stack1 != null) { buffer += stack1; }
return buffer + "\n </div>\n\n <div class=\"snippet\">\n <pre><code>"
+ escapeExpression(((helper = (helper = helpers.sampleJSON || (depth0 != null ? depth0.sampleJSON : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"sampleJSON","hash":{},"data":data}) : helper)))
+ "</code></pre>\n <small class=\"notice\"></small>\n </div>\n</div>\n\n";
return buffer;
},"2":function(depth0,helpers,partials,data) {
var stack1, lambda=this.lambda, buffer = " <option value=\"";
stack1 = lambda(depth0, depth0);
if (stack1 != null) { buffer += stack1; }
buffer += "\">";
stack1 = lambda(depth0, depth0);
if (stack1 != null) { buffer += stack1; }
return buffer + "</option>\n";
},"4":function(depth0,helpers,partials,data) {
return " <option value=\"application/json\">application/json</option>\n";
},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, buffer = "<label for=\"responseContentType\"></label>\n<select name=\"responseContentType\">\n";
stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.produces : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(4, data),"data":data});
if (stack1 != null) { buffer += stack1; }
return buffer + "</select>\n";
},"useData":true});
var StatusCodeView,
__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; },
@@ -2223,6 +2215,14 @@ StatusCodeView = (function(_super) {
})(Backbone.View);
this["Handlebars"]["templates"]["signature"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<div>\n<ul class=\"signature-nav\">\n <li><a class=\"description-link\" href=\"#\">Model</a></li>\n <li><a class=\"snippet-link\" href=\"#\">Model Schema</a></li>\n</ul>\n<div>\n\n<div class=\"signature-container\">\n <div class=\"description\">\n ";
stack1 = ((helper = (helper = helpers.signature || (depth0 != null ? depth0.signature : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"signature","hash":{},"data":data}) : helper));
if (stack1 != null) { buffer += stack1; }
return buffer + "\n </div>\n\n <div class=\"snippet\">\n <pre><code>"
+ escapeExpression(((helper = (helper = helpers.sampleJSON || (depth0 != null ? depth0.sampleJSON : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"sampleJSON","hash":{},"data":data}) : helper)))
+ "</code></pre>\n <small class=\"notice\"></small>\n </div>\n</div>\n\n";
},"useData":true});
this["Handlebars"]["templates"]["status_code"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) {
var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "<td width='15%' class='code'>"
+ escapeExpression(((helper = (helper = helpers.code || (depth0 != null ? depth0.code : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"code","hash":{},"data":data}) : helper)))

File diff suppressed because one or more lines are too long

View File

@@ -1,6 +1,6 @@
/**
* swagger-client - swagger.js is a javascript client for use with swaggering APIs.
* @version v2.1.5-M1
* @version v2.1.6-M1
* @link http://swagger.io
* @license apache 2.0
*/
@@ -502,6 +502,8 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
for(i = 0; i < tags.length; i++) {
var tag = this.tagFromLabel(tags[i]);
var operationGroup = this[tag];
if(typeof this.apis[tag] === 'undefined')
this.apis[tag] = {};
if(typeof operationGroup === 'undefined') {
this[tag] = [];
operationGroup = this[tag];
@@ -516,8 +518,16 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
this[tag].help = this.help.bind(operationGroup);
this.apisArray.push(new OperationGroup(tag, operationGroup.description, operationGroup.externalDocs, operationObject));
}
if(typeof this.apis[tag].help !== 'function')
this.apis[tag].help = this.help.bind(operationGroup);
// bind to the apis object
this.apis[tag][operationId] = operationObject.execute.bind(operationObject);
this.apis[tag][operationId].help = operationObject.help.bind(operationObject);
this.apis[tag][operationId].asCurl = operationObject.asCurl.bind(operationObject);
operationGroup[operationId] = operationObject.execute.bind(operationObject);
operationGroup[operationId].help = operationObject.help.bind(operationObject);
operationGroup[operationId].asCurl = operationObject.asCurl.bind(operationObject);
operationGroup.apis.push(operationObject);
operationGroup.operations[operationId] = operationObject;
@@ -560,12 +570,18 @@ SwaggerClient.prototype.parseUri = function(uri) {
};
};
SwaggerClient.prototype.help = function() {
SwaggerClient.prototype.help = function(dontPrint) {
var i;
log('operations for the "' + this.label + '" tag');
var output = 'operations for the "' + this.label + '" tag';
for(i = 0; i < this.apis.length; i++) {
var api = this.apis[i];
log(' * ' + api.nickname + ': ' + api.operation.summary);
output += '\n * ' + api.nickname + ': ' + api.operation.summary;
}
if(dontPrint)
return output;
else {
log(output);
return output;
}
};
@@ -1610,6 +1626,7 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
res = new SwaggerResource(response, this);
this.apis[newName] = res;
this.apisArray.push(res);
this.finish();
} else {
var k;
this.expectedResourceCount = response.apis.length;
@@ -1665,7 +1682,9 @@ SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
res = new SwaggerResource(response, this);
this.apis[newName] = res;
this.apisArray.push(res);
this.finish();
} else {
this.expectedResourceCount = response.apis.length;
for (k = 0; k < response.apis.length; k++) {
resource = response.apis[k];
res = new SwaggerResource(resource, this);
@@ -1674,9 +1693,6 @@ SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
}
}
this.isValid = true;
if (this.success) {
this.success();
}
return this;
};
@@ -1698,16 +1714,18 @@ SwaggerClient.prototype.convertInfo = function (resp) {
};
SwaggerClient.prototype.selfReflect = function () {
var resource, resource_name, ref;
var resource, tag, ref;
if (this.apis === null) {
return false;
}
ref = this.apis;
for (resource_name in ref) {
resource = ref[resource_name];
if (resource.ready === null) {
for (tag in ref) {
api = ref[tag];
if (api.ready === null) {
return false;
}
this[tag] = api;
this[tag].help = __bind(api.help, api);
}
this.setConsolidatedModels();
this.ready = true;
@@ -1743,7 +1761,6 @@ var SwaggerResource = function (resourceObj, api) {
this.description = resourceObj.description;
this.authorizations = (resourceObj.authorizations || {});
var parts = this.path.split('/');
this.name = parts[parts.length - 1].replace('.{format}', '');
this.basePath = this.api.basePath;
@@ -1792,6 +1809,21 @@ var SwaggerResource = function (resourceObj, api) {
}
};
SwaggerResource.prototype.help = function (dontPrint) {
var i;
var output = 'operations for the "' + this.name + '" tag';
for(i = 0; i < this.operationsArray.length; i++) {
var api = this.operationsArray[i];
output += '\n * ' + api.nickname + ': ' + api.description;
}
if(dontPrint)
return output;
else {
log(output);
return output;
}
};
SwaggerResource.prototype.getAbsoluteBasePath = function (relativeBasePath) {
var pos, url;
url = this.api.basePath;
@@ -2108,6 +2140,7 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
this.deprecated = deprecated;
this['do'] = __bind(this['do'], this);
if(typeof this.deprecated === 'string') {
switch(this.deprecated.toLowerCase()) {
case 'true': case 'yes': case '1': {
@@ -2225,8 +2258,8 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
return _this['do'](arg1 || {}, arg2 || {}, arg3 || defaultSuccessCallback, arg4 || defaultErrorCallback);
};
this.resource[this.nickname].help = function () {
return _this.help();
this.resource[this.nickname].help = function (dontPrint) {
return _this.help(dontPrint);
};
this.resource[this.nickname].asCurl = function (args) {
return _this.asCurl(args);
@@ -2465,16 +2498,19 @@ SwaggerOperation.prototype.getMatchingParams = function (paramTypes, args) {
return matchingParams;
};
SwaggerOperation.prototype.help = function () {
var msg = '';
SwaggerOperation.prototype.help = function (dontPrint) {
var msg = this.nickname + ': ' + this.summary;
var params = this.parameters;
for (var i = 0; i < params.length; i++) {
var param = params[i];
if (msg !== '')
msg += '\n';
msg += '* ' + param.name + (param.required ? ' (required)' : '') + " - " + param.description;
msg += '\n* ' + param.name + (param.required ? ' (required)' : '') + " - " + param.description;
}
if(dontPrint)
return msg;
else {
console.log(msg);
return msg;
}
return msg;
};
SwaggerOperation.prototype.asCurl = function (args) {
@@ -2851,6 +2887,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
url: request.url,
method: request.method,
status: response.status,
statusText: response.statusText,
data: response.responseText,
headers: headers
};

View File

@@ -18,7 +18,7 @@
"dependencies": {
"shred": "0.8.10",
"btoa": "1.1.1",
"swagger-client": "2.1.5-M1"
"swagger-client": "2.1.6-M1"
},
"devDependencies": {
"chai": "^1.10.0",