merged from develop_2.0

This commit is contained in:
Tony Tam
2015-02-19 23:00:38 -08:00
7 changed files with 247 additions and 133 deletions

View File

@@ -1,6 +1,6 @@
/** /**
* swagger-client - swagger.js is a javascript client for use with swaggering APIs. * swagger-client - swagger.js is a javascript client for use with swaggering APIs.
* @version v2.1.5-M1 * @version v2.1.7-M1
* @link http://swagger.io * @link http://swagger.io
* @license apache 2.0 * @license apache 2.0
*/ */
@@ -502,6 +502,8 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
for(i = 0; i < tags.length; i++) { for(i = 0; i < tags.length; i++) {
var tag = this.tagFromLabel(tags[i]); var tag = this.tagFromLabel(tags[i]);
var operationGroup = this[tag]; var operationGroup = this[tag];
if(typeof this.apis[tag] === 'undefined')
this.apis[tag] = {};
if(typeof operationGroup === 'undefined') { if(typeof operationGroup === 'undefined') {
this[tag] = []; this[tag] = [];
operationGroup = this[tag]; operationGroup = this[tag];
@@ -516,8 +518,16 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
this[tag].help = this.help.bind(operationGroup); this[tag].help = this.help.bind(operationGroup);
this.apisArray.push(new OperationGroup(tag, operationGroup.description, operationGroup.externalDocs, operationObject)); 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] = operationObject.execute.bind(operationObject);
operationGroup[operationId].help = operationObject.help.bind(operationObject); operationGroup[operationId].help = operationObject.help.bind(operationObject);
operationGroup[operationId].asCurl = operationObject.asCurl.bind(operationObject);
operationGroup.apis.push(operationObject); operationGroup.apis.push(operationObject);
operationGroup.operations[operationId] = 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; 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++) { for(i = 0; i < this.apis.length; i++) {
var api = this.apis[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;
} }
}; };
@@ -1259,12 +1275,12 @@ var Model = function(name, definition) {
}; };
Model.prototype.createJSONSample = function(modelsToIgnore) { Model.prototype.createJSONSample = function(modelsToIgnore) {
var i, result = {}; var i, result = {}, representations = {};
modelsToIgnore = (modelsToIgnore||{}); modelsToIgnore = (modelsToIgnore||{});
modelsToIgnore[this.name] = this; modelsToIgnore[this.name] = this;
for (i = 0; i < this.properties.length; i++) { for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i]; prop = this.properties[i];
var sample = prop.getSampleValue(modelsToIgnore); var sample = prop.getSampleValue(modelsToIgnore, representations);
result[prop.name] = sample; result[prop.name] = sample;
} }
delete modelsToIgnore[this.name]; delete modelsToIgnore[this.name];
@@ -1272,10 +1288,10 @@ Model.prototype.createJSONSample = function(modelsToIgnore) {
}; };
Model.prototype.getSampleValue = function(modelsToIgnore) { Model.prototype.getSampleValue = function(modelsToIgnore) {
var i, obj = {}; var i, obj = {}, representations = {};
for(i = 0; i < this.properties.length; i++ ) { for(i = 0; i < this.properties.length; i++ ) {
var property = this.properties[i]; var property = this.properties[i];
obj[property.name] = property.sampleValue(false, modelsToIgnore); obj[property.name] = property.sampleValue(false, modelsToIgnore, representations);
} }
return obj; return obj;
}; };
@@ -1340,8 +1356,8 @@ var Property = function(name, obj, required) {
this.multipleOf = obj.multipleOf || null; this.multipleOf = obj.multipleOf || null;
}; };
Property.prototype.getSampleValue = function (modelsToIgnore) { Property.prototype.getSampleValue = function (modelsToIgnore, representations) {
return this.sampleValue(false, modelsToIgnore); return this.sampleValue(false, modelsToIgnore, representations);
}; };
Property.prototype.isArray = function () { Property.prototype.isArray = function () {
@@ -1352,21 +1368,29 @@ Property.prototype.isArray = function () {
return false; return false;
}; };
Property.prototype.sampleValue = function(isArray, ignoredModels) { Property.prototype.sampleValue = function(isArray, ignoredModels, representations) {
isArray = (isArray || this.isArray()); isArray = (isArray || this.isArray());
ignoredModels = (ignoredModels || {}); ignoredModels = (ignoredModels || {});
// representations = (representations || {});
var type = getStringSignature(this.obj, true); var type = getStringSignature(this.obj, true);
var output; var output;
if(this.$ref) { if(this.$ref) {
var refModelName = simpleRef(this.$ref); var refModelName = simpleRef(this.$ref);
var refModel = models[refModelName]; var refModel = models[refModelName];
if(typeof representations[type] !== 'undefined') {
return representations[type];
}
else
if(refModel && typeof ignoredModels[type] === 'undefined') { if(refModel && typeof ignoredModels[type] === 'undefined') {
ignoredModels[type] = this; ignoredModels[type] = this;
output = refModel.getSampleValue(ignoredModels); output = refModel.getSampleValue(ignoredModels, representations);
representations[type] = output;
} }
else { else {
output = refModelName; output = (representations[type] || refModelName);
} }
} }
else if(this.example) else if(this.example)
@@ -1610,6 +1634,7 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
res = new SwaggerResource(response, this); res = new SwaggerResource(response, this);
this.apis[newName] = res; this.apis[newName] = res;
this.apisArray.push(res); this.apisArray.push(res);
this.finish();
} else { } else {
var k; var k;
this.expectedResourceCount = response.apis.length; this.expectedResourceCount = response.apis.length;
@@ -1665,7 +1690,9 @@ SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
res = new SwaggerResource(response, this); res = new SwaggerResource(response, this);
this.apis[newName] = res; this.apis[newName] = res;
this.apisArray.push(res); this.apisArray.push(res);
this.finish();
} else { } else {
this.expectedResourceCount = response.apis.length;
for (k = 0; k < response.apis.length; k++) { for (k = 0; k < response.apis.length; k++) {
resource = response.apis[k]; resource = response.apis[k];
res = new SwaggerResource(resource, this); res = new SwaggerResource(resource, this);
@@ -1674,9 +1701,6 @@ SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
} }
} }
this.isValid = true; this.isValid = true;
if (this.success) {
this.success();
}
return this; return this;
}; };
@@ -1698,16 +1722,18 @@ SwaggerClient.prototype.convertInfo = function (resp) {
}; };
SwaggerClient.prototype.selfReflect = function () { SwaggerClient.prototype.selfReflect = function () {
var resource, resource_name, ref; var resource, tag, ref;
if (this.apis === null) { if (this.apis === null) {
return false; return false;
} }
ref = this.apis; ref = this.apis;
for (resource_name in ref) { for (tag in ref) {
resource = ref[resource_name]; api = ref[tag];
if (resource.ready === null) { if (api.ready === null) {
return false; return false;
} }
this[tag] = api;
this[tag].help = __bind(api.help, api);
} }
this.setConsolidatedModels(); this.setConsolidatedModels();
this.ready = true; this.ready = true;
@@ -1743,7 +1769,6 @@ var SwaggerResource = function (resourceObj, api) {
this.description = resourceObj.description; this.description = resourceObj.description;
this.authorizations = (resourceObj.authorizations || {}); this.authorizations = (resourceObj.authorizations || {});
var parts = this.path.split('/'); var parts = this.path.split('/');
this.name = parts[parts.length - 1].replace('.{format}', ''); this.name = parts[parts.length - 1].replace('.{format}', '');
this.basePath = this.api.basePath; this.basePath = this.api.basePath;
@@ -1792,6 +1817,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) { SwaggerResource.prototype.getAbsoluteBasePath = function (relativeBasePath) {
var pos, url; var pos, url;
url = this.api.basePath; url = this.api.basePath;
@@ -2108,6 +2148,7 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
this.deprecated = deprecated; this.deprecated = deprecated;
this['do'] = __bind(this['do'], this); this['do'] = __bind(this['do'], this);
if(typeof this.deprecated === 'string') { if(typeof this.deprecated === 'string') {
switch(this.deprecated.toLowerCase()) { switch(this.deprecated.toLowerCase()) {
case 'true': case 'yes': case '1': { case 'true': case 'yes': case '1': {
@@ -2225,8 +2266,8 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
return _this['do'](arg1 || {}, arg2 || {}, arg3 || defaultSuccessCallback, arg4 || defaultErrorCallback); return _this['do'](arg1 || {}, arg2 || {}, arg3 || defaultSuccessCallback, arg4 || defaultErrorCallback);
}; };
this.resource[this.nickname].help = function () { this.resource[this.nickname].help = function (dontPrint) {
return _this.help(); return _this.help(dontPrint);
}; };
this.resource[this.nickname].asCurl = function (args) { this.resource[this.nickname].asCurl = function (args) {
return _this.asCurl(args); return _this.asCurl(args);
@@ -2465,16 +2506,19 @@ SwaggerOperation.prototype.getMatchingParams = function (paramTypes, args) {
return matchingParams; return matchingParams;
}; };
SwaggerOperation.prototype.help = function () { SwaggerOperation.prototype.help = function (dontPrint) {
var msg = ''; var msg = this.nickname + ': ' + this.summary;
var params = this.parameters; var params = this.parameters;
for (var i = 0; i < params.length; i++) { for (var i = 0; i < params.length; i++) {
var param = params[i]; var param = params[i];
if (msg !== '') msg += '\n* ' + param.name + (param.required ? ' (required)' : '') + " - " + param.description;
msg += '\n';
msg += '* ' + param.name + (param.required ? ' (required)' : '') + " - " + param.description;
} }
if(dontPrint)
return msg; return msg;
else {
console.log(msg);
return msg;
}
}; };
SwaggerOperation.prototype.asCurl = function (args) { SwaggerOperation.prototype.asCurl = function (args) {
@@ -2851,6 +2895,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
url: request.url, url: request.url,
method: request.method, method: request.method,
status: response.status, status: response.status,
statusText: response.statusText,
data: response.responseText, data: response.responseText,
headers: headers headers: headers
}; };

138
dist/swagger-ui.js vendored
View File

@@ -1,9 +1,3 @@
/**
* swagger-ui - Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API
* @version v2.1.5-M1
* @link http://swagger.io
* @license Apache 2.0
*/
$(function() { $(function() {
// Helper function for vertically aligning DOM elements // Helper function for vertically aligning DOM elements
@@ -475,6 +469,61 @@ this["Handlebars"]["templates"]["content_type"] = Handlebars.template({"1":funct
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer + "</select>\n"; return buffer + "</select>\n";
},"useData":true}); },"useData":true});
var BasicAuthButton,
__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;
BasicAuthButton = (function(_super) {
__extends(BasicAuthButton, _super);
function BasicAuthButton() {
return BasicAuthButton.__super__.constructor.apply(this, arguments);
}
BasicAuthButton.prototype.initialize = function() {};
BasicAuthButton.prototype.render = function() {
var template;
template = this.template();
$(this.el).html(template(this.model));
return this;
};
BasicAuthButton.prototype.events = {
"click #basic_auth_button": "togglePasswordContainer",
"click #apply_basic_auth": "applyPassword"
};
BasicAuthButton.prototype.applyPassword = function() {
var elem, password, username;
username = $(".input_username").val();
password = $(".input_password").val();
window.authorizations.add(this.model.type, new PasswordAuthorization("basic", username, password));
window.swaggerUi.load();
return elem = $('#basic_auth_container').hide();
};
BasicAuthButton.prototype.togglePasswordContainer = function() {
var elem;
if ($('#basic_auth_container').length > 0) {
elem = $('#basic_auth_container').show();
if (elem.is(':visible')) {
return elem.slideUp();
} else {
$('.auth_container').hide();
return elem.show();
}
}
};
BasicAuthButton.prototype.template = function() {
return Handlebars.templates.basic_auth_button_view;
};
return BasicAuthButton;
})(Backbone.View);
this["Handlebars"]["templates"]["main"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["main"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression, buffer = " <div class=\"info_title\">" var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression, buffer = " <div class=\"info_title\">"
+ escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.title : stack1), depth0)) + escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.title : stack1), depth0))
@@ -558,58 +607,32 @@ this["Handlebars"]["templates"]["main"] = Handlebars.template({"1":function(dept
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer + " </h4>\n </div>\n</div>\n"; return buffer + " </h4>\n </div>\n</div>\n";
},"useData":true}); },"useData":true});
var BasicAuthButton, var ContentTypeView,
__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; }, __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; __hasProp = {}.hasOwnProperty;
BasicAuthButton = (function(_super) { ContentTypeView = (function(_super) {
__extends(BasicAuthButton, _super); __extends(ContentTypeView, _super);
function BasicAuthButton() { function ContentTypeView() {
return BasicAuthButton.__super__.constructor.apply(this, arguments); return ContentTypeView.__super__.constructor.apply(this, arguments);
} }
BasicAuthButton.prototype.initialize = function() {}; ContentTypeView.prototype.initialize = function() {};
BasicAuthButton.prototype.render = function() { ContentTypeView.prototype.render = function() {
var template; var template;
template = this.template(); template = this.template();
$(this.el).html(template(this.model)); $(this.el).html(template(this.model));
$('label[for=contentType]', $(this.el)).text('Response Content Type');
return this; return this;
}; };
BasicAuthButton.prototype.events = { ContentTypeView.prototype.template = function() {
"click #basic_auth_button": "togglePasswordContainer", return Handlebars.templates.content_type;
"click #apply_basic_auth": "applyPassword"
}; };
BasicAuthButton.prototype.applyPassword = function() { return ContentTypeView;
var elem, password, username;
username = $(".input_username").val();
password = $(".input_password").val();
window.authorizations.add(this.model.type, new PasswordAuthorization("basic", username, password));
window.swaggerUi.load();
return elem = $('#basic_auth_container').hide();
};
BasicAuthButton.prototype.togglePasswordContainer = function() {
var elem;
if ($('#basic_auth_container').length > 0) {
elem = $('#basic_auth_container').show();
if (elem.is(':visible')) {
return elem.slideUp();
} else {
$('.auth_container').hide();
return elem.show();
}
}
};
BasicAuthButton.prototype.template = function() {
return Handlebars.templates.basic_auth_button_view;
};
return BasicAuthButton;
})(Backbone.View); })(Backbone.View);
@@ -716,35 +739,6 @@ this["Handlebars"]["templates"]["operation"] = Handlebars.template({"1":function
if (stack1 != null) { buffer += stack1; } if (stack1 != null) { buffer += stack1; }
return buffer + " </form>\n <div class='response' style='display:none'>\n <h4>Request URL</h4>\n <div class='block request_url'></div>\n <h4>Response Body</h4>\n <div class='block response_body'></div>\n <h4>Response Code</h4>\n <div class='block response_code'></div>\n <h4>Response Headers</h4>\n <div class='block response_headers'></div>\n </div>\n </div>\n </li>\n </ul>\n"; return buffer + " </form>\n <div class='response' style='display:none'>\n <h4>Request URL</h4>\n <div class='block request_url'></div>\n <h4>Response Body</h4>\n <div class='block response_body'></div>\n <h4>Response Code</h4>\n <div class='block response_code'></div>\n <h4>Response Headers</h4>\n <div class='block response_headers'></div>\n </div>\n </div>\n </li>\n </ul>\n";
},"useData":true}); },"useData":true});
var ContentTypeView,
__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;
ContentTypeView = (function(_super) {
__extends(ContentTypeView, _super);
function ContentTypeView() {
return ContentTypeView.__super__.constructor.apply(this, arguments);
}
ContentTypeView.prototype.initialize = function() {};
ContentTypeView.prototype.render = function() {
var template;
template = this.template();
$(this.el).html(template(this.model));
$('label[for=contentType]', $(this.el)).text('Response Content Type');
return this;
};
ContentTypeView.prototype.template = function() {
return Handlebars.templates.content_type;
};
return ContentTypeView;
})(Backbone.View);
this["Handlebars"]["templates"]["param"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { this["Handlebars"]["templates"]["param"] = Handlebars.template({"1":function(depth0,helpers,partials,data) {
var stack1, buffer = ""; 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}); 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});

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. * swagger-client - swagger.js is a javascript client for use with swaggering APIs.
* @version v2.1.5-M1 * @version v2.1.7-M1
* @link http://swagger.io * @link http://swagger.io
* @license apache 2.0 * @license apache 2.0
*/ */
@@ -502,6 +502,8 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
for(i = 0; i < tags.length; i++) { for(i = 0; i < tags.length; i++) {
var tag = this.tagFromLabel(tags[i]); var tag = this.tagFromLabel(tags[i]);
var operationGroup = this[tag]; var operationGroup = this[tag];
if(typeof this.apis[tag] === 'undefined')
this.apis[tag] = {};
if(typeof operationGroup === 'undefined') { if(typeof operationGroup === 'undefined') {
this[tag] = []; this[tag] = [];
operationGroup = this[tag]; operationGroup = this[tag];
@@ -516,8 +518,16 @@ SwaggerClient.prototype.buildFromSpec = function(response) {
this[tag].help = this.help.bind(operationGroup); this[tag].help = this.help.bind(operationGroup);
this.apisArray.push(new OperationGroup(tag, operationGroup.description, operationGroup.externalDocs, operationObject)); 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] = operationObject.execute.bind(operationObject);
operationGroup[operationId].help = operationObject.help.bind(operationObject); operationGroup[operationId].help = operationObject.help.bind(operationObject);
operationGroup[operationId].asCurl = operationObject.asCurl.bind(operationObject);
operationGroup.apis.push(operationObject); operationGroup.apis.push(operationObject);
operationGroup.operations[operationId] = 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; 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++) { for(i = 0; i < this.apis.length; i++) {
var api = this.apis[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;
} }
}; };
@@ -1259,12 +1275,12 @@ var Model = function(name, definition) {
}; };
Model.prototype.createJSONSample = function(modelsToIgnore) { Model.prototype.createJSONSample = function(modelsToIgnore) {
var i, result = {}; var i, result = {}, representations = {};
modelsToIgnore = (modelsToIgnore||{}); modelsToIgnore = (modelsToIgnore||{});
modelsToIgnore[this.name] = this; modelsToIgnore[this.name] = this;
for (i = 0; i < this.properties.length; i++) { for (i = 0; i < this.properties.length; i++) {
prop = this.properties[i]; prop = this.properties[i];
var sample = prop.getSampleValue(modelsToIgnore); var sample = prop.getSampleValue(modelsToIgnore, representations);
result[prop.name] = sample; result[prop.name] = sample;
} }
delete modelsToIgnore[this.name]; delete modelsToIgnore[this.name];
@@ -1272,10 +1288,10 @@ Model.prototype.createJSONSample = function(modelsToIgnore) {
}; };
Model.prototype.getSampleValue = function(modelsToIgnore) { Model.prototype.getSampleValue = function(modelsToIgnore) {
var i, obj = {}; var i, obj = {}, representations = {};
for(i = 0; i < this.properties.length; i++ ) { for(i = 0; i < this.properties.length; i++ ) {
var property = this.properties[i]; var property = this.properties[i];
obj[property.name] = property.sampleValue(false, modelsToIgnore); obj[property.name] = property.sampleValue(false, modelsToIgnore, representations);
} }
return obj; return obj;
}; };
@@ -1340,8 +1356,8 @@ var Property = function(name, obj, required) {
this.multipleOf = obj.multipleOf || null; this.multipleOf = obj.multipleOf || null;
}; };
Property.prototype.getSampleValue = function (modelsToIgnore) { Property.prototype.getSampleValue = function (modelsToIgnore, representations) {
return this.sampleValue(false, modelsToIgnore); return this.sampleValue(false, modelsToIgnore, representations);
}; };
Property.prototype.isArray = function () { Property.prototype.isArray = function () {
@@ -1352,21 +1368,29 @@ Property.prototype.isArray = function () {
return false; return false;
}; };
Property.prototype.sampleValue = function(isArray, ignoredModels) { Property.prototype.sampleValue = function(isArray, ignoredModels, representations) {
isArray = (isArray || this.isArray()); isArray = (isArray || this.isArray());
ignoredModels = (ignoredModels || {}); ignoredModels = (ignoredModels || {});
// representations = (representations || {});
var type = getStringSignature(this.obj, true); var type = getStringSignature(this.obj, true);
var output; var output;
if(this.$ref) { if(this.$ref) {
var refModelName = simpleRef(this.$ref); var refModelName = simpleRef(this.$ref);
var refModel = models[refModelName]; var refModel = models[refModelName];
if(typeof representations[type] !== 'undefined') {
return representations[type];
}
else
if(refModel && typeof ignoredModels[type] === 'undefined') { if(refModel && typeof ignoredModels[type] === 'undefined') {
ignoredModels[type] = this; ignoredModels[type] = this;
output = refModel.getSampleValue(ignoredModels); output = refModel.getSampleValue(ignoredModels, representations);
representations[type] = output;
} }
else { else {
output = refModelName; output = (representations[type] || refModelName);
} }
} }
else if(this.example) else if(this.example)
@@ -1610,6 +1634,7 @@ SwaggerClient.prototype.buildFrom1_2Spec = function (response) {
res = new SwaggerResource(response, this); res = new SwaggerResource(response, this);
this.apis[newName] = res; this.apis[newName] = res;
this.apisArray.push(res); this.apisArray.push(res);
this.finish();
} else { } else {
var k; var k;
this.expectedResourceCount = response.apis.length; this.expectedResourceCount = response.apis.length;
@@ -1665,7 +1690,9 @@ SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
res = new SwaggerResource(response, this); res = new SwaggerResource(response, this);
this.apis[newName] = res; this.apis[newName] = res;
this.apisArray.push(res); this.apisArray.push(res);
this.finish();
} else { } else {
this.expectedResourceCount = response.apis.length;
for (k = 0; k < response.apis.length; k++) { for (k = 0; k < response.apis.length; k++) {
resource = response.apis[k]; resource = response.apis[k];
res = new SwaggerResource(resource, this); res = new SwaggerResource(resource, this);
@@ -1674,9 +1701,6 @@ SwaggerClient.prototype.buildFrom1_1Spec = function (response) {
} }
} }
this.isValid = true; this.isValid = true;
if (this.success) {
this.success();
}
return this; return this;
}; };
@@ -1698,16 +1722,18 @@ SwaggerClient.prototype.convertInfo = function (resp) {
}; };
SwaggerClient.prototype.selfReflect = function () { SwaggerClient.prototype.selfReflect = function () {
var resource, resource_name, ref; var resource, tag, ref;
if (this.apis === null) { if (this.apis === null) {
return false; return false;
} }
ref = this.apis; ref = this.apis;
for (resource_name in ref) { for (tag in ref) {
resource = ref[resource_name]; api = ref[tag];
if (resource.ready === null) { if (api.ready === null) {
return false; return false;
} }
this[tag] = api;
this[tag].help = __bind(api.help, api);
} }
this.setConsolidatedModels(); this.setConsolidatedModels();
this.ready = true; this.ready = true;
@@ -1743,7 +1769,6 @@ var SwaggerResource = function (resourceObj, api) {
this.description = resourceObj.description; this.description = resourceObj.description;
this.authorizations = (resourceObj.authorizations || {}); this.authorizations = (resourceObj.authorizations || {});
var parts = this.path.split('/'); var parts = this.path.split('/');
this.name = parts[parts.length - 1].replace('.{format}', ''); this.name = parts[parts.length - 1].replace('.{format}', '');
this.basePath = this.api.basePath; this.basePath = this.api.basePath;
@@ -1792,6 +1817,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) { SwaggerResource.prototype.getAbsoluteBasePath = function (relativeBasePath) {
var pos, url; var pos, url;
url = this.api.basePath; url = this.api.basePath;
@@ -2108,6 +2148,7 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
this.deprecated = deprecated; this.deprecated = deprecated;
this['do'] = __bind(this['do'], this); this['do'] = __bind(this['do'], this);
if(typeof this.deprecated === 'string') { if(typeof this.deprecated === 'string') {
switch(this.deprecated.toLowerCase()) { switch(this.deprecated.toLowerCase()) {
case 'true': case 'yes': case '1': { case 'true': case 'yes': case '1': {
@@ -2225,8 +2266,8 @@ var SwaggerOperation = function (nickname, path, method, parameters, summary, no
return _this['do'](arg1 || {}, arg2 || {}, arg3 || defaultSuccessCallback, arg4 || defaultErrorCallback); return _this['do'](arg1 || {}, arg2 || {}, arg3 || defaultSuccessCallback, arg4 || defaultErrorCallback);
}; };
this.resource[this.nickname].help = function () { this.resource[this.nickname].help = function (dontPrint) {
return _this.help(); return _this.help(dontPrint);
}; };
this.resource[this.nickname].asCurl = function (args) { this.resource[this.nickname].asCurl = function (args) {
return _this.asCurl(args); return _this.asCurl(args);
@@ -2465,16 +2506,19 @@ SwaggerOperation.prototype.getMatchingParams = function (paramTypes, args) {
return matchingParams; return matchingParams;
}; };
SwaggerOperation.prototype.help = function () { SwaggerOperation.prototype.help = function (dontPrint) {
var msg = ''; var msg = this.nickname + ': ' + this.summary;
var params = this.parameters; var params = this.parameters;
for (var i = 0; i < params.length; i++) { for (var i = 0; i < params.length; i++) {
var param = params[i]; var param = params[i];
if (msg !== '') msg += '\n* ' + param.name + (param.required ? ' (required)' : '') + " - " + param.description;
msg += '\n';
msg += '* ' + param.name + (param.required ? ' (required)' : '') + " - " + param.description;
} }
if(dontPrint)
return msg; return msg;
else {
console.log(msg);
return msg;
}
}; };
SwaggerOperation.prototype.asCurl = function (args) { SwaggerOperation.prototype.asCurl = function (args) {
@@ -2851,6 +2895,7 @@ JQueryHttpClient.prototype.execute = function(obj) {
url: request.url, url: request.url,
method: request.method, method: request.method,
status: response.status, status: response.status,
statusText: response.statusText,
data: response.responseText, data: response.responseText,
headers: headers headers: headers
}; };

View File

@@ -2,7 +2,7 @@
"name": "swagger-ui", "name": "swagger-ui",
"author": "Tony Tam <fehguy@gmail.com>", "author": "Tony Tam <fehguy@gmail.com>",
"description": "Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API", "description": "Swagger UI is a dependency-free collection of HTML, Javascript, and CSS assets that dynamically generate beautiful documentation from a Swagger-compliant API",
"version": "2.1.5-M1", "version": "2.1.6-M1",
"homepage": "http://swagger.io", "homepage": "http://swagger.io",
"license": "Apache 2.0", "license": "Apache 2.0",
"scripts": { "scripts": {
@@ -18,7 +18,7 @@
"dependencies": { "dependencies": {
"shred": "0.8.10", "shred": "0.8.10",
"btoa": "1.1.1", "btoa": "1.1.1",
"swagger-client": "2.1.5-M1" "swagger-client": "2.1.7-M1"
}, },
"devDependencies": { "devDependencies": {
"chai": "^1.10.0", "chai": "^1.10.0",

View File

@@ -105,6 +105,14 @@ describe('swagger 2.0 spec tests', function (done) {
}); });
}); });
it('should find the pet resource description', function(done){
var locator = webdriver.By.xpath("//div[contains(., 'Everything about your Pets')]");
driver.findElements(locator).then(function (elements) {
expect(elements.length).to.not.equal(0);
done();
});
});
it('should find the user link', function(done){ it('should find the user link', function(done){
var locator = webdriver.By.xpath("//*[@data-id='user']"); var locator = webdriver.By.xpath("//*[@data-id='user']");
driver.isElementPresent(locator).then(function (isPresent) { driver.isElementPresent(locator).then(function (isPresent) {

View File

@@ -20,6 +20,28 @@
"schemes": [ "schemes": [
"http" "http"
], ],
"tags": [
{
"name": "user",
"description": "Operations about user"
},
{
"name": "store",
"description": "Access to Petstore orders",
"externalDocs": {
"description": "Find out more",
"url": "http://swagger.io"
}
},
{
"name": "pet",
"description": "Everything about your Pets",
"externalDocs": {
"description": "Find out more",
"url": "http://swagger.io"
}
}
],
"paths": { "paths": {
"/pet": { "/pet": {
"post": { "post": {