diff --git a/dist/lib/swagger-client.js b/dist/lib/swagger-client.js index 5173335d..4619ed33 100644 --- a/dist/lib/swagger-client.js +++ b/dist/lib/swagger-client.js @@ -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.7-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; } }; @@ -1259,12 +1275,12 @@ var Model = function(name, definition) { }; Model.prototype.createJSONSample = function(modelsToIgnore) { - var i, result = {}; + var i, result = {}, representations = {}; modelsToIgnore = (modelsToIgnore||{}); modelsToIgnore[this.name] = this; for (i = 0; i < this.properties.length; i++) { prop = this.properties[i]; - var sample = prop.getSampleValue(modelsToIgnore); + var sample = prop.getSampleValue(modelsToIgnore, representations); result[prop.name] = sample; } delete modelsToIgnore[this.name]; @@ -1272,10 +1288,10 @@ Model.prototype.createJSONSample = function(modelsToIgnore) { }; Model.prototype.getSampleValue = function(modelsToIgnore) { - var i, obj = {}; + var i, obj = {}, representations = {}; for(i = 0; i < this.properties.length; i++ ) { var property = this.properties[i]; - obj[property.name] = property.sampleValue(false, modelsToIgnore); + obj[property.name] = property.sampleValue(false, modelsToIgnore, representations); } return obj; }; @@ -1340,8 +1356,8 @@ var Property = function(name, obj, required) { this.multipleOf = obj.multipleOf || null; }; -Property.prototype.getSampleValue = function (modelsToIgnore) { - return this.sampleValue(false, modelsToIgnore); +Property.prototype.getSampleValue = function (modelsToIgnore, representations) { + return this.sampleValue(false, modelsToIgnore, representations); }; Property.prototype.isArray = function () { @@ -1352,21 +1368,29 @@ Property.prototype.isArray = function () { return false; }; -Property.prototype.sampleValue = function(isArray, ignoredModels) { +Property.prototype.sampleValue = function(isArray, ignoredModels, representations) { isArray = (isArray || this.isArray()); ignoredModels = (ignoredModels || {}); + // representations = (representations || {}); + var type = getStringSignature(this.obj, true); var output; if(this.$ref) { var refModelName = simpleRef(this.$ref); var refModel = models[refModelName]; + if(typeof representations[type] !== 'undefined') { + return representations[type]; + } + else + if(refModel && typeof ignoredModels[type] === 'undefined') { ignoredModels[type] = this; - output = refModel.getSampleValue(ignoredModels); + output = refModel.getSampleValue(ignoredModels, representations); + representations[type] = output; } else { - output = refModelName; + output = (representations[type] || refModelName); } } else if(this.example) @@ -1610,6 +1634,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 +1690,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 +1701,6 @@ SwaggerClient.prototype.buildFrom1_1Spec = function (response) { } } this.isValid = true; - if (this.success) { - this.success(); - } return this; }; @@ -1698,16 +1722,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 +1769,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 +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) { var pos, url; url = this.api.basePath; @@ -2108,6 +2148,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 +2266,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 +2506,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 +2895,7 @@ JQueryHttpClient.prototype.execute = function(obj) { url: request.url, method: request.method, status: response.status, + statusText: response.statusText, data: response.responseText, headers: headers }; diff --git a/dist/swagger-ui.js b/dist/swagger-ui.js index f74be42e..3867a2d6 100644 --- a/dist/swagger-ui.js +++ b/dist/swagger-ui.js @@ -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() { // 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; } return buffer + "\n"; },"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) { var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression, buffer = "