From ef14c42d4cef20a98c9e0e98653cb301e7a2bae8 Mon Sep 17 00:00:00 2001 From: Tony Tam Date: Sat, 31 Jan 2015 20:39:57 -0800 Subject: [PATCH] unified client --- dist/lib/swagger-client.js | 2425 ++++++++--------- dist/swagger-ui.js | 930 +++---- dist/swagger-ui.min.js | 4 +- lib/swagger-client.js | 2425 ++++++++--------- src/main/coffeescript/SwaggerUi.coffee | 11 +- .../coffeescript/view/OperationView.coffee | 16 +- 6 files changed, 2830 insertions(+), 2981 deletions(-) diff --git a/dist/lib/swagger-client.js b/dist/lib/swagger-client.js index 2b5b850b..84c13f8f 100644 --- a/dist/lib/swagger-client.js +++ b/dist/lib/swagger-client.js @@ -273,33 +273,33 @@ PrimitiveModel.prototype.getMockSignature = function(modelsToIgnore) { } return returnVal; }; -/** - * Provides support for 1.x versions of swagger - */ -var SwaggerApi = function (url, options) { +var SwaggerClient = function(url, options) { this.isBuilt = false; this.url = null; this.debug = false; this.basePath = null; + this.modelsArray = []; this.authorizations = null; this.authorizationScheme = null; + this.isValid = false; this.info = null; this.useJQuery = false; - this.modelsArray = []; - this.isValid = false; - options = (options || {}); - if (url) - if (url.url) - options = url; - else - this.url = url; - else + if(typeof url !== 'undefined') + return this.initialize(url, options); +}; + +SwaggerClient.prototype.initialize = function (url, options) { + this.models = models; + + options = (options||{}); + + if(typeof url === 'string') + this.url = url; + else if(typeof url === 'object') { options = url; - - if (typeof options.url === 'string') this.url = options.url; - + } this.swaggerRequstHeaders = options.swaggerRequstHeaders || 'application/json;charset=utf-8,*/*'; this.defaultSuccessCallback = options.defaultSuccessCallback || null; this.defaultErrorCallback = options.defaultErrorCallback || null; @@ -307,7 +307,7 @@ var SwaggerApi = function (url, options) { if (typeof options.success === 'function') this.success = options.success; - if (typeof options.useJQuery === 'boolean') + if (options.useJQuery) this.useJQuery = options.useJQuery; if (options.authorizations) { @@ -318,59 +318,1166 @@ var SwaggerApi = function (url, options) { } this.supportedSubmitMethods = options.supportedSubmitMethods || []; - this.failure = typeof options.failure === 'function' ? options.failure : function () { }; - this.progress = typeof options.progress === 'function' ? options.progress : function () { }; + this.failure = options.failure || function() {}; + this.progress = options.progress || function() {}; + this.spec = options.spec; + this.options = options; + if (typeof options.success === 'function') { this.build(); - this.isBuilt = true; + // this.isBuilt = true; } }; -SwaggerApi.prototype.build = function (mock) { - if (this.isBuilt) - return this; - var _this = this; +SwaggerClient.prototype.build = function(mock) { + if (this.isBuilt) return this; + var self = this; this.progress('fetching resource list: ' + this.url); var obj = { useJQuery: this.useJQuery, url: this.url, - method: 'GET', + method: "get", headers: { - accept: _this.swaggerRequstHeaders + accept: this.swaggerRequstHeaders }, on: { - error: function (response) { - if (_this.url.substring(0, 4) !== 'http') { - return _this.fail('Please specify the protocol for ' + _this.url); - } else if (response.status === 0) { - return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.'); - } else if (response.status === 404) { - return _this.fail('Can\'t read swagger JSON from ' + _this.url); - } else { - return _this.fail(response.status + ' : ' + response.statusText + ' ' + _this.url); - } + error: function(response) { + if (self.url.substring(0, 4) !== 'http') + return self.fail('Please specify the protocol for ' + self.url); + else if (response.status === 0) + return self.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.'); + else if (response.status === 404) + return self.fail('Can\'t read swagger JSON from ' + self.url); + else + return self.fail(response.status + ' : ' + response.statusText + ' ' + self.url); }, - response: function (resp) { + response: function(resp) { var responseObj = resp.obj || JSON.parse(resp.data); - _this.swaggerVersion = responseObj.swaggerVersion; - if (_this.swaggerVersion === '1.2') { - return _this.buildFromSpec(responseObj); - } else { - return _this.buildFrom1_1Spec(responseObj); + self.swaggerVersion = responseObj.swaggerVersion; + + if(responseObj.swagger && parseInt(responseObj.swagger) === 2) { + self.swaggerVersion = responseObj.swagger; + self.buildFromSpec(responseObj); + self.isValid = true; + } + else { + if (self.swaggerVersion === '1.2') { + return self.buildFrom1_2Spec(responseObj); + } else { + return self.buildFrom1_1Spec(responseObj); + } } } } }; - var e = (typeof window !== 'undefined' ? window : exports); - e.authorizations.apply(obj); - if (mock === true) - return obj; + if(this.spec) { + setTimeout(function() { self.buildFromSpec(self.spec); }, 10); + } + else { + var e = (typeof window !== 'undefined' ? window : exports); + var status = e.authorizations.apply(obj); + if(mock) + return obj; + new SwaggerHttp().execute(obj); + } - new SwaggerHttp().execute(obj); return this; }; -SwaggerApi.prototype.buildFromSpec = function (response) { +SwaggerClient.prototype.buildFromSpec = function(response) { + if(this.isBuilt) return this; + + this.info = response.info || {}; + this.title = response.title || ''; + this.host = response.host || ''; + this.schemes = response.schemes || []; + this.basePath = response.basePath || ''; + this.apis = {}; + this.apisArray = []; + this.consumes = response.consumes; + this.produces = response.produces; + this.securityDefinitions = response.securityDefinitions; + + // legacy support + this.authSchemes = response.securityDefinitions; + + var location; + + if(typeof this.url === 'string') { + location = this.parseUri(this.url); + } + + if(typeof this.schemes === 'undefined' || this.schemes.length === 0) { + this.scheme = location.scheme || 'http'; + } + else { + this.scheme = this.schemes[0]; + } + + if(typeof this.host === 'undefined' || this.host === '') { + this.host = location.host; + if (location.port) { + this.host = this.host + ':' + location.port; + } + } + + this.definitions = response.definitions; + var key; + for(key in this.definitions) { + var model = new Model(key, this.definitions[key]); + if(model) { + models[key] = model; + } + } + + // get paths, create functions for each operationId + var path; + var operations = []; + for(path in response.paths) { + if(typeof response.paths[path] === 'object') { + var httpMethod; + for(httpMethod in response.paths[path]) { + if(['delete', 'get', 'head', 'options', 'patch', 'post', 'put'].indexOf(httpMethod) === -1) { + continue; + } + var operation = response.paths[path][httpMethod]; + var tags = operation.tags; + if(typeof tags === 'undefined') { + operation.tags = [ 'default' ]; + tags = operation.tags; + } + var operationId = this.idFromOp(path, httpMethod, operation); + var operationObject = new Operation ( + this, + operation.scheme, + operationId, + httpMethod, + path, + operation, + this.definitions + ); + // bind this operation's execute command to the api + if(tags.length > 0) { + var i; + for(i = 0; i < tags.length; i++) { + var tag = this.tagFromLabel(tags[i]); + var operationGroup = this[tag]; + if(typeof operationGroup === 'undefined') { + this[tag] = []; + operationGroup = this[tag]; + operationGroup.operations = {}; + operationGroup.label = tag; + operationGroup.apis = []; + this[tag].help = this.help.bind(operationGroup); + this.apisArray.push(new OperationGroup(tag, operationObject)); + } + operationGroup[operationId] = operationObject.execute.bind(operationObject); + operationGroup[operationId].help = operationObject.help.bind(operationObject); + operationGroup.apis.push(operationObject); + operationGroup.operations[operationId] = operationObject; + + // legacy UI feature + var j; + var api; + for(j = 0; j < this.apisArray.length; j++) { + if(this.apisArray[j].tag === tag) { + api = this.apisArray[j]; + } + } + if(api) { + api.operationsArray.push(operationObject); + } + } + } + else { + log('no group to bind to'); + } + } + } + } + this.isBuilt = true; + if (this.success) + this.success(); + return this; +}; + +SwaggerClient.prototype.parseUri = function(uri) { + var urlParseRE = /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/; + var parts = urlParseRE.exec(uri); + return { + scheme: parts[4].replace(':',''), + host: parts[11], + port: parts[12], + path: parts[15] + }; +}; + +SwaggerClient.prototype.help = function() { + var i; + log('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); + } +}; + +SwaggerClient.prototype.tagFromLabel = function(label) { + return label; +}; + +SwaggerClient.prototype.idFromOp = function(path, httpMethod, op) { + var opId = op.operationId || (path.substring(1) + '_' + httpMethod); + return opId.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()\+\s]/g,'_'); +}; + +SwaggerClient.prototype.fail = function(message) { + this.failure(message); + throw message; +}; + +var OperationGroup = function(tag, operation) { + this.tag = tag; + this.path = tag; + this.name = tag; + this.operation = operation; + this.operationsArray = []; + + this.description = operation.description || ""; +}; + +var Operation = function(parent, scheme, operationId, httpMethod, path, args, definitions) { + var errors = []; + parent = parent||{}; + args = args||{}; + + this.operations = {}; + this.operation = args; + this.deprecated = args.deprecated; + this.consumes = args.consumes; + this.produces = args.produces; + this.parent = parent; + this.host = parent.host || 'localhost'; + this.schemes = parent.schemes; + this.scheme = scheme || parent.scheme || 'http'; + this.basePath = parent.basePath || '/'; + this.nickname = (operationId||errors.push('Operations must have a nickname.')); + this.method = (httpMethod||errors.push('Operation ' + operationId + ' is missing method.')); + this.path = (path||errors.push('Operation ' + this.nickname + ' is missing path.')); + this.parameters = args !== null ? (args.parameters||[]) : {}; + this.summary = args.summary || ''; + this.responses = (args.responses||{}); + this.type = null; + this.security = args.security; + this.authorizations = args.security; + this.description = args.description; + this.useJQuery = parent.useJQuery; + + if(definitions) { + // add to global models + var key; + for(key in this.definitions) { + var model = new Model(key, definitions[key]); + if(model) { + models[key] = model; + } + } + } + + var i; + for(i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + if(param.type === 'array') { + param.isList = true; + param.allowMultiple = true; + } + var innerType = this.getType(param); + if(innerType && innerType.toString().toLowerCase() === 'boolean') { + param.allowableValues = {}; + param.isList = true; + param['enum'] = ["true", "false"]; + } + if(typeof param['enum'] !== 'undefined') { + var id; + param.allowableValues = {}; + param.allowableValues.values = []; + param.allowableValues.descriptiveValues = []; + for(id = 0; id < param['enum'].length; id++) { + var value = param['enum'][id]; + var isDefault = (value === param.default) ? true : false; + param.allowableValues.values.push(value); + param.allowableValues.descriptiveValues.push({value : value, isDefault: isDefault}); + } + } + if(param.type === 'array' && typeof param.allowableValues === 'undefined') { + // can't show as a list if no values to select from + delete param.isList; + delete param.allowMultiple; + } + param.signature = this.getModelSignature(innerType, models); + param.sampleJSON = this.getModelSampleJSON(innerType, models); + param.responseClassSignature = param.signature; + } + + var defaultResponseCode, response, model, responses = this.responses; + + if(responses['200']) { + response = responses['200']; + defaultResponseCode = '200'; + } + else if(responses['201']) { + response = responses['201']; + defaultResponseCode = '201'; + } + else if(responses['202']) { + response = responses['202']; + defaultResponseCode = '202'; + } + else if(responses['203']) { + response = responses['203']; + defaultResponseCode = '203'; + } + else if(responses['204']) { + response = responses['204']; + defaultResponseCode = '204'; + } + else if(responses['205']) { + response = responses['205']; + defaultResponseCode = '205'; + } + else if(responses['206']) { + response = responses['206']; + defaultResponseCode = '206'; + } + else if(responses['default']) { + response = responses['default']; + defaultResponseCode = 'default'; + } + + if(response && response.schema) { + var resolvedModel = this.resolveModel(response.schema, definitions); + delete responses[defaultResponseCode]; + if(resolvedModel) { + this.successResponse = {}; + this.successResponse[defaultResponseCode] = resolvedModel; + } + else { + this.successResponse = {}; + this.successResponse[defaultResponseCode] = response.schema.type; + } + this.type = response; + } + + if (errors.length > 0) { + if(this.resource && this.resource.api && this.resource.api.fail) + this.resource.api.fail(errors); + } + + return this; +}; + +OperationGroup.prototype.sort = function(sorter) { + +}; + +Operation.prototype.getType = function (param) { + var type = param.type; + var format = param.format; + var isArray = false; + var str; + if(type === 'integer' && format === 'int32') + str = 'integer'; + else if(type === 'integer' && format === 'int64') + str = 'long'; + else if(type === 'integer') + str = 'integer'; + else if(type === 'string' && format === 'date-time') + str = 'date-time'; + else if(type === 'string' && format === 'date') + str = 'date'; + else if(type === 'number' && format === 'float') + str = 'float'; + else if(type === 'number' && format === 'double') + str = 'double'; + else if(type === 'number') + str = 'double'; + else if(type === 'boolean') + str = 'boolean'; + else if(type === 'string') + str = 'string'; + else if(type === 'array') { + isArray = true; + if(param.items) + str = this.getType(param.items); + } + if(param.$ref) + str = param.$ref; + + var schema = param.schema; + if(schema) { + var ref = schema.$ref; + if(ref) { + ref = simpleRef(ref); + if(isArray) + return [ ref ]; + else + return ref; + } + else + return this.getType(schema); + } + if(isArray) + return [ str ]; + else + return str; +}; + +Operation.prototype.resolveModel = function (schema, definitions) { + if(typeof schema.$ref !== 'undefined') { + var ref = schema.$ref; + if(ref.indexOf('#/definitions/') === 0) + ref = ref.substring('#/definitions/'.length); + if(definitions[ref]) { + return new Model(ref, definitions[ref]); + } + } + if(schema.type === 'array') + return new ArrayModel(schema); + else + return null; +}; + +Operation.prototype.help = function(dontPrint) { + var out = this.nickname + ': ' + this.summary + '\n'; + for(var i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + var typeInfo = typeFromJsonSchema(param.type, param.format); + out += '\n * ' + param.name + ' (' + typeInfo + '): ' + param.description; + } + if(typeof dontPrint === 'undefined') + log(out); + return out; +}; + +Operation.prototype.getModelSignature = function(type, definitions) { + var isPrimitive, listType; + + if(type instanceof Array) { + listType = true; + type = type[0]; + } + + if(type === 'string') + isPrimitive = true; + else + isPrimitive = (listType && definitions[listType]) || (definitions[type]) ? false : true; + if (isPrimitive) { + return type; + } else { + if (listType) + return definitions[type].getMockSignature(); + else + return definitions[type].getMockSignature(); + } +}; + +Operation.prototype.supportHeaderParams = function () { + return true; +}; + +Operation.prototype.supportedSubmitMethods = function () { + return this.parent.supportedSubmitMethods; +}; + +Operation.prototype.getHeaderParams = function (args) { + var headers = this.setContentTypes(args, {}); + for(var i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + if(typeof args[param.name] !== 'undefined') { + if (param.in === 'header') { + var value = args[param.name]; + if(Array.isArray(value)) + value = this.encodePathCollection(param.collectionFormat, param.name, value); + else + value = this.encodePathParam(value); + headers[param.name] = value; + } + } + } + return headers; +}; + +Operation.prototype.urlify = function (args) { + var formParams = {}; + var requestUrl = this.path; + + // grab params from the args, build the querystring along the way + var querystring = ''; + for(var i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + if(typeof args[param.name] !== 'undefined') { + if(param.in === 'path') { + var reg = new RegExp('\{' + param.name + '\}', 'gi'); + var value = args[param.name]; + if(Array.isArray(value)) + value = this.encodePathCollection(param.collectionFormat, param.name, value); + else + value = this.encodePathParam(value); + requestUrl = requestUrl.replace(reg, value); + } + else if (param.in === 'query' && typeof args[param.name] !== 'undefined') { + if(querystring === '') + querystring += '?'; + else + querystring += '&'; + if(typeof param.collectionFormat !== 'undefined') { + var qp = args[param.name]; + if(Array.isArray(qp)) + querystring += this.encodeQueryCollection(param.collectionFormat, param.name, qp); + else + querystring += this.encodeQueryParam(param.name) + '=' + this.encodeQueryParam(args[param.name]); + } + else + querystring += this.encodeQueryParam(param.name) + '=' + this.encodeQueryParam(args[param.name]); + } + else if (param.in === 'formData') + formParams[param.name] = args[param.name]; + } + } + var url = this.scheme + '://' + this.host; + + if(this.basePath !== '/') + url += this.basePath; + + return url + requestUrl + querystring; +}; + +Operation.prototype.getMissingParams = function(args) { + var missingParams = []; + // check required params, track the ones that are missing + var i; + for(i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + if(param.required === true) { + if(typeof args[param.name] === 'undefined') + missingParams = param.name; + } + } + return missingParams; +}; + +Operation.prototype.getBody = function(headers, args) { + var formParams = {}; + var body; + + for(var i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + if(typeof args[param.name] !== 'undefined') { + if (param.in === 'body') { + body = args[param.name]; + } else if(param.in === 'formData') { + formParams[param.name] = args[param.name]; + } + } + } + + // handle form params + if(headers['Content-Type'] === 'application/x-www-form-urlencoded') { + var encoded = ""; + var key; + for(key in formParams) { + value = formParams[key]; + if(typeof value !== 'undefined'){ + if(encoded !== "") + encoded += "&"; + encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value); + } + } + body = encoded; + } + + return body; +}; + +/** + * gets sample response for a single operation + **/ +Operation.prototype.getModelSampleJSON = function(type, models) { + var isPrimitive, listType, sampleJson; + + listType = (type instanceof Array); + isPrimitive = models[type] ? false : true; + sampleJson = isPrimitive ? void 0 : models[type].createJSONSample(); + if (sampleJson) { + sampleJson = listType ? [sampleJson] : sampleJson; + if(typeof sampleJson == 'string') + return sampleJson; + else if(typeof sampleJson === 'object') { + var t = sampleJson; + if(sampleJson instanceof Array && sampleJson.length > 0) { + t = sampleJson[0]; + } + if(t.nodeName) { + var xmlString = new XMLSerializer().serializeToString(t); + return this.formatXml(xmlString); + } + else + return JSON.stringify(sampleJson, null, 2); + } + else + return sampleJson; + } +}; + +/** + * legacy binding + **/ +Operation.prototype["do"] = function(args, opts, callback, error, parent) { + return this.execute(args, opts, callback, error, parent); +}; + + +/** + * executes an operation + **/ +Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) { + var args = arg1 || {}; + var opts = {}, success, error; + if(typeof arg2 === 'object') { + opts = arg2; + success = arg3; + error = arg4; + } + + if(typeof arg2 === 'function') { + success = arg2; + error = arg3; + } + + success = (success||log); + error = (error||log); + + if(typeof opts.useJQuery === 'boolean') { + this.useJQuery = opts.useJQuery; + } + + var missingParams = this.getMissingParams(args); + if(missingParams.length > 0) { + var message = 'missing required params: ' + missingParams; + fail(message); + return; + } + var headers = this.getHeaderParams(args); + headers = this.setContentTypes(args, opts); + var body = this.getBody(headers, args); + var url = this.urlify(args); + + var obj = { + url: url, + method: this.method.toUpperCase(), + body: body, + useJQuery: this.useJQuery, + headers: headers, + on: { + response: function(response) { + return success(response, parent); + }, + error: function(response) { + return error(response, parent); + } + } + }; + var status = e.authorizations.apply(obj, this.operation.security); + if(opts.mock === true) + return obj; + else + new SwaggerHttp().execute(obj); +}; + +Operation.prototype.setContentTypes = function(args, opts) { + // default type + var accepts = 'application/json'; + var consumes = args.parameterContentType || 'application/json'; + + var allDefinedParams = this.parameters; + var definedFormParams = []; + var definedFileParams = []; + var body; + var headers = {}; + + // get params from the operation and set them in definedFileParams, definedFormParams, headers + var i; + for(i = 0; i < allDefinedParams.length; i++) { + var param = allDefinedParams[i]; + if(param.in === 'formData') { + if(param.type === 'file') + definedFileParams.push(param); + else + definedFormParams.push(param); + } + else if(param.in === 'header' && this.headers) { + var key = param.name; + var headerValue = this.headers[param.name]; + if(typeof this.headers[param.name] !== 'undefined') + headers[key] = headerValue; + } + else if(param.in === 'body' && typeof args[param.name] !== 'undefined') { + body = args[param.name]; + } + } + + // if there's a body, need to set the consumes header via requestContentType + if (body && (this.method === 'post' || this.method === 'put' || this.method === 'patch' || this.method === 'delete')) { + if (opts.requestContentType) + consumes = opts.requestContentType; + } else { + // if any form params, content type must be set + if(definedFormParams.length > 0) { + if(opts.requestContentType) // override if set + consumes = opts.requestContentType; + else if(definedFileParams.length > 0) // if a file, must be multipart/form-data + consumes = 'multipart/form-data'; + else // default to x-www-from-urlencoded + consumes = 'application/x-www-form-urlencoded'; + } + else if (this.type == 'DELETE') + body = '{}'; + else if (this.type != 'DELETE') + consumes = null; + } + + if (consumes && this.consumes) { + if (this.consumes.indexOf(consumes) === -1) { + log('server doesn\'t consume ' + consumes + ', try ' + JSON.stringify(this.consumes)); + } + } + + if (opts.responseContentType) { + accepts = opts.responseContentType; + } else { + accepts = 'application/json'; + } + if (accepts && this.produces) { + if (this.produces.indexOf(accepts) === -1) { + log('server can\'t produce ' + accepts); + } + } + + if ((consumes && body !== '') || (consumes === 'application/x-www-form-urlencoded')) + headers['Content-Type'] = consumes; + if (accepts) + headers.Accept = accepts; + return headers; +}; + +Operation.prototype.asCurl = function (args) { + var results = []; + var headers = this.getHeaderParams(args); + if (headers) { + var key; + for (key in headers) + results.push("--header \"" + key + ": " + headers[key] + "\""); + } + return "curl " + (results.join(" ")) + " " + this.urlify(args); +}; + +Operation.prototype.encodePathCollection = function(type, name, value) { + var encoded = ''; + var i; + var separator = ''; + if(type === 'ssv') + separator = '%20'; + else if(type === 'tsv') + separator = '\\t'; + else if(type === 'pipes') + separator = '|'; + else + separator = ','; + + for(i = 0; i < value.length; i++) { + if(i === 0) + encoded = this.encodeQueryParam(value[i]); + else + encoded += separator + this.encodeQueryParam(value[i]); + } + return encoded; +}; + +Operation.prototype.encodeQueryCollection = function(type, name, value) { + var encoded = ''; + var i; + if(type === 'default' || type === 'multi') { + for(i = 0; i < value.length; i++) { + if(i > 0) encoded += '&'; + encoded += this.encodeQueryParam(name) + '=' + this.encodeQueryParam(value[i]); + } + } + else { + var separator = ''; + if(type === 'csv') + separator = ','; + else if(type === 'ssv') + separator = '%20'; + else if(type === 'tsv') + separator = '\\t'; + else if(type === 'pipes') + separator = '|'; + else if(type === 'brackets') { + for(i = 0; i < value.length; i++) { + if(i !== 0) + encoded += '&'; + encoded += this.encodeQueryParam(name) + '[]=' + this.encodeQueryParam(value[i]); + } + } + if(separator !== '') { + for(i = 0; i < value.length; i++) { + if(i === 0) + encoded = this.encodeQueryParam(name) + '=' + this.encodeQueryParam(value[i]); + else + encoded += separator + this.encodeQueryParam(value[i]); + } + } + } + return encoded; +}; + +Operation.prototype.encodeQueryParam = function(arg) { + return encodeURIComponent(arg); +}; + +/** + * TODO revisit, might not want to leave '/' + **/ +Operation.prototype.encodePathParam = function(pathParam) { + var encParts, part, parts, i, len; + pathParam = pathParam.toString(); + if (pathParam.indexOf('/') === -1) { + return encodeURIComponent(pathParam); + } else { + parts = pathParam.split('/'); + encParts = []; + for (i = 0, len = parts.length; i < len; i++) { + encParts.push(encodeURIComponent(parts[i])); + } + return encParts.join('/'); + } +}; + +var Model = function(name, definition) { + this.name = name; + this.definition = definition || {}; + this.properties = []; + var requiredFields = definition.required || []; + if(definition.type === 'array') { + var out = new ArrayModel(definition); + return out; + } + var key; + var props = definition.properties; + if(props) { + for(key in props) { + var required = false; + var property = props[key]; + if(requiredFields.indexOf(key) >= 0) + required = true; + this.properties.push(new Property(key, property, required)); + } + } +}; + +Model.prototype.createJSONSample = function(modelsToIgnore) { + var result = {}; + modelsToIgnore = (modelsToIgnore||{}); + modelsToIgnore[this.name] = this; + var i; + for (i = 0; i < this.properties.length; i++) { + prop = this.properties[i]; + result[prop.name] = prop.getSampleValue(modelsToIgnore); + } + delete modelsToIgnore[this.name]; + return result; +}; + +Model.prototype.getSampleValue = function(modelsToIgnore) { + var i; + var obj = {}; + for(i = 0; i < this.properties.length; i++ ) { + var property = this.properties[i]; + obj[property.name] = property.sampleValue(false, modelsToIgnore); + } + return obj; +}; + +Model.prototype.getMockSignature = function(modelsToIgnore) { + var propertiesStr = []; + var i, prop; + for (i = 0; i < this.properties.length; i++) { + prop = this.properties[i]; + propertiesStr.push(prop.toString()); + } + + var strong = ''; + var stronger = ''; + var strongClose = ''; + var classOpen = strong + this.name + ' {' + strongClose; + var classClose = strong + '}' + strongClose; + var returnVal = classOpen + '
' + propertiesStr.join(',
') + '
' + classClose; + if (!modelsToIgnore) + modelsToIgnore = {}; + + modelsToIgnore[this.name] = this; + for (i = 0; i < this.properties.length; i++) { + prop = this.properties[i]; + var ref = prop.$ref; + var model = models[ref]; + if (model && typeof modelsToIgnore[model.name] === 'undefined') { + returnVal = returnVal + ('
' + model.getMockSignature(modelsToIgnore)); + } + } + return returnVal; +}; + +var Property = function(name, obj, required) { + this.schema = obj; + this.required = required; + if(obj.$ref) + this.$ref = simpleRef(obj.$ref); + else if (obj.type === 'array' && obj.items) { + if(obj.items.$ref) + this.$ref = simpleRef(obj.items.$ref); + else + obj = obj.items; + } + this.name = name; + this.description = obj.description; + this.obj = obj; + this.optional = true; + this.optional = !required; + this.default = obj.default || null; + this.example = obj.example || null; + this.collectionFormat = obj.collectionFormat || null; + this.maximum = obj.maximum || null; + this.exclusiveMaximum = obj.exclusiveMaximum || null; + this.minimum = obj.minimum || null; + this.exclusiveMinimum = obj.exclusiveMinimum || null; + this.maxLength = obj.maxLength || null; + this.minLength = obj.minLength || null; + this.pattern = obj.pattern || null; + this.maxItems = obj.maxItems || null; + this.minItems = obj.minItems || null; + this.uniqueItems = obj.uniqueItems || null; + this['enum'] = obj['enum'] || null; + this.multipleOf = obj.multipleOf || null; +}; + +Property.prototype.getSampleValue = function (modelsToIgnore) { + return this.sampleValue(false, modelsToIgnore); +}; + +Property.prototype.isArray = function () { + var schema = this.schema; + if(schema.type === 'array') + return true; + else + return false; +}; + +Property.prototype.sampleValue = function(isArray, ignoredModels) { + isArray = (isArray || this.isArray()); + ignoredModels = (ignoredModels || {}); + var type = getStringSignature(this.obj); + var output; + + if(this.$ref) { + var refModelName = simpleRef(this.$ref); + var refModel = models[refModelName]; + if(refModel && typeof ignoredModels[type] === 'undefined') { + ignoredModels[type] = this; + output = refModel.getSampleValue(ignoredModels); + } + else + type = refModel; + } + else if(this.example) + output = this.example; + else if(this.default) + output = this.default; + else if(type === 'date-time') + output = new Date().toISOString(); + else if(type === 'string') + output = 'string'; + else if(type === 'integer') + output = 0; + else if(type === 'long') + output = 0; + else if(type === 'float') + output = 0.0; + else if(type === 'double') + output = 0.0; + else if(type === 'boolean') + output = true; + else + output = {}; + ignoredModels[type] = output; + if(isArray) + return [output]; + else + return output; +}; + +getStringSignature = function(obj) { + var str = ''; + if(typeof obj.type === 'undefined') + str += obj; + else if(obj.type === 'array') { + str += 'Array['; + str += getStringSignature((obj.items || obj.$ref || {})); + str += ']'; + } + else if(obj.type === 'integer' && obj.format === 'int32') + str += 'integer'; + else if(obj.type === 'integer' && obj.format === 'int64') + str += 'long'; + else if(obj.type === 'integer' && typeof obj.format === 'undefined') + str += 'long'; + else if(obj.type === 'string' && obj.format === 'date-time') + str += 'date-time'; + else if(obj.type === 'string' && obj.format === 'date') + str += 'date'; + else if(obj.type === 'string' && typeof obj.format === 'undefined') + str += 'string'; + else if(obj.type === 'number' && obj.format === 'float') + str += 'float'; + else if(obj.type === 'number' && obj.format === 'double') + str += 'double'; + else if(obj.type === 'number' && typeof obj.format === 'undefined') + str += 'double'; + else if(obj.type === 'boolean') + str += 'boolean'; + else if(obj.$ref) + str += simpleRef(obj.$ref); + else + str += obj.type; + return str; +}; + +simpleRef = function(name) { + if(typeof name === 'undefined') + return null; + if(name.indexOf("#/definitions/") === 0) + return name.substring('#/definitions/'.length); + else + return name; +}; + +Property.prototype.toString = function() { + var str = getStringSignature(this.obj); + if(str !== '') { + str = '' + this.name + ' (' + str + ''; + if(!this.required) + str += ', optional'; + str += ')'; + } + else + str = this.name + ' (' + JSON.stringify(this.obj) + ')'; + + if(typeof this.description !== 'undefined') + str += ': ' + this.description; + + var options = ''; + var isArray = this.schema.type === 'array'; + var type = isArray ? this.schema.items.type : this.schema.type; + + if (this.default) + options += optionHtml('Default', this.default); + + switch (type) { + case 'string': + if (this.minLength) + options += optionHtml('Min. Length', this.minLength); + if (this.maxLength) + options += optionHtml('Max. Length', this.maxLength); + if (this.pattern) + options += optionHtml('Reg. Exp.', this.pattern); + break; + case 'integer': + case 'number': + if (this.minimum) + options += optionHtml('Min. Value', this.minimum); + if (this.exclusiveMinimum) + options += optionHtml('Exclusive Min.', "true"); + if (this.maximum) + options += optionHtml('Max. Value', this.maximum); + if (this.exclusiveMaximum) + options += optionHtml('Exclusive Max.', "true"); + if (this.multipleOf) + options += optionHtml('Multiple Of', this.multipleOf); + break; + } + + if (isArray) { + if (this.minItems) + options += optionHtml('Min. Items', this.minItems); + if (this.maxItems) + options += optionHtml('Max. Items', this.maxItems); + if (this.uniqueItems) + options += optionHtml('Unique Items', "true"); + if (this.collectionFormat) + options += optionHtml('Coll. Format', this.collectionFormat); + } + + if (this['enum']) { + var enumString; + + if (type === 'number' || type === 'integer') + enumString = this['enum'].join(', '); + else { + enumString = '"' + this['enum'].join('", "') + '"'; + } + + options += optionHtml('Enum', enumString); + } + + if (options.length > 0) + str = '' + str + '' + options + '
' + this.name + '
'; + + return str; +}; + +optionHtml = function(label, value) { + return '' + label + ':' + value + ''; +} + +typeFromJsonSchema = function(type, format) { + var str; + if(type === 'integer' && format === 'int32') + str = 'integer'; + else if(type === 'integer' && format === 'int64') + str = 'long'; + else if(type === 'integer' && typeof format === 'undefined') + str = 'long'; + else if(type === 'string' && format === 'date-time') + str = 'date-time'; + else if(type === 'string' && format === 'date') + str = 'date'; + else if(type === 'number' && format === 'float') + str = 'float'; + else if(type === 'number' && format === 'double') + str = 'double'; + else if(type === 'number' && typeof format === 'undefined') + str = 'double'; + else if(type === 'boolean') + str = 'boolean'; + else if(type === 'string') + str = 'string'; + + return str; +}; + +var sampleModels = {}; +var cookies = {}; +var models = {}; + +SwaggerClient.prototype.buildFrom1_2Spec = function (response) { if (response.apiVersion != null) { this.apiVersion = response.apiVersion; } @@ -421,7 +1528,7 @@ SwaggerApi.prototype.buildFromSpec = function (response) { return this; }; -SwaggerApi.prototype.buildFrom1_1Spec = function (response) { +SwaggerClient.prototype.buildFrom1_1Spec = function (response) { log('This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info'); if (response.apiVersion != null) this.apiVersion = response.apiVersion; @@ -467,7 +1574,7 @@ SwaggerApi.prototype.buildFrom1_1Spec = function (response) { return this; }; -SwaggerApi.prototype.convertInfo = function (resp) { +SwaggerClient.prototype.convertInfo = function (resp) { if(typeof resp == 'object') { var info = {} @@ -484,7 +1591,7 @@ SwaggerApi.prototype.convertInfo = function (resp) { } }; -SwaggerApi.prototype.selfReflect = function () { +SwaggerClient.prototype.selfReflect = function () { var resource, resource_name, ref; if (this.apis === null) { return false; @@ -503,17 +1610,12 @@ SwaggerApi.prototype.selfReflect = function () { } }; -SwaggerApi.prototype.fail = function (message) { - this.failure(message); - throw message; -}; - -SwaggerApi.prototype.setConsolidatedModels = function () { - var model, modelName, resource, resource_name, _i, _len, _ref, _ref1, _results; +SwaggerClient.prototype.setConsolidatedModels = function () { + var model, modelName, resource, resource_name, i, apis, models, results; this.models = {}; - _ref = this.apis; - for (resource_name in _ref) { - resource = _ref[resource_name]; + apis = this.apis; + for (resource_name in apis) { + resource = apis[resource_name]; for (modelName in resource.models) { if (typeof this.models[modelName] === 'undefined') { this.models[modelName] = resource.models[modelName]; @@ -521,33 +1623,13 @@ SwaggerApi.prototype.setConsolidatedModels = function () { } } } - _ref1 = this.modelsArray; - _results = []; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - model = _ref1[_i]; - _results.push(model.setReferencedModels(this.models)); + models = this.modelsArray; + results = []; + for (i = 0; i < models.length; i++) { + model = models[i]; + results.push(model.setReferencedModels(this.models)); } - return _results; -}; - -SwaggerApi.prototype.help = function () { - var operation, operation_name, parameter, resource, resource_name, _i, _len, _ref, _ref1, _ref2; - _ref = this.apis; - for (resource_name in _ref) { - resource = _ref[resource_name]; - log(resource_name); - _ref1 = resource.operations; - for (operation_name in _ref1) { - operation = _ref1[operation_name]; - log(' ' + operation.nickname); - _ref2 = operation.parameters; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - parameter = _ref2[_i]; - log(' ' + parameter.name + (parameter.required ? ' (required)' : '') + ' - ' + parameter.description); - } - } - } - return this; + return results; }; var SwaggerResource = function (resourceObj, api) { @@ -1552,1173 +2634,6 @@ SwaggerRequest.prototype.setHeaders = function (params, opts, operation) { return headers; }; -var SwaggerClient = function(url, options) { - this.isBuilt = false; - this.url = null; - this.debug = false; - this.basePath = null; - this.authorizations = null; - this.authorizationScheme = null; - this.isValid = false; - this.info = null; - this.useJQuery = false; - this.models = {}; - - options = (options||{}); - - if(typeof url === 'string') - this.url = url; - else if(typeof url === 'object') { - options = url; - this.url = options.url; - } - - if (typeof options.success === 'function') - this.success = options.success; - - if (options.useJQuery) - this.useJQuery = options.useJQuery; - - this.supportedSubmitMethods = options.supportedSubmitMethods || []; - this.failure = options.failure || function() {}; - this.progress = options.progress || function() {}; - this.spec = options.spec; - - if (typeof options.success === 'function') - this.build(); -}; - -SwaggerClient.prototype.build = function() { - var self = this; - this.progress('fetching resource list: ' + this.url); - var obj = { - useJQuery: this.useJQuery, - url: this.url, - method: "get", - headers: { - accept: "application/json, */*" - }, - on: { - error: function(response) { - if (self.url.substring(0, 4) !== 'http') - return self.fail('Please specify the protocol for ' + self.url); - else if (response.status === 0) - return self.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.'); - else if (response.status === 404) - return self.fail('Can\'t read swagger JSON from ' + self.url); - else - return self.fail(response.status + ' : ' + response.statusText + ' ' + self.url); - }, - response: function(resp) { - var responseObj = resp.obj || JSON.parse(resp.data); - self.swaggerVersion = responseObj.swaggerVersion; - - if(responseObj.swagger && parseInt(responseObj.swagger) === 2) { - self.swaggerVersion = responseObj.swagger; - self.buildFromSpec(responseObj); - self.isValid = true; - } - else { - self.isValid = false; - self.failure(); - } - } - } - }; - if(this.spec) { - setTimeout(function() { self.buildFromSpec(self.spec); }, 10); - } - else { - var e = (typeof window !== 'undefined' ? window : exports); - var status = e.authorizations.apply(obj); - new SwaggerHttp().execute(obj); - } - - return this; -}; - -SwaggerClient.prototype.buildFromSpec = function(response) { - if(this.isBuilt) return this; - - this.info = response.info || {}; - this.title = response.title || ''; - this.host = response.host || ''; - this.schemes = response.schemes || []; - this.basePath = response.basePath || ''; - this.apis = {}; - this.apisArray = []; - this.consumes = response.consumes; - this.produces = response.produces; - this.securityDefinitions = response.securityDefinitions; - - // legacy support - this.authSchemes = response.securityDefinitions; - - var location; - - if(typeof this.url === 'string') { - location = this.parseUri(this.url); - } - - if(typeof this.schemes === 'undefined' || this.schemes.length === 0) { - this.scheme = location.scheme || 'http'; - } - else { - this.scheme = this.schemes[0]; - } - - if(typeof this.host === 'undefined' || this.host === '') { - this.host = location.host; - if (location.port) { - this.host = this.host + ':' + location.port; - } - } - - this.definitions = response.definitions; - var key; - for(key in this.definitions) { - var model = new Model(key, this.definitions[key]); - if(model) { - models[key] = model; - } - } - - // get paths, create functions for each operationId - var path; - var operations = []; - for(path in response.paths) { - if(typeof response.paths[path] === 'object') { - var httpMethod; - for(httpMethod in response.paths[path]) { - if(['delete', 'get', 'head', 'options', 'patch', 'post', 'put'].indexOf(httpMethod) === -1) { - continue; - } - var operation = response.paths[path][httpMethod]; - var tags = operation.tags; - if(typeof tags === 'undefined') { - operation.tags = [ 'default' ]; - tags = operation.tags; - } - var operationId = this.idFromOp(path, httpMethod, operation); - var operationObject = new Operation ( - this, - operationId, - httpMethod, - path, - operation, - this.definitions - ); - // bind this operation's execute command to the api - if(tags.length > 0) { - var i; - for(i = 0; i < tags.length; i++) { - var tag = this.tagFromLabel(tags[i]); - var operationGroup = this[tag]; - if(typeof operationGroup === 'undefined') { - this[tag] = []; - operationGroup = this[tag]; - operationGroup.operations = {}; - operationGroup.label = tag; - operationGroup.apis = []; - this[tag].help = this.help.bind(operationGroup); - this.apisArray.push(new OperationGroup(tag, operationObject)); - } - operationGroup[operationId] = operationObject.execute.bind(operationObject); - operationGroup[operationId].help = operationObject.help.bind(operationObject); - operationGroup.apis.push(operationObject); - operationGroup.operations[operationId] = operationObject; - - // legacy UI feature - var j; - var api; - for(j = 0; j < this.apisArray.length; j++) { - if(this.apisArray[j].tag === tag) { - api = this.apisArray[j]; - } - } - if(api) { - api.operationsArray.push(operationObject); - } - } - } - else { - log('no group to bind to'); - } - } - } - } - this.isBuilt = true; - if (this.success) - this.success(); - return this; -}; - -SwaggerClient.prototype.parseUri = function(uri) { - var urlParseRE = /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/; - var parts = urlParseRE.exec(uri); - return { - scheme: parts[4].replace(':',''), - host: parts[11], - port: parts[12], - path: parts[15] - }; -}; - -SwaggerClient.prototype.help = function() { - var i; - log('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); - } -}; - -SwaggerClient.prototype.tagFromLabel = function(label) { - return label; -}; - -SwaggerClient.prototype.idFromOp = function(path, httpMethod, op) { - var opId = op.operationId || (path.substring(1) + '_' + httpMethod); - return opId.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()\+\s]/g,'_'); -}; - -SwaggerClient.prototype.fail = function(message) { - this.failure(message); - throw message; -}; - -var OperationGroup = function(tag, operation) { - this.tag = tag; - this.path = tag; - this.name = tag; - this.operation = operation; - this.operationsArray = []; - - this.description = operation.description || ""; -}; - -var Operation = function(parent, operationId, httpMethod, path, args, definitions) { - var errors = []; - parent = parent||{}; - args = args||{}; - - this.operations = {}; - this.operation = args; - this.deprecated = args.deprecated; - this.consumes = args.consumes; - this.produces = args.produces; - this.parent = parent; - this.host = parent.host || 'localhost'; - this.schemes = parent.schemes; - this.scheme = parent.scheme || 'http'; - this.basePath = parent.basePath || '/'; - this.nickname = (operationId||errors.push('Operations must have a nickname.')); - this.method = (httpMethod||errors.push('Operation ' + operationId + ' is missing method.')); - this.path = (path||errors.push('Operation ' + this.nickname + ' is missing path.')); - this.parameters = args !== null ? (args.parameters||[]) : {}; - this.summary = args.summary || ''; - this.responses = (args.responses||{}); - this.type = null; - this.security = args.security; - this.authorizations = args.security; - this.description = args.description; - this.useJQuery = parent.useJQuery; - - var i; - for(i = 0; i < this.parameters.length; i++) { - var param = this.parameters[i]; - if(param.type === 'array') { - param.isList = true; - param.allowMultiple = true; - } - var innerType = this.getType(param); - if(innerType && innerType.toString().toLowerCase() === 'boolean') { - param.allowableValues = {}; - param.isList = true; - param['enum'] = ["true", "false"]; - } - if(typeof param['enum'] !== 'undefined') { - var id; - param.allowableValues = {}; - param.allowableValues.values = []; - param.allowableValues.descriptiveValues = []; - for(id = 0; id < param['enum'].length; id++) { - var value = param['enum'][id]; - var isDefault = (value === param.default) ? true : false; - param.allowableValues.values.push(value); - param.allowableValues.descriptiveValues.push({value : value, isDefault: isDefault}); - } - } - if(param.type === 'array' && typeof param.allowableValues === 'undefined') { - // can't show as a list if no values to select from - delete param.isList; - delete param.allowMultiple; - } - param.signature = this.getSignature(innerType, models); - param.sampleJSON = this.getSampleJSON(innerType, models); - param.responseClassSignature = param.signature; - } - - var response; - var model; - var responses = this.responses; - - if(responses['200']) { - response = responses['200']; - defaultResponseCode = '200'; - } - else if(responses['201']) { - response = responses['201']; - defaultResponseCode = '201'; - } - else if(responses['202']) { - response = responses['202']; - defaultResponseCode = '202'; - } - else if(responses['203']) { - response = responses['203']; - defaultResponseCode = '203'; - } - else if(responses['204']) { - response = responses['204']; - defaultResponseCode = '204'; - } - else if(responses['205']) { - response = responses['205']; - defaultResponseCode = '205'; - } - else if(responses['206']) { - response = responses['206']; - defaultResponseCode = '206'; - } - else if(responses['default']) { - response = responses['default']; - defaultResponseCode = 'default'; - } - - if(response && response.schema) { - var resolvedModel = this.resolveModel(response.schema, definitions); - if(resolvedModel) { - this.type = resolvedModel.name; - this.responseSampleJSON = JSON.stringify(resolvedModel.getSampleValue(), null, 2); - this.responseClassSignature = resolvedModel.getMockSignature(); - delete responses[defaultResponseCode]; - } - else { - this.type = response.schema.type; - } - } - - if (errors.length > 0) { - if(this.resource && this.resource.api && this.resource.api.fail) - this.resource.api.fail(errors); - } - - return this; -}; - -OperationGroup.prototype.sort = function(sorter) { - -}; - -Operation.prototype.getType = function (param) { - var type = param.type; - var format = param.format; - var isArray = false; - var str; - if(type === 'integer' && format === 'int32') - str = 'integer'; - else if(type === 'integer' && format === 'int64') - str = 'long'; - else if(type === 'integer') - str = 'integer'; - else if(type === 'string' && format === 'date-time') - str = 'date-time'; - else if(type === 'string' && format === 'date') - str = 'date'; - else if(type === 'number' && format === 'float') - str = 'float'; - else if(type === 'number' && format === 'double') - str = 'double'; - else if(type === 'number') - str = 'double'; - else if(type === 'boolean') - str = 'boolean'; - else if(type === 'string') - str = 'string'; - else if(type === 'array') { - isArray = true; - if(param.items) - str = this.getType(param.items); - } - if(param.$ref) - str = param.$ref; - - var schema = param.schema; - if(schema) { - var ref = schema.$ref; - if(ref) { - ref = simpleRef(ref); - if(isArray) - return [ ref ]; - else - return ref; - } - else - return this.getType(schema); - } - if(isArray) - return [ str ]; - else - return str; -}; - -Operation.prototype.resolveModel = function (schema, definitions) { - if(typeof schema.$ref !== 'undefined') { - var ref = schema.$ref; - if(ref.indexOf('#/definitions/') === 0) - ref = ref.substring('#/definitions/'.length); - if(definitions[ref]) { - return new Model(ref, definitions[ref]); - } - } - if(schema.type === 'array') - return new ArrayModel(schema); - else - return null; -}; - -Operation.prototype.help = function(dontPrint) { - var out = this.nickname + ': ' + this.summary + '\n'; - for(var i = 0; i < this.parameters.length; i++) { - var param = this.parameters[i]; - var typeInfo = typeFromJsonSchema(param.type, param.format); - out += '\n * ' + param.name + ' (' + typeInfo + '): ' + param.description; - } - if(typeof dontPrint === 'undefined') - log(out); - return out; -}; - -Operation.prototype.getSignature = function(type, models) { - var isPrimitive, listType; - - if(type instanceof Array) { - listType = true; - type = type[0]; - } - - if(type === 'string') - isPrimitive = true; - else - isPrimitive = (listType && models[listType]) || (models[type]) ? false : true; - if (isPrimitive) { - return type; - } else { - if (listType) - return models[type].getMockSignature(); - else - return models[type].getMockSignature(); - } -}; - -Operation.prototype.supportHeaderParams = function () { - return true; -}; - -Operation.prototype.supportedSubmitMethods = function () { - return this.parent.supportedSubmitMethods; -}; - -Operation.prototype.getHeaderParams = function (args) { - var headers = this.setContentTypes(args, {}); - for(var i = 0; i < this.parameters.length; i++) { - var param = this.parameters[i]; - if(typeof args[param.name] !== 'undefined') { - if (param.in === 'header') { - var value = args[param.name]; - if(Array.isArray(value)) - value = this.encodePathCollection(param.collectionFormat, param.name, value); - else - value = this.encodePathParam(value); - headers[param.name] = value; - } - } - } - return headers; -}; - -Operation.prototype.urlify = function (args) { - var formParams = {}; - var requestUrl = this.path; - - // grab params from the args, build the querystring along the way - var querystring = ''; - for(var i = 0; i < this.parameters.length; i++) { - var param = this.parameters[i]; - if(typeof args[param.name] !== 'undefined') { - if(param.in === 'path') { - var reg = new RegExp('\{' + param.name + '\}', 'gi'); - var value = args[param.name]; - if(Array.isArray(value)) - value = this.encodePathCollection(param.collectionFormat, param.name, value); - else - value = this.encodePathParam(value); - requestUrl = requestUrl.replace(reg, value); - } - else if (param.in === 'query' && typeof args[param.name] !== 'undefined') { - if(querystring === '') - querystring += '?'; - else - querystring += '&'; - if(typeof param.collectionFormat !== 'undefined') { - var qp = args[param.name]; - if(Array.isArray(qp)) - querystring += this.encodeQueryCollection(param.collectionFormat, param.name, qp); - else - querystring += this.encodeQueryParam(param.name) + '=' + this.encodeQueryParam(args[param.name]); - } - else - querystring += this.encodeQueryParam(param.name) + '=' + this.encodeQueryParam(args[param.name]); - } - else if (param.in === 'formData') - formParams[param.name] = args[param.name]; - } - } - var url = this.scheme + '://' + this.host; - - if(this.basePath !== '/') - url += this.basePath; - - return url + requestUrl + querystring; -}; - -Operation.prototype.getMissingParams = function(args) { - var missingParams = []; - // check required params, track the ones that are missing - var i; - for(i = 0; i < this.parameters.length; i++) { - var param = this.parameters[i]; - if(param.required === true) { - if(typeof args[param.name] === 'undefined') - missingParams = param.name; - } - } - return missingParams; -}; - -Operation.prototype.getBody = function(headers, args) { - var formParams = {}; - var body; - - for(var i = 0; i < this.parameters.length; i++) { - var param = this.parameters[i]; - if(typeof args[param.name] !== 'undefined') { - if (param.in === 'body') { - body = args[param.name]; - } else if(param.in === 'formData') { - formParams[param.name] = args[param.name]; - } - } - } - - // handle form params - if(headers['Content-Type'] === 'application/x-www-form-urlencoded') { - var encoded = ""; - var key; - for(key in formParams) { - value = formParams[key]; - if(typeof value !== 'undefined'){ - if(encoded !== "") - encoded += "&"; - encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value); - } - } - body = encoded; - } - - return body; -}; - -/** - * gets sample response for a single operation - **/ -Operation.prototype.getSampleJSON = function(type, models) { - var isPrimitive, listType, sampleJson; - - listType = (type instanceof Array); - isPrimitive = models[type] ? false : true; - sampleJson = isPrimitive ? void 0 : models[type].createJSONSample(); - if (sampleJson) { - sampleJson = listType ? [sampleJson] : sampleJson; - if(typeof sampleJson == 'string') - return sampleJson; - else if(typeof sampleJson === 'object') { - var t = sampleJson; - if(sampleJson instanceof Array && sampleJson.length > 0) { - t = sampleJson[0]; - } - if(t.nodeName) { - var xmlString = new XMLSerializer().serializeToString(t); - return this.formatXml(xmlString); - } - else - return JSON.stringify(sampleJson, null, 2); - } - else - return sampleJson; - } -}; - -/** - * legacy binding - **/ -Operation.prototype["do"] = function(args, opts, callback, error, parent) { - return this.execute(args, opts, callback, error, parent); -}; - - -/** - * executes an operation - **/ -Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) { - var args = arg1 || {}; - var opts = {}, success, error; - if(typeof arg2 === 'object') { - opts = arg2; - success = arg3; - error = arg4; - } - - if(typeof arg2 === 'function') { - success = arg2; - error = arg3; - } - - success = (success||log); - error = (error||log); - - if(typeof opts.useJQuery === 'boolean') { - this.useJQuery = opts.useJQuery; - } - - var missingParams = this.getMissingParams(args); - if(missingParams.length > 0) { - var message = 'missing required params: ' + missingParams; - fail(message); - return; - } - var headers = this.getHeaderParams(args); - headers = this.setContentTypes(args, opts); - var body = this.getBody(headers, args); - var url = this.urlify(args); - - var obj = { - url: url, - method: this.method.toUpperCase(), - body: body, - useJQuery: this.useJQuery, - headers: headers, - on: { - response: function(response) { - return success(response, parent); - }, - error: function(response) { - return error(response, parent); - } - } - }; - var status = e.authorizations.apply(obj, this.operation.security); - if(opts.mock === true) - return obj; - else - new SwaggerHttp().execute(obj); -}; - -Operation.prototype.setContentTypes = function(args, opts) { - // default type - var accepts = 'application/json'; - var consumes = args.parameterContentType || 'application/json'; - - var allDefinedParams = this.parameters; - var definedFormParams = []; - var definedFileParams = []; - var body; - var headers = {}; - - // get params from the operation and set them in definedFileParams, definedFormParams, headers - var i; - for(i = 0; i < allDefinedParams.length; i++) { - var param = allDefinedParams[i]; - if(param.in === 'formData') { - if(param.type === 'file') - definedFileParams.push(param); - else - definedFormParams.push(param); - } - else if(param.in === 'header' && this.headers) { - var key = param.name; - var headerValue = this.headers[param.name]; - if(typeof this.headers[param.name] !== 'undefined') - headers[key] = headerValue; - } - else if(param.in === 'body' && typeof args[param.name] !== 'undefined') { - body = args[param.name]; - } - } - - // if there's a body, need to set the consumes header via requestContentType - if (body && (this.method === 'post' || this.method === 'put' || this.method === 'patch' || this.method === 'delete')) { - if (opts.requestContentType) - consumes = opts.requestContentType; - } else { - // if any form params, content type must be set - if(definedFormParams.length > 0) { - if(opts.requestContentType) // override if set - consumes = opts.requestContentType; - else if(definedFileParams.length > 0) // if a file, must be multipart/form-data - consumes = 'multipart/form-data'; - else // default to x-www-from-urlencoded - consumes = 'application/x-www-form-urlencoded'; - } - else if (this.type == 'DELETE') - body = '{}'; - else if (this.type != 'DELETE') - consumes = null; - } - - if (consumes && this.consumes) { - if (this.consumes.indexOf(consumes) === -1) { - log('server doesn\'t consume ' + consumes + ', try ' + JSON.stringify(this.consumes)); - } - } - - if (opts.responseContentType) { - accepts = opts.responseContentType; - } else { - accepts = 'application/json'; - } - if (accepts && this.produces) { - if (this.produces.indexOf(accepts) === -1) { - log('server can\'t produce ' + accepts); - } - } - - if ((consumes && body !== '') || (consumes === 'application/x-www-form-urlencoded')) - headers['Content-Type'] = consumes; - if (accepts) - headers.Accept = accepts; - return headers; -}; - -Operation.prototype.asCurl = function (args) { - var results = []; - var headers = this.getHeaderParams(args); - if (headers) { - var key; - for (key in headers) - results.push("--header \"" + key + ": " + headers[key] + "\""); - } - return "curl " + (results.join(" ")) + " " + this.urlify(args); -}; - -Operation.prototype.encodePathCollection = function(type, name, value) { - var encoded = ''; - var i; - var separator = ''; - if(type === 'ssv') - separator = '%20'; - else if(type === 'tsv') - separator = '\\t'; - else if(type === 'pipes') - separator = '|'; - else - separator = ','; - - for(i = 0; i < value.length; i++) { - if(i === 0) - encoded = this.encodeQueryParam(value[i]); - else - encoded += separator + this.encodeQueryParam(value[i]); - } - return encoded; -}; - -Operation.prototype.encodeQueryCollection = function(type, name, value) { - var encoded = ''; - var i; - if(type === 'default' || type === 'multi') { - for(i = 0; i < value.length; i++) { - if(i > 0) encoded += '&'; - encoded += this.encodeQueryParam(name) + '=' + this.encodeQueryParam(value[i]); - } - } - else { - var separator = ''; - if(type === 'csv') - separator = ','; - else if(type === 'ssv') - separator = '%20'; - else if(type === 'tsv') - separator = '\\t'; - else if(type === 'pipes') - separator = '|'; - else if(type === 'brackets') { - for(i = 0; i < value.length; i++) { - if(i !== 0) - encoded += '&'; - encoded += this.encodeQueryParam(name) + '[]=' + this.encodeQueryParam(value[i]); - } - } - if(separator !== '') { - for(i = 0; i < value.length; i++) { - if(i === 0) - encoded = this.encodeQueryParam(name) + '=' + this.encodeQueryParam(value[i]); - else - encoded += separator + this.encodeQueryParam(value[i]); - } - } - } - return encoded; -}; - -Operation.prototype.encodeQueryParam = function(arg) { - return encodeURIComponent(arg); -}; - -/** - * TODO revisit, might not want to leave '/' - **/ -Operation.prototype.encodePathParam = function(pathParam) { - var encParts, part, parts, i, len; - pathParam = pathParam.toString(); - if (pathParam.indexOf('/') === -1) { - return encodeURIComponent(pathParam); - } else { - parts = pathParam.split('/'); - encParts = []; - for (i = 0, len = parts.length; i < len; i++) { - encParts.push(encodeURIComponent(parts[i])); - } - return encParts.join('/'); - } -}; - -var Model = function(name, definition) { - this.name = name; - this.definition = definition || {}; - this.properties = []; - var requiredFields = definition.required || []; - if(definition.type === 'array') { - var out = new ArrayModel(definition); - return out; - } - var key; - var props = definition.properties; - if(props) { - for(key in props) { - var required = false; - var property = props[key]; - if(requiredFields.indexOf(key) >= 0) - required = true; - this.properties.push(new Property(key, property, required)); - } - } -}; - -Model.prototype.createJSONSample = function(modelsToIgnore) { - var result = {}; - modelsToIgnore = (modelsToIgnore||{}); - modelsToIgnore[this.name] = this; - var i; - for (i = 0; i < this.properties.length; i++) { - prop = this.properties[i]; - result[prop.name] = prop.getSampleValue(modelsToIgnore); - } - delete modelsToIgnore[this.name]; - return result; -}; - -Model.prototype.getSampleValue = function(modelsToIgnore) { - var i; - var obj = {}; - for(i = 0; i < this.properties.length; i++ ) { - var property = this.properties[i]; - obj[property.name] = property.sampleValue(false, modelsToIgnore); - } - return obj; -}; - -Model.prototype.getMockSignature = function(modelsToIgnore) { - var propertiesStr = []; - var i, prop; - for (i = 0; i < this.properties.length; i++) { - prop = this.properties[i]; - propertiesStr.push(prop.toString()); - } - - var strong = ''; - var stronger = ''; - var strongClose = ''; - var classOpen = strong + this.name + ' {' + strongClose; - var classClose = strong + '}' + strongClose; - var returnVal = classOpen + '
' + propertiesStr.join(',
') + '
' + classClose; - if (!modelsToIgnore) - modelsToIgnore = {}; - - modelsToIgnore[this.name] = this; - for (i = 0; i < this.properties.length; i++) { - prop = this.properties[i]; - var ref = prop.$ref; - var model = models[ref]; - if (model && typeof modelsToIgnore[model.name] === 'undefined') { - returnVal = returnVal + ('
' + model.getMockSignature(modelsToIgnore)); - } - } - return returnVal; -}; - -var Property = function(name, obj, required) { - this.schema = obj; - this.required = required; - if(obj.$ref) - this.$ref = simpleRef(obj.$ref); - else if (obj.type === 'array') { - if(obj.items.$ref) - this.$ref = simpleRef(obj.items.$ref); - else - obj = obj.items; - } - this.name = name; - this.description = obj.description; - this.obj = obj; - this.optional = true; - this.optional = !required; - this.default = obj.default || null; - this.example = obj.example || null; - this.collectionFormat = obj.collectionFormat || null; - this.maximum = obj.maximum || null; - this.exclusiveMaximum = obj.exclusiveMaximum || null; - this.minimum = obj.minimum || null; - this.exclusiveMinimum = obj.exclusiveMinimum || null; - this.maxLength = obj.maxLength || null; - this.minLength = obj.minLength || null; - this.pattern = obj.pattern || null; - this.maxItems = obj.maxItems || null; - this.minItems = obj.minItems || null; - this.uniqueItems = obj.uniqueItems || null; - this['enum'] = obj['enum'] || null; - this.multipleOf = obj.multipleOf || null; -}; - -Property.prototype.getSampleValue = function (modelsToIgnore) { - return this.sampleValue(false, modelsToIgnore); -}; - -Property.prototype.isArray = function () { - var schema = this.schema; - if(schema.type === 'array') - return true; - else - return false; -}; - -Property.prototype.sampleValue = function(isArray, ignoredModels) { - isArray = (isArray || this.isArray()); - ignoredModels = (ignoredModels || {}); - var type = getStringSignature(this.obj); - var output; - - if(this.$ref) { - var refModelName = simpleRef(this.$ref); - var refModel = models[refModelName]; - if(refModel && typeof ignoredModels[type] === 'undefined') { - ignoredModels[type] = this; - output = refModel.getSampleValue(ignoredModels); - } - else - type = refModel; - } - else if(this.example) - output = this.example; - else if(this.default) - output = this.default; - else if(type === 'date-time') - output = new Date().toISOString(); - else if(type === 'string') - output = 'string'; - else if(type === 'integer') - output = 0; - else if(type === 'long') - output = 0; - else if(type === 'float') - output = 0.0; - else if(type === 'double') - output = 0.0; - else if(type === 'boolean') - output = true; - else - output = {}; - ignoredModels[type] = output; - if(isArray) - return [output]; - else - return output; -}; - -getStringSignature = function(obj) { - var str = ''; - if(typeof obj.type === 'undefined') - str += obj; - else if(obj.type === 'array') { - str += 'Array['; - str += getStringSignature((obj.items || obj.$ref || {})); - str += ']'; - } - else if(obj.type === 'integer' && obj.format === 'int32') - str += 'integer'; - else if(obj.type === 'integer' && obj.format === 'int64') - str += 'long'; - else if(obj.type === 'integer' && typeof obj.format === 'undefined') - str += 'long'; - else if(obj.type === 'string' && obj.format === 'date-time') - str += 'date-time'; - else if(obj.type === 'string' && obj.format === 'date') - str += 'date'; - else if(obj.type === 'string' && typeof obj.format === 'undefined') - str += 'string'; - else if(obj.type === 'number' && obj.format === 'float') - str += 'float'; - else if(obj.type === 'number' && obj.format === 'double') - str += 'double'; - else if(obj.type === 'number' && typeof obj.format === 'undefined') - str += 'double'; - else if(obj.type === 'boolean') - str += 'boolean'; - else if(obj.$ref) - str += simpleRef(obj.$ref); - else - str += obj.type; - return str; -}; - -simpleRef = function(name) { - if(typeof name === 'undefined') - return null; - if(name.indexOf("#/definitions/") === 0) - return name.substring('#/definitions/'.length); - else - return name; -}; - -Property.prototype.toString = function() { - var str = getStringSignature(this.obj); - if(str !== '') { - str = '' + this.name + ' (' + str + ''; - if(!this.required) - str += ', optional'; - str += ')'; - } - else - str = this.name + ' (' + JSON.stringify(this.obj) + ')'; - - if(typeof this.description !== 'undefined') - str += ': ' + this.description; - - var options = ''; - var isArray = this.schema.type === 'array'; - var type = isArray ? this.schema.items.type : this.schema.type; - - if (this.default) - options += optionHtml('Default', this.default); - - switch (type) { - case 'string': - if (this.minLength) - options += optionHtml('Min. Length', this.minLength); - if (this.maxLength) - options += optionHtml('Max. Length', this.maxLength); - if (this.pattern) - options += optionHtml('Reg. Exp.', this.pattern); - break; - case 'integer': - case 'number': - if (this.minimum) - options += optionHtml('Min. Value', this.minimum); - if (this.exclusiveMinimum) - options += optionHtml('Exclusive Min.', "true"); - if (this.maximum) - options += optionHtml('Max. Value', this.maximum); - if (this.exclusiveMaximum) - options += optionHtml('Exclusive Max.', "true"); - if (this.multipleOf) - options += optionHtml('Multiple Of', this.multipleOf); - break; - } - - if (isArray) { - if (this.minItems) - options += optionHtml('Min. Items', this.minItems); - if (this.maxItems) - options += optionHtml('Max. Items', this.maxItems); - if (this.uniqueItems) - options += optionHtml('Unique Items', "true"); - if (this.collectionFormat) - options += optionHtml('Coll. Format', this.collectionFormat); - } - - if (this['enum']) { - var enumString; - - if (type === 'number' || type === 'integer') - enumString = this['enum'].join(', '); - else { - enumString = '"' + this['enum'].join('", "') + '"'; - } - - options += optionHtml('Enum', enumString); - } - - if (options.length > 0) - str = '' + str + '' + options + '
' + this.name + '
'; - - return str; -}; - -optionHtml = function(label, value) { - return '' + label + ':' + value + ''; -} - -typeFromJsonSchema = function(type, format) { - var str; - if(type === 'integer' && format === 'int32') - str = 'integer'; - else if(type === 'integer' && format === 'int64') - str = 'long'; - else if(type === 'integer' && typeof format === 'undefined') - str = 'long'; - else if(type === 'string' && format === 'date-time') - str = 'date-time'; - else if(type === 'string' && format === 'date') - str = 'date'; - else if(type === 'number' && format === 'float') - str = 'float'; - else if(type === 'number' && format === 'double') - str = 'double'; - else if(type === 'number' && typeof format === 'undefined') - str = 'double'; - else if(type === 'boolean') - str = 'boolean'; - else if(type === 'string') - str = 'string'; - - return str; -}; - -var sampleModels = {}; -var cookies = {}; -var models = {}; - /** * SwaggerHttp is a wrapper for executing requests */ @@ -2970,5 +2885,5 @@ e.CookieAuthorization = CookieAuthorization; e.SwaggerClient = SwaggerClient; e.Operation = Operation; e.Model = Model; -e.SwaggerApi = SwaggerApi; +e.models = models; })(); \ No newline at end of file diff --git a/dist/swagger-ui.js b/dist/swagger-ui.js index 34f3b391..57c05f50 100644 --- a/dist/swagger-ui.js +++ b/dist/swagger-ui.js @@ -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 "\n
\n
\n
" - + 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))) - + "
\n \n \n
\n
\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; @@ -246,13 +238,7 @@ SwaggerUi = (function(_super) { })(this); this.options.failure = (function(_this) { return function(d) { - if (_this.api && _this.api.isValid === false) { - log("not a valid 2.0 spec, loading legacy client"); - _this.api = new SwaggerApi(_this.options); - return _this.api.build(); - } else { - return _this.onLoadFailure(d); - } + return _this.onLoadFailure(d); }; })(this); this.headerView = new HeaderView({ @@ -391,6 +377,43 @@ SwaggerUi = (function(_super) { window.SwaggerUi = SwaggerUi; +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 "\n
\n
\n
" + + 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))) + + "
\n \n \n
\n
\n\n"; +},"useData":true}); +Handlebars.registerHelper('sanitize', function(html) { + html = html.replace(/)<[^<]*)*<\/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 "
\n
\n
\n
Username
\n \n
Password
\n \n \n
\n
\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}); + if (stack1 != null) { buffer += stack1; } + return buffer; +},"2":function(depth0,helpers,partials,data) { + var stack1, lambda=this.lambda, buffer = " \n"; +},"4":function(depth0,helpers,partials,data) { + return " \n"; + },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { + var stack1, buffer = "\n\n"; +},"useData":true}); var ApiKeyButton, __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; @@ -444,115 +467,6 @@ ApiKeyButton = (function(_super) { })(Backbone.View); -this["Handlebars"]["templates"]["basic_auth_button_view"] = Handlebars.template({"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { - return "
\n
\n
\n
Username
\n \n
Password
\n \n \n
\n
\n\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; - console.log("applying password"); - 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"]["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 = " \n"; -},"4":function(depth0,helpers,partials,data) { - return " \n"; - },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { - var stack1, buffer = "\n\n"; -},"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"]["main"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { var stack1, lambda=this.lambda, escapeExpression=this.escapeExpression, buffer = "
" + escapeExpression(lambda(((stack1 = (depth0 != null ? depth0.info : depth0)) != null ? stack1.title : stack1), depth0)) @@ -636,68 +550,59 @@ this["Handlebars"]["templates"]["main"] = Handlebars.template({"1":function(dept if (stack1 != null) { buffer += stack1; } return buffer + " \n
\n\n"; },"useData":true}); -var HeaderView, +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; -HeaderView = (function(_super) { - __extends(HeaderView, _super); +BasicAuthButton = (function(_super) { + __extends(BasicAuthButton, _super); - function HeaderView() { - return HeaderView.__super__.constructor.apply(this, arguments); + function BasicAuthButton() { + return BasicAuthButton.__super__.constructor.apply(this, arguments); } - HeaderView.prototype.events = { - 'click #show-pet-store-icon': 'showPetStore', - 'click #show-wordnik-dev-icon': 'showWordnikDev', - 'click #explore': 'showCustom', - 'keyup #input_baseUrl': 'showCustomOnKeyup', - 'keyup #input_apiKey': 'showCustomOnKeyup' + BasicAuthButton.prototype.initialize = function() {}; + + BasicAuthButton.prototype.render = function() { + var template; + template = this.template(); + $(this.el).html(template(this.model)); + return this; }; - HeaderView.prototype.initialize = function() {}; - - HeaderView.prototype.showPetStore = function(e) { - return this.trigger('update-swagger-ui', { - url: "http://petstore.swagger.wordnik.com/api/api-docs" - }); + BasicAuthButton.prototype.events = { + "click #basic_auth_button": "togglePasswordContainer", + "click #apply_basic_auth": "applyPassword" }; - HeaderView.prototype.showWordnikDev = function(e) { - return this.trigger('update-swagger-ui', { - url: "http://api.wordnik.com/v4/resources.json" - }); + BasicAuthButton.prototype.applyPassword = function() { + var elem, password, username; + console.log("applying password"); + 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(); }; - HeaderView.prototype.showCustomOnKeyup = function(e) { - if (e.keyCode === 13) { - return this.showCustom(); + 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(); + } } }; - HeaderView.prototype.showCustom = function(e) { - if (e != null) { - e.preventDefault(); - } - return this.trigger('update-swagger-ui', { - url: $('#input_baseUrl').val(), - apiKey: $('#input_apiKey').val() - }); + BasicAuthButton.prototype.template = function() { + return Handlebars.templates.basic_auth_button_view; }; - HeaderView.prototype.update = function(url, apiKey, trigger) { - if (trigger == null) { - trigger = false; - } - $('#input_baseUrl').val(url); - if (trigger) { - return this.trigger('update-swagger-ui', { - url: url - }); - } - }; - - return HeaderView; + return BasicAuthButton; })(Backbone.View); @@ -801,6 +706,219 @@ this["Handlebars"]["templates"]["operation"] = Handlebars.template({"1":function if (stack1 != null) { buffer += stack1; } return buffer + " \n \n \n \n \n"; },"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) { + 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}); + if (stack1 != null) { buffer += stack1; } + return buffer; +},"2":function(depth0,helpers,partials,data) { + var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; + return " \n
\n"; +},"4":function(depth0,helpers,partials,data) { + var stack1, buffer = ""; + stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(5, data),"inverse":this.program(7, data),"data":data}); + if (stack1 != null) { buffer += stack1; } + return buffer; +},"5":function(depth0,helpers,partials,data) { + var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; + return " \n
\n
\n"; +},"7":function(depth0,helpers,partials,data) { + var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; + return " \n
\n
\n"; +},"9":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(10, data),"data":data}); + if (stack1 != null) { buffer += stack1; } + return buffer; +},"10":function(depth0,helpers,partials,data) { + var stack1, buffer = ""; + stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(11, data),"inverse":this.program(13, data),"data":data}); + if (stack1 != null) { buffer += stack1; } + return buffer; +},"11":function(depth0,helpers,partials,data) { + var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; + return " \n"; +},"13":function(depth0,helpers,partials,data) { + var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; + return " \n"; +},"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 = "" + + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper))) + + "\n\n\n"; + stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isBody : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(9, data),"data":data}); + if (stack1 != null) { buffer += stack1; } + buffer += "\n\n"; + stack1 = ((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper)); + if (stack1 != null) { buffer += stack1; } + buffer += "\n"; + stack1 = ((helper = (helper = helpers.paramType || (depth0 != null ? depth0.paramType : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"paramType","hash":{},"data":data}) : helper)); + if (stack1 != null) { buffer += stack1; } + return buffer + "\n\n \n\n"; +},"useData":true}); +var HeaderView, + __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; + +HeaderView = (function(_super) { + __extends(HeaderView, _super); + + function HeaderView() { + return HeaderView.__super__.constructor.apply(this, arguments); + } + + HeaderView.prototype.events = { + 'click #show-pet-store-icon': 'showPetStore', + 'click #show-wordnik-dev-icon': 'showWordnikDev', + 'click #explore': 'showCustom', + 'keyup #input_baseUrl': 'showCustomOnKeyup', + 'keyup #input_apiKey': 'showCustomOnKeyup' + }; + + HeaderView.prototype.initialize = function() {}; + + HeaderView.prototype.showPetStore = function(e) { + return this.trigger('update-swagger-ui', { + url: "http://petstore.swagger.wordnik.com/api/api-docs" + }); + }; + + HeaderView.prototype.showWordnikDev = function(e) { + return this.trigger('update-swagger-ui', { + url: "http://api.wordnik.com/v4/resources.json" + }); + }; + + HeaderView.prototype.showCustomOnKeyup = function(e) { + if (e.keyCode === 13) { + return this.showCustom(); + } + }; + + HeaderView.prototype.showCustom = function(e) { + if (e != null) { + e.preventDefault(); + } + return this.trigger('update-swagger-ui', { + url: $('#input_baseUrl').val(), + apiKey: $('#input_apiKey').val() + }); + }; + + HeaderView.prototype.update = function(url, apiKey, trigger) { + if (trigger == null) { + trigger = false; + } + $('#input_baseUrl').val(url); + if (trigger) { + return this.trigger('update-swagger-ui', { + url: url + }); + } + }; + + return HeaderView; + +})(Backbone.View); + +this["Handlebars"]["templates"]["param_list"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { + return " multiple='multiple'"; + },"3":function(depth0,helpers,partials,data) { + return ""; +},"5":function(depth0,helpers,partials,data) { + var stack1, buffer = ""; + stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(3, data),"inverse":this.program(6, data),"data":data}); + if (stack1 != null) { buffer += stack1; } + return buffer; +},"6":function(depth0,helpers,partials,data) { + var stack1, helperMissing=helpers.helperMissing, buffer = ""; + stack1 = ((helpers.isArray || (depth0 && depth0.isArray) || helperMissing).call(depth0, depth0, {"name":"isArray","hash":{},"fn":this.program(3, data),"inverse":this.program(7, data),"data":data})); + if (stack1 != null) { buffer += stack1; } + return buffer; +},"7":function(depth0,helpers,partials,data) { + return " \n"; + },"9":function(depth0,helpers,partials,data) { + var stack1, buffer = ""; + stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isDefault : depth0), {"name":"if","hash":{},"fn":this.program(10, data),"inverse":this.program(12, data),"data":data}); + if (stack1 != null) { buffer += stack1; } + return buffer; +},"10":function(depth0,helpers,partials,data) { + var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; + return " \n"; +},"12":function(depth0,helpers,partials,data) { + var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; + return " \n"; +},"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 = "" + + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper))) + + "\n\n \n\n"; + stack1 = ((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper)); + if (stack1 != null) { buffer += stack1; } + buffer += "\n"; + stack1 = ((helper = (helper = helpers.paramType || (depth0 != null ? depth0.paramType : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"paramType","hash":{},"data":data}) : helper)); + if (stack1 != null) { buffer += stack1; } + return buffer + "\n"; +},"useData":true}); var MainView, __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; @@ -914,68 +1032,38 @@ MainView = (function(_super) { })(Backbone.View); -this["Handlebars"]["templates"]["param"] = 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}); - if (stack1 != null) { buffer += stack1; } - return buffer; -},"2":function(depth0,helpers,partials,data) { +this["Handlebars"]["templates"]["param_readonly"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return " \n
\n"; -},"4":function(depth0,helpers,partials,data) { - var stack1, buffer = ""; - stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(5, data),"inverse":this.program(7, data),"data":data}); - if (stack1 != null) { buffer += stack1; } - return buffer; -},"5":function(depth0,helpers,partials,data) { - var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return " \n
\n
\n"; -},"7":function(depth0,helpers,partials,data) { - var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return " \n
\n
\n"; -},"9":function(depth0,helpers,partials,data) { + + "\n"; +},"3":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(10, data),"data":data}); + stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(4, data),"inverse":this.program(6, data),"data":data}); if (stack1 != null) { buffer += stack1; } return buffer; -},"10":function(depth0,helpers,partials,data) { - var stack1, buffer = ""; - stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(11, data),"inverse":this.program(13, data),"data":data}); - if (stack1 != null) { buffer += stack1; } - return buffer; -},"11":function(depth0,helpers,partials,data) { +},"4":function(depth0,helpers,partials,data) { var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return " \n"; -},"13":function(depth0,helpers,partials,data) { - var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return " \n"; -},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { + + "\n"; +},"6":function(depth0,helpers,partials,data) { + return " (empty)\n"; + },"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 = "" + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper))) - + "\n\n\n"; - stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isBody : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(9, data),"data":data}); + + "\n\n"; + stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isBody : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(3, data),"data":data}); if (stack1 != null) { buffer += stack1; } - buffer += "\n\n"; + buffer += "\n"; stack1 = ((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper)); if (stack1 != null) { buffer += stack1; } buffer += "\n"; stack1 = ((helper = (helper = helpers.paramType || (depth0 != null ? depth0.paramType : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"paramType","hash":{},"data":data}) : helper)); if (stack1 != null) { buffer += stack1; } - return buffer + "\n\n \n\n"; + return buffer + "\n\n"; },"useData":true}); var OperationView, __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; }, @@ -1042,7 +1130,7 @@ OperationView = (function(_super) { }; OperationView.prototype.render = function() { - var a, auth, auths, code, contentTypeModel, isMethodSubmissionSupported, k, key, modelAuths, o, param, ref, responseContentTypeView, responseSignatureView, schema, schemaObj, scopeIndex, signatureModel, statusCode, type, v, value, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4; + var a, auth, auths, code, contentTypeModel, foo, isMethodSubmissionSupported, k, key, modelAuths, o, param, ref, responseContentTypeView, responseSignatureView, schema, schemaObj, scopeIndex, signatureModel, statusCode, successResponse, type, v, value, _i, _j, _k, _l, _len, _len1, _len2, _len3, _len4, _m, _ref, _ref1, _ref2, _ref3, _ref4; isMethodSubmissionSupported = true; if (!isMethodSubmissionSupported) { this.model.isReadOnly = true; @@ -1122,12 +1210,28 @@ OperationView = (function(_super) { this.model.responseMessages = []; } $(this.el).html(Handlebars.templates.operation(this.model)); - if (this.model.responseClassSignature && this.model.responseClassSignature !== 'string') { + signatureModel = null; + if (this.model.successResponse) { + successResponse = this.model.successResponse; + for (key in successResponse) { + value = successResponse[key]; + if (typeof value === 'object' && typeof value.createJSONSample === 'function') { + foo = 'bar'; + signatureModel = { + sampleJSON: JSON.stringify(value.createJSONSample(), void 0, 2), + isParam: false, + signature: value.getMockSignature() + }; + } + } + } else if (this.model.responseClassSignature && this.model.responseClassSignature !== 'string') { signatureModel = { sampleJSON: this.model.responseSampleJSON, isParam: false, signature: this.model.responseClassSignature }; + } + if (signatureModel) { responseSignatureView = new SignatureView({ model: signatureModel, tagName: 'div' @@ -1572,6 +1676,39 @@ OperationView = (function(_super) { })(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 " \n"; +},"3":function(depth0,helpers,partials,data) { + var stack1, buffer = ""; + stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(4, data),"inverse":this.program(6, data),"data":data}); + if (stack1 != null) { buffer += stack1; } + return buffer; +},"4":function(depth0,helpers,partials,data) { + var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; + return " " + + escapeExpression(((helper = (helper = helpers['default'] || (depth0 != null ? depth0['default'] : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"default","hash":{},"data":data}) : helper))) + + "\n"; +},"6":function(depth0,helpers,partials,data) { + return " (empty)\n"; + },"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 = "" + + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper))) + + "\n\n"; + stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isBody : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(3, data),"data":data}); + if (stack1 != null) { buffer += stack1; } + buffer += "\n"; + stack1 = ((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper)); + if (stack1 != null) { buffer += stack1; } + buffer += "\n"; + stack1 = ((helper = (helper = helpers.paramType || (depth0 != null ? depth0.paramType : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"paramType","hash":{},"data":data}) : helper)); + if (stack1 != null) { buffer += stack1; } + return buffer + "\n\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; @@ -1601,61 +1738,73 @@ ParameterContentTypeView = (function(_super) { })(Backbone.View); -this["Handlebars"]["templates"]["param_list"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { - return " multiple='multiple'"; - },"3":function(depth0,helpers,partials,data) { - return ""; +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}); + if (stack1 != null) { buffer += stack1; } + return buffer; +},"2":function(depth0,helpers,partials,data) { + var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; + return " \n"; +},"4":function(depth0,helpers,partials,data) { + var stack1, buffer = ""; + stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(5, data),"inverse":this.program(7, data),"data":data}); + if (stack1 != null) { buffer += stack1; } + return buffer; },"5":function(depth0,helpers,partials,data) { - var stack1, buffer = ""; - stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(3, data),"inverse":this.program(6, data),"data":data}); - if (stack1 != null) { buffer += stack1; } - return buffer; -},"6":function(depth0,helpers,partials,data) { - var stack1, helperMissing=helpers.helperMissing, buffer = ""; - stack1 = ((helpers.isArray || (depth0 && depth0.isArray) || helperMissing).call(depth0, depth0, {"name":"isArray","hash":{},"fn":this.program(3, data),"inverse":this.program(7, data),"data":data})); - if (stack1 != null) { buffer += stack1; } - return buffer; + var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; + return " \n
\n
\n"; },"7":function(depth0,helpers,partials,data) { - return " \n"; - },"9":function(depth0,helpers,partials,data) { + var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; + return " \n
\n
\n"; +},"9":function(depth0,helpers,partials,data) { var stack1, buffer = ""; - stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isDefault : depth0), {"name":"if","hash":{},"fn":this.program(10, data),"inverse":this.program(12, data),"data":data}); + stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isFile : depth0), {"name":"if","hash":{},"fn":this.program(10, data),"inverse":this.program(12, data),"data":data}); if (stack1 != null) { buffer += stack1; } return buffer; },"10":function(depth0,helpers,partials,data) { var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return " \n"; + return " \n"; },"12":function(depth0,helpers,partials,data) { + var stack1, buffer = ""; + stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(13, data),"inverse":this.program(15, data),"data":data}); + if (stack1 != null) { buffer += stack1; } + return buffer; +},"13":function(depth0,helpers,partials,data) { var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return " \n"; + return " \n"; +},"15":function(depth0,helpers,partials,data) { + var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; + return " \n"; },"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 = "" + var stack1, helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, buffer = "" + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper))) - + "\n\n \n\n"; + buffer += "\n\n "; stack1 = ((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper)); if (stack1 != null) { buffer += stack1; } - buffer += "\n"; + buffer += "\n\n"; stack1 = ((helper = (helper = helpers.paramType || (depth0 != null ? depth0.paramType : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"paramType","hash":{},"data":data}) : helper)); if (stack1 != null) { buffer += stack1; } - return buffer + "\n"; + return buffer + "\n\n"; },"useData":true}); var ParameterView, __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; }, @@ -1766,38 +1915,26 @@ ParameterView = (function(_super) { })(Backbone.View); -this["Handlebars"]["templates"]["param_readonly"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { - var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return " \n"; -},"3":function(depth0,helpers,partials,data) { +this["Handlebars"]["templates"]["parameter_content_type"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { var stack1, buffer = ""; - stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(4, data),"inverse":this.program(6, data),"data":data}); + stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.consumes : 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 = " \n"; },"4":function(depth0,helpers,partials,data) { - var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return " " - + escapeExpression(((helper = (helper = helpers['default'] || (depth0 != null ? depth0['default'] : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"default","hash":{},"data":data}) : helper))) - + "\n"; -},"6":function(depth0,helpers,partials,data) { - return " (empty)\n"; + return " \n"; },"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 = "" - + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper))) - + "\n\n"; - stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isBody : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(3, data),"data":data}); + var stack1, buffer = "\n\n"; },"useData":true}); var ResourceView, __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; }, @@ -1870,38 +2007,43 @@ ResourceView = (function(_super) { })(Backbone.View); -this["Handlebars"]["templates"]["param_readonly_required"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { +this["Handlebars"]["templates"]["resource"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { + return " : "; + },"3":function(depth0,helpers,partials,data) { var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return " \n"; -},"3":function(depth0,helpers,partials,data) { - var stack1, buffer = ""; - stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(4, data),"inverse":this.program(6, data),"data":data}); + + " "; + stack1 = ((helper = (helper = helpers.summary || (depth0 != null ? depth0.summary : depth0)) != null ? helper : helperMissing),(options={"name":"summary","hash":{},"fn":this.program(1, data),"inverse":this.noop,"data":data}),(typeof helper === functionType ? helper.call(depth0, options) : helper)); + if (!helpers.summary) { stack1 = blockHelperMissing.call(depth0, stack1, options); } if (stack1 != null) { buffer += stack1; } - return buffer; -},"4":function(depth0,helpers,partials,data) { - var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return " " - + escapeExpression(((helper = (helper = helpers['default'] || (depth0 != null ? depth0['default'] : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"default","hash":{},"data":data}) : helper))) - + "\n"; -},"6":function(depth0,helpers,partials,data) { - return " (empty)\n"; - },"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 = "" - + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper))) - + "\n\n"; - stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isBody : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(3, data),"data":data}); + stack1 = ((helper = (helper = helpers.summary || (depth0 != null ? depth0.summary : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"summary","hash":{},"data":data}) : helper)); if (stack1 != null) { buffer += stack1; } - buffer += "\n"; - stack1 = ((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper)); + buffer += "\n \n
    \n
  • \n Show/Hide\n
  • \n
  • \n \n List Operations\n \n
  • \n
  • \n \n Expand Operations\n \n
  • \n "; + stack1 = ((helper = (helper = helpers.url || (depth0 != null ? depth0.url : depth0)) != null ? helper : helperMissing),(options={"name":"url","hash":{},"fn":this.program(3, data),"inverse":this.noop,"data":data}),(typeof helper === functionType ? helper.call(depth0, options) : helper)); + if (!helpers.url) { stack1 = blockHelperMissing.call(depth0, stack1, options); } if (stack1 != null) { buffer += stack1; } - buffer += "\n"; - stack1 = ((helper = (helper = helpers.paramType || (depth0 != null ? depth0.paramType : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"paramType","hash":{},"data":data}) : helper)); - if (stack1 != null) { buffer += stack1; } - return buffer + "\n\n"; + return buffer + "\n
\n
\n\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; }, @@ -1932,73 +2074,26 @@ ResponseContentTypeView = (function(_super) { })(Backbone.View); -this["Handlebars"]["templates"]["param_required"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { +this["Handlebars"]["templates"]["response_content_type"] = 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}); + 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 helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return " \n"; + var stack1, lambda=this.lambda, buffer = " \n"; },"4":function(depth0,helpers,partials,data) { - var stack1, buffer = ""; - stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(5, data),"inverse":this.program(7, data),"data":data}); + return " \n"; + },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { + var stack1, buffer = "\n\n
\n
\n"; -},"7":function(depth0,helpers,partials,data) { - var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return " \n
\n
\n"; -},"9":function(depth0,helpers,partials,data) { - var stack1, buffer = ""; - stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isFile : depth0), {"name":"if","hash":{},"fn":this.program(10, data),"inverse":this.program(12, data),"data":data}); - if (stack1 != null) { buffer += stack1; } - return buffer; -},"10":function(depth0,helpers,partials,data) { - var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return " \n"; -},"12":function(depth0,helpers,partials,data) { - var stack1, buffer = ""; - stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0['default'] : depth0), {"name":"if","hash":{},"fn":this.program(13, data),"inverse":this.program(15, data),"data":data}); - if (stack1 != null) { buffer += stack1; } - return buffer; -},"13":function(depth0,helpers,partials,data) { - var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return " \n"; -},"15":function(depth0,helpers,partials,data) { - var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return " \n"; -},"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 = "" - + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper))) - + "\n\n"; - stack1 = helpers['if'].call(depth0, (depth0 != null ? depth0.isBody : depth0), {"name":"if","hash":{},"fn":this.program(1, data),"inverse":this.program(9, data),"data":data}); - if (stack1 != null) { buffer += stack1; } - buffer += "\n\n "; - stack1 = ((helper = (helper = helpers.description || (depth0 != null ? depth0.description : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"description","hash":{},"data":data}) : helper)); - if (stack1 != null) { buffer += stack1; } - buffer += "\n\n"; - stack1 = ((helper = (helper = helpers.paramType || (depth0 != null ? depth0.paramType : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"paramType","hash":{},"data":data}) : helper)); - if (stack1 != null) { buffer += stack1; } - return buffer + "\n\n"; + return buffer + "\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; }, @@ -2072,26 +2167,13 @@ SignatureView = (function(_super) { })(Backbone.View); -this["Handlebars"]["templates"]["parameter_content_type"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { - var stack1, buffer = ""; - stack1 = helpers.each.call(depth0, (depth0 != null ? depth0.consumes : depth0), {"name":"each","hash":{},"fn":this.program(2, data),"inverse":this.noop,"data":data}); +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 = "
\n\n
\n\n
\n
\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; -},"2":function(depth0,helpers,partials,data) { - var stack1, lambda=this.lambda, buffer = " \n"; -},"4":function(depth0,helpers,partials,data) { - return " \n"; - },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { - var stack1, buffer = "\n\n"; + return buffer + "\n
\n\n
\n
"
+    + 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)))
+    + "
\n \n
\n
\n\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; }, @@ -2135,78 +2217,6 @@ StatusCodeView = (function(_super) { })(Backbone.View); -this["Handlebars"]["templates"]["resource"] = Handlebars.template({"1":function(depth0,helpers,partials,data) { - return " : "; - },"3":function(depth0,helpers,partials,data) { - var helper, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression; - return "
  • \n Raw\n
  • "; -},"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { - var stack1, helper, options, functionType="function", helperMissing=helpers.helperMissing, escapeExpression=this.escapeExpression, blockHelperMissing=helpers.blockHelperMissing, buffer = "
    \n

    \n " - + escapeExpression(((helper = (helper = helpers.name || (depth0 != null ? depth0.name : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"name","hash":{},"data":data}) : helper))) - + " "; - stack1 = ((helper = (helper = helpers.summary || (depth0 != null ? depth0.summary : depth0)) != null ? helper : helperMissing),(options={"name":"summary","hash":{},"fn":this.program(1, data),"inverse":this.noop,"data":data}),(typeof helper === functionType ? helper.call(depth0, options) : helper)); - if (!helpers.summary) { stack1 = blockHelperMissing.call(depth0, stack1, options); } - if (stack1 != null) { buffer += stack1; } - stack1 = ((helper = (helper = helpers.summary || (depth0 != null ? depth0.summary : depth0)) != null ? helper : helperMissing),(typeof helper === functionType ? helper.call(depth0, {"name":"summary","hash":{},"data":data}) : helper)); - if (stack1 != null) { buffer += stack1; } - buffer += "\n

    \n
      \n
    • \n Show/Hide\n
    • \n
    • \n \n List Operations\n \n
    • \n
    • \n \n Expand Operations\n \n
    • \n "; - stack1 = ((helper = (helper = helpers.url || (depth0 != null ? depth0.url : depth0)) != null ? helper : helperMissing),(options={"name":"url","hash":{},"fn":this.program(3, data),"inverse":this.noop,"data":data}),(typeof helper === functionType ? helper.call(depth0, options) : helper)); - if (!helpers.url) { stack1 = blockHelperMissing.call(depth0, stack1, options); } - if (stack1 != null) { buffer += stack1; } - return buffer + "\n
    \n
    \n\n"; -},"useData":true}); -Handlebars.registerHelper('sanitize', function(html) { - html = html.replace(/)<[^<]*)*<\/script>/gi, ''); - return new Handlebars.SafeString(html); -}); - -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 = " \n"; -},"4":function(depth0,helpers,partials,data) { - return " \n"; - },"compiler":[6,">= 2.0.0-beta.1"],"main":function(depth0,helpers,partials,data) { - var stack1, buffer = "\n\n"; -},"useData":true}); -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 = "
    \n\n
    \n\n
    \n
    \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
    \n\n
    \n
    "
    -    + 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)))
    -    + "
    \n \n
    \n
    \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 = "" + 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))) diff --git a/dist/swagger-ui.min.js b/dist/swagger-ui.min.js index 9b133a41..f0bc6af0 100644 --- a/dist/swagger-ui.min.js +++ b/dist/swagger-ui.min.js @@ -1,2 +1,2 @@ -function clippyCopiedCallback(){$("#api_key_copied").fadeIn().delay(1e3).fadeOut()}$(function(){$.fn.vAlign=function(){return this.each(function(){var e=$(this).height(),t=$(this).parent().height(),n=(t-e)/2;$(this).css("margin-top",n)})},$.fn.stretchFormtasticInputWidthToParent=function(){return this.each(function(){var e=$(this).closest("form").innerWidth(),t=parseInt($(this).closest("form").css("padding-left"),10)+parseInt($(this).closest("form").css("padding-right"),10),n=parseInt($(this).css("padding-left"),10)+parseInt($(this).css("padding-right"),10);$(this).css("width",e-t-n)})},$("form.formtastic li.string input, form.formtastic textarea").stretchFormtasticInputWidthToParent(),$("ul.downplayed li div.content p").vAlign(),$("form.sandbox").submit(function(){var e=!0;return $(this).find("input.required").each(function(){$(this).removeClass("error"),""==$(this).val()&&($(this).addClass("error"),$(this).wiggle(),e=!1)}),e})}),log=function(){log.history=log.history||[],log.history.push(arguments),this.console&&console.log(Array.prototype.slice.call(arguments)[0])},Function.prototype.bind&&console&&"object"==typeof console.log&&["log","info","warn","error","assert","dir","clear","profile","profileEnd"].forEach(function(e){console[e]=this.bind(console[e],console)},Function.prototype.call);var Docs={shebang:function(){var e=$.param.fragment().split("/");switch(e.shift(),e.length){case 1:var t="resource_"+e[0];Docs.expandEndpointListForResource(e[0]),$("#"+t).slideto({highlight:!1});break;case 2:Docs.expandEndpointListForResource(e[0]),$("#"+t).slideto({highlight:!1});var n=e.join("_"),a=n+"_content";Docs.expandOperation($("#"+a)),$("#"+n).slideto({highlight:!1})}},toggleEndpointListForResource:function(e){var t=$("li#resource_"+Docs.escapeResourceName(e)+" ul.endpoints");t.is(":visible")?Docs.collapseEndpointListForResource(e):Docs.expandEndpointListForResource(e)},expandEndpointListForResource:function(e){var e=Docs.escapeResourceName(e);if(""==e)return void $(".resource ul.endpoints").slideDown();$("li#resource_"+e).addClass("active");var t=$("li#resource_"+e+" ul.endpoints");t.slideDown()},collapseEndpointListForResource:function(e){var e=Docs.escapeResourceName(e);if(""==e)return void $(".resource ul.endpoints").slideUp();$("li#resource_"+e).removeClass("active");var t=$("li#resource_"+e+" ul.endpoints");t.slideUp()},expandOperationsForResource:function(e){return Docs.expandEndpointListForResource(e),""==e?void $(".resource ul.endpoints li.operation div.content").slideDown():void $("li#resource_"+Docs.escapeResourceName(e)+" li.operation div.content").each(function(){Docs.expandOperation($(this))})},collapseOperationsForResource:function(e){return Docs.expandEndpointListForResource(e),""==e?void $(".resource ul.endpoints li.operation div.content").slideUp():void $("li#resource_"+Docs.escapeResourceName(e)+" li.operation div.content").each(function(){Docs.collapseOperation($(this))})},escapeResourceName:function(e){return e.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g,"\\$&")},expandOperation:function(e){e.slideDown()},collapseOperation:function(e){e.slideUp()}};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(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return"\n
    \n
    \n
    "+l((s=null!=(s=t.keyName||(null!=e?e.keyName:e))?s:r,typeof s===i?s.call(e,{name:"keyName",hash:{},data:a}):s))+'
    \n \n \n
    \n
    \n\n'},useData:!0});var SwaggerUi,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;SwaggerUi=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.dom_id="swagger_ui",t.prototype.options=null,t.prototype.api=null,t.prototype.headerView=null,t.prototype.mainView=null,t.prototype.initialize=function(e){return null==e&&(e={}),null!=e.dom_id&&(this.dom_id=e.dom_id,delete e.dom_id),null==$("#"+this.dom_id)&&$("body").append('
    '),this.options=e,this.options.success=function(e){return function(){return e.render()}}(this),this.options.progress=function(e){return function(t){return e.showMessage(t)}}(this),this.options.failure=function(e){return function(t){return e.api&&e.api.isValid===!1?(log("not a valid 2.0 spec, loading legacy client"),e.api=new SwaggerApi(e.options),e.api.build()):e.onLoadFailure(t)}}(this),this.headerView=new HeaderView({el:$("#header")}),this.headerView.on("update-swagger-ui",function(e){return function(t){return e.updateSwaggerUi(t)}}(this))},t.prototype.setOption=function(e,t){return this.options[e]=t},t.prototype.getOption=function(e){return this.options[e]},t.prototype.updateSwaggerUi=function(e){return this.options.url=e.url,this.load()},t.prototype.load=function(){var e,t;return null!=(t=this.mainView)&&t.clear(),e=this.options.url,e&&0!==e.indexOf("http")&&(e=this.buildUrl(window.location.href.toString(),e)),this.options.url=e,this.headerView.update(e),this.api=new SwaggerClient(this.options),this.api.build()},t.prototype.collapseAll=function(){return Docs.collapseEndpointListForResource("")},t.prototype.listAll=function(){return Docs.collapseOperationsForResource("")},t.prototype.expandAll=function(){return Docs.expandOperationsForResource("")},t.prototype.render=function(){switch(this.showMessage("Finished Loading Resource Information. Rendering Swagger UI..."),this.mainView=new MainView({model:this.api,el:$("#"+this.dom_id),swaggerOptions:this.options}).render(),this.showMessage(),this.options.docExpansion){case"full":this.expandAll();break;case"list":this.listAll()}return this.renderGFM(),this.options.onComplete&&this.options.onComplete(this.api,this),setTimeout(function(){return function(){return Docs.shebang()}}(this),400)},t.prototype.buildUrl=function(e,t){var n,a;return 0===t.indexOf("/")?(a=e.split("/"),e=a[0]+"//"+a[2],e+t):(n=e.length,e.indexOf("?")>-1&&(n=Math.min(n,e.indexOf("?"))),e.indexOf("#")>-1&&(n=Math.min(n,e.indexOf("#"))),e=e.substring(0,n),-1!==e.indexOf("/",e.length-1)?e+t:e+"/"+t)},t.prototype.showMessage=function(e){return null==e&&(e=""),$("#message-bar").removeClass("message-fail"),$("#message-bar").addClass("message-success"),$("#message-bar").html(e)},t.prototype.onLoadFailure=function(e){var t;return null==e&&(e=""),$("#message-bar").removeClass("message-success"),$("#message-bar").addClass("message-fail"),t=$("#message-bar").html(e),null!=this.options.onFailure&&this.options.onFailure(e),t},t.prototype.renderGFM=function(e){return null==e&&(e=""),$(".markdown").each(function(){return $(this).html(marked($(this).html()))})},t}(Backbone.Router),window.SwaggerUi=SwaggerUi;var ApiKeyButton,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;ApiKeyButton=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.initialize=function(){},t.prototype.render=function(){var e;return e=this.template(),$(this.el).html(e(this.model)),this},t.prototype.events={"click #apikey_button":"toggleApiKeyContainer","click #apply_api_key":"applyApiKey"},t.prototype.applyApiKey=function(){var e;return window.authorizations.add(this.model.name,new ApiKeyAuthorization(this.model.name,$("#input_apiKey_entry").val(),this.model["in"])),window.swaggerUi.load(),e=$("#apikey_container").show()},t.prototype.toggleApiKeyContainer=function(){var e;return $("#apikey_container").length>0?(e=$("#apikey_container").first(),e.is(":visible")?e.hide():($(".auth_container").hide(),e.show())):void 0},t.prototype.template=function(){return Handlebars.templates.apikey_button_view},t}(Backbone.View),this.Handlebars.templates.basic_auth_button_view=Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(){return'
    \n
    \n
    \n
    Username
    \n \n
    Password
    \n \n \n
    \n
    \n\n'},useData:!0});var BasicAuthButton,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;BasicAuthButton=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.initialize=function(){},t.prototype.render=function(){var e;return e=this.template(),$(this.el).html(e(this.model)),this},t.prototype.events={"click #basic_auth_button":"togglePasswordContainer","click #apply_basic_auth":"applyPassword"},t.prototype.applyPassword=function(){var e,t,n;return console.log("applying password"),n=$(".input_username").val(),t=$(".input_password").val(),window.authorizations.add(this.model.type,new PasswordAuthorization("basic",n,t)),window.swaggerUi.load(),e=$("#basic_auth_container").hide()},t.prototype.togglePasswordContainer=function(){var e;return $("#basic_auth_container").length>0?(e=$("#basic_auth_container").show(),e.is(":visible")?e.slideUp():($(".auth_container").hide(),e.show())):void 0},t.prototype.template=function(){return Handlebars.templates.basic_auth_button_view},t}(Backbone.View),this.Handlebars.templates.content_type=Handlebars.template({1:function(e,t,n,a){var s,i="";return s=t.each.call(e,null!=e?e.produces:e,{name:"each",hash:{},fn:this.program(2,a),inverse:this.noop,data:a}),null!=s&&(i+=s),i},2:function(e){var t,n=this.lambda,a=' \n"},4:function(){return' \n'},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i='\n\n"},useData:!0});var ContentTypeView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;ContentTypeView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.initialize=function(){},t.prototype.render=function(){var e;return e=this.template(),$(this.el).html(e(this.model)),$("label[for=contentType]",$(this.el)).text("Response Content Type"),this},t.prototype.template=function(){return Handlebars.templates.content_type},t}(Backbone.View),this.Handlebars.templates.main=Handlebars.template({1:function(e,t,n,a){var s,i=this.lambda,r=this.escapeExpression,l='
    '+r(i(null!=(s=null!=e?e.info:e)?s.title:s,e))+'
    \n
    ';return s=i(null!=(s=null!=e?e.info:e)?s.description:s,e),null!=s&&(l+=s),l+="
    \n ",s=t["if"].call(e,null!=(s=null!=e?e.info:e)?s.termsOfServiceUrl:s,{name:"if",hash:{},fn:this.program(2,a),inverse:this.noop,data:a}),null!=s&&(l+=s),l+="\n ",s=t["if"].call(e,null!=(s=null!=(s=null!=e?e.info:e)?s.contact:s)?s.name:s,{name:"if",hash:{},fn:this.program(4,a),inverse:this.noop,data:a}),null!=s&&(l+=s),l+="\n ",s=t["if"].call(e,null!=(s=null!=(s=null!=e?e.info:e)?s.contact:s)?s.url:s,{name:"if",hash:{},fn:this.program(6,a),inverse:this.noop,data:a}),null!=s&&(l+=s),l+="\n ",s=t["if"].call(e,null!=(s=null!=(s=null!=e?e.info:e)?s.contact:s)?s.email:s,{name:"if",hash:{},fn:this.program(8,a),inverse:this.noop,data:a}),null!=s&&(l+=s),l+="\n ",s=t["if"].call(e,null!=(s=null!=e?e.info:e)?s.license:s,{name:"if",hash:{},fn:this.program(10,a),inverse:this.noop,data:a}),null!=s&&(l+=s),l+"\n"},2:function(e){var t,n=this.lambda,a=this.escapeExpression;return''},4:function(e){var t,n=this.lambda,a=this.escapeExpression;return"
    Created by "+a(n(null!=(t=null!=(t=null!=e?e.info:e)?t.contact:t)?t.name:t,e))+"
    "},6:function(e){var t,n=this.lambda,a=this.escapeExpression;return""},8:function(e){var t,n=this.lambda,a=this.escapeExpression;return"'},10:function(e){var t,n=this.lambda,a=this.escapeExpression;return""},12:function(e){var t,n=this.lambda,a=this.escapeExpression;return' , api version: '+a(n(null!=(t=null!=e?e.info:e)?t.version:t,e))+"\n "},14:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return' \n \n'},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o=this.escapeExpression,p="
    \n";return s=t["if"].call(e,null!=e?e.info:e,{name:"if",hash:{},fn:this.program(1,a),inverse:this.noop,data:a}),null!=s&&(p+=s),p+="
    \n
    \n
      \n\n
      \n
      \n
      \n

      [ base url: "+o((i=null!=(i=t.basePath||(null!=e?e.basePath:e))?i:l,typeof i===r?i.call(e,{name:"basePath",hash:{},data:a}):i))+"\n",s=t["if"].call(e,null!=(s=null!=e?e.info:e)?s.version:s,{name:"if",hash:{},fn:this.program(12,a),inverse:this.noop,data:a}),null!=s&&(p+=s),p+="]\n",s=t["if"].call(e,null!=e?e.validatorUrl:e,{name:"if",hash:{},fn:this.program(14,a),inverse:this.noop,data:a}),null!=s&&(p+=s),p+"

      \n
      \n
      \n"},useData:!0});var HeaderView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;HeaderView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.events={"click #show-pet-store-icon":"showPetStore","click #show-wordnik-dev-icon":"showWordnikDev","click #explore":"showCustom","keyup #input_baseUrl":"showCustomOnKeyup","keyup #input_apiKey":"showCustomOnKeyup"},t.prototype.initialize=function(){},t.prototype.showPetStore=function(){return this.trigger("update-swagger-ui",{url:"http://petstore.swagger.wordnik.com/api/api-docs"})},t.prototype.showWordnikDev=function(){return this.trigger("update-swagger-ui",{url:"http://api.wordnik.com/v4/resources.json"})},t.prototype.showCustomOnKeyup=function(e){return 13===e.keyCode?this.showCustom():void 0},t.prototype.showCustom=function(e){return null!=e&&e.preventDefault(),this.trigger("update-swagger-ui",{url:$("#input_baseUrl").val(),apiKey:$("#input_apiKey").val()})},t.prototype.update=function(e,t,n){return null==n&&(n=!1),$("#input_baseUrl").val(e),n?this.trigger("update-swagger-ui",{url:e}):void 0},t}(Backbone.View),this.Handlebars.templates.operation=Handlebars.template({1:function(){return"deprecated"},3:function(){return"

      Warning: Deprecated

      \n"},5:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o='

      Implementation Notes

      \n

      ';return i=null!=(i=t.description||(null!=e?e.description:e))?i:l,s=typeof i===r?i.call(e,{name:"description",hash:{},data:a}):i,null!=s&&(o+=s),o+"

      \n"},7:function(){return'
      \n '},9:function(e,t,n,a){var s,i=' \n"},10:function(e){var t,n=this.lambda,a=this.escapeExpression,s="
      "+a(n(null!=e?e.scope:e,e))+"
      \n"},12:function(){return"
      "},14:function(){return'
      \n \n
      \n'},16:function(){return'

      Response Class

      \n

      \n
      \n
      \n'},18:function(){return'

      Parameters

      \n \n \n \n \n \n \n \n \n \n \n \n\n \n
      ParameterValueDescriptionParameter TypeData Type
      \n'},20:function(){return"
      \n

      Response Messages

      \n \n \n \n \n \n \n \n \n \n \n \n
      HTTP Status CodeReasonResponse Model
      \n"},22:function(){return""},24:function(){return"
      \n \n \n \n
      \n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r,l="function",o=t.helperMissing,p=this.escapeExpression,u=t.blockHelperMissing,h="\n
        \n
      • \n \n \n
      • \n
      \n"},useData:!0});var MainView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;MainView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}var n;return __extends(t,e),n={alpha:function(e,t){return e.path.localeCompare(t.path)},method:function(e,t){return e.method.localeCompare(t.method)}},t.prototype.initialize=function(e){var t,n,a,s;null==e&&(e={}),this.model.auths=[],s=this.model.securityDefinitions;for(n in s)a=s[n],t={name:n,type:a.type,value:a},this.model.auths.push(t);return"2.0"===this.model.swaggerVersion?this.model.validatorUrl="validatorUrl"in e.swaggerOptions?e.swaggerOptions.validatorUrl:this.model.url.indexOf("localhost")>0?null:"http://online.swagger.io/validator":void 0},t.prototype.render=function(){var e,t,n,a,s,i,r,l,o,p;if(this.model.securityDefinitions)for(s in this.model.securityDefinitions)e=this.model.securityDefinitions[s],"apiKey"===e.type&&0===$("#apikey_button").length&&(t=new ApiKeyButton({model:e}).render().el,$(".auth_main_container").append(t)),"basicAuth"===e.type&&0===$("#basic_auth_button").length&&(t=new BasicAuthButton({model:e}).render().el,$(".auth_main_container").append(t));for($(this.el).html(Handlebars.templates.main(this.model)),r={},n=0,p=this.model.apisArray,l=0,o=p.length;o>l;l++){for(i=p[l],a=i.name;"undefined"!=typeof r[a];)a=a+"_"+n,n+=1;i.id=a,r[a]=i,this.addResource(i,this.model.auths)}return $(".propWrap").hover(function(){return $(".optionsWrapper",$(this)).show()},function(){return $(".optionsWrapper",$(this)).hide()}),this},t.prototype.addResource=function(e,t){var n;return e.id=e.id.replace(/\s/g,"_"),n=new ResourceView({model:e,tagName:"li",id:"resource_"+e.id,className:"resource",auths:t,swaggerOptions:this.options.swaggerOptions}),$("#resources").append(n.render().el)},t.prototype.clear=function(){return $(this.el).html("")},t}(Backbone.View),this.Handlebars.templates.param=Handlebars.template({1:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e.isFile:e,{name:"if",hash:{},fn:this.program(2,a),inverse:this.program(4,a),data:a}),null!=s&&(i+=s),i},2:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return' \n
      \n'},4:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(5,a),inverse:this.program(7,a),data:a}),null!=s&&(i+=s),i},5:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n
      \n
      \n'},7:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n
      \n
      \n'},9:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e.isFile:e,{name:"if",hash:{},fn:this.program(2,a),inverse:this.program(10,a),data:a}),null!=s&&(i+=s),i},10:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(11,a),inverse:this.program(13,a),data:a}),null!=s&&(i+=s),i},11:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n"},13:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o=this.escapeExpression,p=""+o((i=null!=(i=t.name||(null!=e?e.name:e))?i:l,typeof i===r?i.call(e,{name:"name",hash:{},data:a}):i))+"\n\n\n";return s=t["if"].call(e,null!=e?e.isBody:e,{name:"if",hash:{},fn:this.program(1,a),inverse:this.program(9,a),data:a}),null!=s&&(p+=s),p+='\n\n',i=null!=(i=t.description||(null!=e?e.description:e))?i:l,s=typeof i===r?i.call(e,{name:"description",hash:{},data:a}):i,null!=s&&(p+=s),p+="\n",i=null!=(i=t.paramType||(null!=e?e.paramType:e))?i:l,s=typeof i===r?i.call(e,{name:"paramType",hash:{},data:a}):i,null!=s&&(p+=s),p+'\n\n \n\n'},useData:!0});var OperationView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;OperationView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.invocationUrl=null,t.prototype.events={"submit .sandbox":"submitOperation","click .submit":"submitOperation","click .response_hider":"hideResponse","click .toggleOperation":"toggleOperationContent","mouseenter .api-ic":"mouseEnter","mouseout .api-ic":"mouseExit"},t.prototype.initialize=function(e){return null==e&&(e={}),this.auths=e.auths,this},t.prototype.mouseEnter=function(e){var t,n,a,s,i,r,l,o,p,u;return t=$(this.el).find(".content"),p=e.pageX,u=e.pageY,r=$(window).scrollLeft(),l=$(window).scrollTop(),s=r+$(window).width(),i=l+$(window).height(),o=t.width(),n=t.height(),p+o>s&&(p=s-o),r>p&&(p=r),u+n>i&&(u=i-n),l>u&&(u=l),a={},a.top=u,a.left=p,t.css(a),$(e.currentTarget.parentNode).find("#api_information_panel").show()},t.prototype.mouseExit=function(e){return $(e.currentTarget.parentNode).find("#api_information_panel").hide()},t.prototype.render=function(){var e,t,n,a,s,i,r,l,o,p,u,h,c,d,m,f,y,g,v,_,w,b,x,k,O,C,P,T,S,D,H,E,R,M,V,U,N;if(i=!0,i||(this.model.isReadOnly=!0),this.model.description=this.model.description||this.model.notes,this.model.description&&(this.model.description=this.model.description.replace(/(?:\r\n|\r|\n)/g,"
      ")),this.model.oauth=null,o=this.model.authorizations||this.model.security)if(Array.isArray(o))for(x=0,P=o.length;P>x;x++){n=o[x];for(l in n){t=n[l];for(e in this.auths)if(t=this.auths[e],"oauth2"===t.type){this.model.oauth={},this.model.oauth.scopes=[],R=t.value.scopes;for(r in R)w=R[r],y=n[l].indexOf(r),y>=0&&(p={scope:r,description:w},this.model.oauth.scopes.push(p))}}}else for(r in o)if(w=o[r],"oauth2"===r)for(null===this.model.oauth&&(this.model.oauth={}),void 0===this.model.oauth.scopes&&(this.model.oauth.scopes=[]),k=0,T=w.length;T>k;k++)p=w[k],this.model.oauth.scopes.push(p);if("undefined"!=typeof this.model.responses){this.model.responseMessages=[],M=this.model.responses;for(a in M)b=M[a],m=null,f=this.model.responses[a].schema,f&&f.$ref&&(m=f.$ref,0===m.indexOf("#/definitions/")&&(m=m.substring("#/definitions/".length))),this.model.responseMessages.push({code:a,message:b.description,responseModel:m}) -}for("undefined"==typeof this.model.responseMessages&&(this.model.responseMessages=[]),$(this.el).html(Handlebars.templates.operation(this.model)),this.model.responseClassSignature&&"string"!==this.model.responseClassSignature?(g={sampleJSON:this.model.responseSampleJSON,isParam:!1,signature:this.model.responseClassSignature},d=new SignatureView({model:g,tagName:"div"}),$(".model-signature",$(this.el)).append(d.render().el)):(this.model.responseClassSignature="string",$(".model-signature",$(this.el)).html(this.model.type)),s={isParam:!1},s.consumes=this.model.consumes,s.produces=this.model.produces,V=this.model.parameters,O=0,S=V.length;S>O;O++)u=V[O],_=u.type||u.dataType||"","undefined"==typeof _&&(m=u.schema,m&&m.$ref&&(h=m.$ref,_=0===h.indexOf("#/definitions/")?h.substring("#/definitions/".length):h)),_&&"file"===_.toLowerCase()&&(s.consumes||(s.consumes="multipart/form-data")),u.type=_;for(c=new ResponseContentTypeView({model:s}),$(".response-content-type",$(this.el)).append(c.render().el),U=this.model.parameters,C=0,D=U.length;D>C;C++)u=U[C],this.addParameter(u,s.consumes);for(N=this.model.responseMessages,E=0,H=N.length;H>E;E++)v=N[E],this.addStatusCode(v);return this},t.prototype.addParameter=function(e,t){var n;return e.consumes=t,n=new ParameterView({model:e,tagName:"tr",readOnly:this.model.isReadOnly}),$(".operation-params",$(this.el)).append(n.render().el)},t.prototype.addStatusCode=function(e){var t;return t=new StatusCodeView({model:e,tagName:"tr"}),$(".operation-status",$(this.el)).append(t.render().el)},t.prototype.submitOperation=function(e){var t,n,a,s,i,r,l,o,p,u,h,c,d,m,f,y;if(null!=e&&e.preventDefault(),n=$(".sandbox",$(this.el)),t=!0,n.find("input.required").each(function(){return $(this).removeClass("error"),""===jQuery.trim($(this).val())?($(this).addClass("error"),$(this).wiggle({callback:function(e){return function(){return $(e).focus()}}(this)}),t=!1):void 0}),n.find("textarea.required").each(function(){return $(this).removeClass("error"),""===jQuery.trim($(this).val())?($(this).addClass("error"),$(this).wiggle({callback:function(e){return function(){return $(e).focus()}}(this)}),t=!1):void 0}),t){for(s={},r={parent:this},a=!1,m=n.find("input"),o=0,h=m.length;h>o;o++)i=m[o],null!=i.value&&jQuery.trim(i.value).length>0&&(s[i.name]=i.value),"file"===i.type&&(a=!0);for(f=n.find("textarea"),p=0,c=f.length;c>p;p++)i=f[p],null!=i.value&&jQuery.trim(i.value).length>0&&(s[i.name]=i.value);for(y=n.find("select"),u=0,d=y.length;d>u;u++)i=y[u],l=this.getSelectedValue(i),null!=l&&jQuery.trim(l).length>0&&(s[i.name]=l);return r.responseContentType=$("div select[name=responseContentType]",$(this.el)).val(),r.requestContentType=$("div select[name=parameterContentType]",$(this.el)).val(),$(".response_throbber",$(this.el)).show(),a?this.handleFileUpload(s,n):this.model["do"](s,r,this.showCompleteStatus,this.showErrorStatus,this)}},t.prototype.success=function(e,t){return t.showCompleteStatus(e)},t.prototype.handleFileUpload=function(e,t){var n,a,s,i,r,l,o,p,u,h,c,d,m,f,y,g,v,_,w;for(g=t.serializeArray(),p=0,d=g.length;d>p;p++)i=g[p],null!=i.value&&jQuery.trim(i.value).length>0&&(e[i.name]=i.value);for(n=new FormData,o=0,v=this.model.parameters,u=0,m=v.length;m>u;u++)l=v[u],"form"===l.paramType&&"file"!==l.type.toLowerCase()&&void 0!==e[l.name]&&n.append(l.name,e[l.name]);for(s={},_=this.model.parameters,h=0,f=_.length;f>h;h++)l=_[h],"header"===l.paramType&&(s[l.name]=e[l.name]);for(w=t.find('input[type~="file"]'),c=0,y=w.length;y>c;c++)a=w[c],"undefined"!=typeof a.files[0]&&(n.append($(a).attr("name"),a.files[0]),o+=1);return this.invocationUrl=this.model.supportHeaderParams()?(s=this.model.getHeaderParams(e),delete s["Content-Type"],this.model.urlify(e,!1)):this.model.urlify(e,!0),$(".request_url",$(this.el)).html("
      "),$(".request_url pre",$(this.el)).text(this.invocationUrl),r={type:this.model.method,url:this.invocationUrl,headers:s,data:n,dataType:"json",contentType:!1,processData:!1,error:function(e){return function(t){return e.showErrorStatus(e.wrap(t),e)}}(this),success:function(e){return function(t){return e.showResponse(t,e)}}(this),complete:function(e){return function(t){return e.showCompleteStatus(e.wrap(t),e)}}(this)},window.authorizations&&window.authorizations.apply(r),0===o&&r.data.append("fake","true"),jQuery.ajax(r),!1},t.prototype.wrap=function(e){var t,n,a,s,i,r,l;for(a={},n=e.getAllResponseHeaders().split("\r"),r=0,l=n.length;l>r;r++)s=n[r],t=s.match(/^([^:]*?):(.*)$/),t||(t=[]),t.shift(),void 0!==t[0]&&void 0!==t[1]&&(a[t[0].trim()]=t[1].trim());return i={},i.content={},i.content.data=e.responseText,i.headers=a,i.request={},i.request.url=this.invocationUrl,i.status=e.status,i},t.prototype.getSelectedValue=function(e){var t,n,a,s,i;if(e.multiple){for(n=[],i=e.options,a=0,s=i.length;s>a;a++)t=i[a],t.selected&&n.push(t.value);return n.length>0?n:null}return e.value},t.prototype.hideResponse=function(e){return null!=e&&e.preventDefault(),$(".response",$(this.el)).slideUp(),$(".response_hider",$(this.el)).fadeOut()},t.prototype.showResponse=function(e){var t;return t=JSON.stringify(e,null,"	").replace(/\n/g,"
      "),$(".response_body",$(this.el)).html(escape(t))},t.prototype.showErrorStatus=function(e,t){return t.showStatus(e)},t.prototype.showCompleteStatus=function(e,t){return t.showStatus(e)},t.prototype.formatXml=function(e){var t,n,a,s,i,r,l,o,p,u,h,c,d;for(o=/(>)(<)(\/*)/g,u=/[ ]*(.*)[ ]+\n/g,t=/(<.+>)(.+\n)/g,e=e.replace(o,"$1\n$2$3").replace(u,"$1\n").replace(t,"$1\n$2"),l=0,n="",i=e.split("\n"),a=0,s="other",p={"single->single":0,"single->closing":-1,"single->opening":0,"single->other":0,"closing->single":0,"closing->closing":-1,"closing->opening":0,"closing->other":0,"opening->single":1,"opening->closing":0,"opening->opening":1,"opening->other":1,"other->single":0,"other->closing":-1,"other->opening":0,"other->other":0},h=function(e){var t,i,r,l,o,u,h;return u={single:Boolean(e.match(/<.+\/>/)),closing:Boolean(e.match(/<\/.+>/)),opening:Boolean(e.match(/<[^!?].*>/))},o=function(){var e;e=[];for(r in u)h=u[r],h&&e.push(r);return e}()[0],o=void 0===o?"other":o,t=s+"->"+o,s=o,l="",a+=p[t],l=function(){var e,t,n;for(n=[],i=e=0,t=a;t>=0?t>e:e>t;i=t>=0?++e:--e)n.push(" ");return n}().join(""),"opening->closing"===t?n=n.substr(0,n.length-1)+e+"\n":n+=l+e+"\n"},c=0,d=i.length;d>c;c++)r=i[c],h(r);return n},t.prototype.showStatus=function(e){var t,n,a,s,i,r,l,o,p,u,h;if(void 0===e.content?(n=e.data,h=e.url):(n=e.content.data,h=e.request.url),i=e.headers,a=null,i&&(a=i["Content-Type"]||i["content-type"],a&&(a=a.split(";")[0].trim())),$(".response_body",$(this.el)).removeClass("json"),$(".response_body",$(this.el)).removeClass("xml"),n)if("application/json"===a||/\+json$/.test(a)){r=null;try{r=JSON.stringify(JSON.parse(n),null," ")}catch(c){s=c,r="can't parse JSON. Raw result:\n\n"+n}t=$("").text(r),o=$('
      ').append(t)}else"application/xml"===a||/\+xml$/.test(a)?(t=$("").text(this.formatXml(n)),o=$('
      ').append(t)):"text/html"===a?(t=$("").html(_.escape(n)),o=$('
      ').append(t)):/^image\//.test(a)?o=$("").attr("src",h):(t=$("").text(n),o=$('
      ').append(t));else t=$("").text("no content"),o=$('
      ').append(t);return p=o,$(".request_url",$(this.el)).html("
      "),$(".request_url pre",$(this.el)).text(h),$(".response_code",$(this.el)).html("
      "+e.status+"
      "),$(".response_body",$(this.el)).html(p),$(".response_headers",$(this.el)).html("
      "+_.escape(JSON.stringify(e.headers,null,"  ")).replace(/\n/g,"
      ")+"
      "),$(".response",$(this.el)).slideDown(),$(".response_hider",$(this.el)).show(),$(".response_throbber",$(this.el)).hide(),u=$(".response_body",$(this.el))[0],l=this.options.swaggerOptions,l.highlightSizeThreshold&&e.data.length>l.highlightSizeThreshold?u:hljs.highlightBlock(u)},t.prototype.toggleOperationContent=function(){var e;return e=$("#"+Docs.escapeResourceName(this.model.parentId+"_"+this.model.nickname+"_content")),e.is(":visible")?Docs.collapseOperation(e):Docs.expandOperation(e)},t}(Backbone.View);var ParameterContentTypeView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;ParameterContentTypeView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.initialize=function(){},t.prototype.render=function(){var e;return e=this.template(),$(this.el).html(e(this.model)),$("label[for=parameterContentType]",$(this.el)).text("Parameter content type:"),this},t.prototype.template=function(){return Handlebars.templates.parameter_content_type},t}(Backbone.View),this.Handlebars.templates.param_list=Handlebars.template({1:function(){return" multiple='multiple'"},3:function(){return""},5:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(3,a),inverse:this.program(6,a),data:a}),null!=s&&(i+=s),i},6:function(e,t,n,a){var s,i=t.helperMissing,r="";return s=(t.isArray||e&&e.isArray||i).call(e,e,{name:"isArray",hash:{},fn:this.program(3,a),inverse:this.program(7,a),data:a}),null!=s&&(r+=s),r},7:function(){return" \n"},9:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e.isDefault:e,{name:"if",hash:{},fn:this.program(10,a),inverse:this.program(12,a),data:a}),null!=s&&(i+=s),i},10:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return' \n"},12:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o=this.escapeExpression,p=""+o((i=null!=(i=t.name||(null!=e?e.name:e))?i:l,typeof i===r?i.call(e,{name:"name",hash:{},data:a}):i))+"\n\n \n\n',i=null!=(i=t.description||(null!=e?e.description:e))?i:l,s=typeof i===r?i.call(e,{name:"description",hash:{},data:a}):i,null!=s&&(p+=s),p+="\n",i=null!=(i=t.paramType||(null!=e?e.paramType:e))?i:l,s=typeof i===r?i.call(e,{name:"paramType",hash:{},data:a}):i,null!=s&&(p+=s),p+'\n'},useData:!0});var ParameterView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;ParameterView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.initialize=function(){return Handlebars.registerHelper("isArray",function(e,t){return"array"===e.type.toLowerCase()||e.allowMultiple?t.fn(this):t.inverse(this)})},t.prototype.render=function(){var e,t,n,a,s,i,r,l,o,p;return p=this.model.type||this.model.dataType,"undefined"==typeof p&&(i=this.model.schema,i&&i.$ref&&(a=i.$ref,p=0===a.indexOf("#/definitions/")?a.substring("#/definitions/".length):a)),this.model.type=p,this.model.paramType=this.model["in"]||this.model.paramType,"body"===this.model.paramType&&(this.model.isBody=!0),p&&"file"===p.toLowerCase()&&(this.model.isFile=!0),this.model["default"]=this.model["default"]||this.model.defaultValue,this.model.allowableValues&&(this.model.isList=!0),o=this.template(),$(this.el).html(o(this.model)),r={sampleJSON:this.model.sampleJSON,isParam:!0,signature:this.model.signature},this.model.sampleJSON?(l=new SignatureView({model:r,tagName:"div"}),$(".model-signature",$(this.el)).append(l.render().el)):$(".model-signature",$(this.el)).html(this.model.signature),t=!1,this.model.isBody&&(t=!0),e={isParam:t},e.consumes=this.model.consumes,t?(n=new ParameterContentTypeView({model:e}),$(".parameter-content-type",$(this.el)).append(n.render().el)):(s=new ResponseContentTypeView({model:e}),$(".response-content-type",$(this.el)).append(s.render().el)),this},t.prototype.template=function(){return this.model.isList?Handlebars.templates.param_list:this.options.readOnly?this.model.required?Handlebars.templates.param_readonly_required:Handlebars.templates.param_readonly:this.model.required?Handlebars.templates.param_required:Handlebars.templates.param},t}(Backbone.View),this.Handlebars.templates.param_readonly=Handlebars.template({1:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n"},3:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(4,a),inverse:this.program(6,a),data:a}),null!=s&&(i+=s),i},4:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" "+l((s=null!=(s=t["default"]||(null!=e?e["default"]:e))?s:r,typeof s===i?s.call(e,{name:"default",hash:{},data:a}):s))+"\n"},6:function(){return" (empty)\n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o=this.escapeExpression,p=""+o((i=null!=(i=t.name||(null!=e?e.name:e))?i:l,typeof i===r?i.call(e,{name:"name",hash:{},data:a}):i))+"\n\n";return s=t["if"].call(e,null!=e?e.isBody:e,{name:"if",hash:{},fn:this.program(1,a),inverse:this.program(3,a),data:a}),null!=s&&(p+=s),p+='\n',i=null!=(i=t.description||(null!=e?e.description:e))?i:l,s=typeof i===r?i.call(e,{name:"description",hash:{},data:a}):i,null!=s&&(p+=s),p+="\n",i=null!=(i=t.paramType||(null!=e?e.paramType:e))?i:l,s=typeof i===r?i.call(e,{name:"paramType",hash:{},data:a}):i,null!=s&&(p+=s),p+'\n\n'},useData:!0});var ResourceView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;ResourceView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.initialize=function(e){return null==e&&(e={}),this.auths=e.auths,""===this.model.description?this.model.description=null:void 0},t.prototype.render=function(){var e,t,n,a,s,i,r;for($(this.el).html(Handlebars.templates.resource(this.model)),n={},this.model.description&&(this.model.summary=this.model.description),r=this.model.operationsArray,s=0,i=r.length;i>s;s++){for(a=r[s],e=0,t=a.nickname;"undefined"!=typeof n[t];)t=t+"_"+e,e+=1;n[t]=a,a.nickname=t,a.parentId=this.model.id,this.addOperation(a)}return $(".toggleEndpointList",this.el).click(this.callDocs.bind(this,"toggleEndpointListForResource")),$(".collapseResource",this.el).click(this.callDocs.bind(this,"collapseOperationsForResource")),$(".expandResource",this.el).click(this.callDocs.bind(this,"expandOperationsForResource")),this},t.prototype.addOperation=function(e){var t;return e.number=this.number,t=new OperationView({model:e,tagName:"li",className:"endpoint",swaggerOptions:this.options.swaggerOptions,auths:this.auths}),$(".endpoints",$(this.el)).append(t.render().el),this.number++},t.prototype.callDocs=function(e,t){return t.preventDefault(),Docs[e](t.currentTarget.getAttribute("data-id"))},t}(Backbone.View),this.Handlebars.templates.param_readonly_required=Handlebars.template({1:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n"},3:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(4,a),inverse:this.program(6,a),data:a}),null!=s&&(i+=s),i},4:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" "+l((s=null!=(s=t["default"]||(null!=e?e["default"]:e))?s:r,typeof s===i?s.call(e,{name:"default",hash:{},data:a}):s))+"\n"},6:function(){return" (empty)\n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o=this.escapeExpression,p=""+o((i=null!=(i=t.name||(null!=e?e.name:e))?i:l,typeof i===r?i.call(e,{name:"name",hash:{},data:a}):i))+"\n\n";return s=t["if"].call(e,null!=e?e.isBody:e,{name:"if",hash:{},fn:this.program(1,a),inverse:this.program(3,a),data:a}),null!=s&&(p+=s),p+='\n',i=null!=(i=t.description||(null!=e?e.description:e))?i:l,s=typeof i===r?i.call(e,{name:"description",hash:{},data:a}):i,null!=s&&(p+=s),p+="\n",i=null!=(i=t.paramType||(null!=e?e.paramType:e))?i:l,s=typeof i===r?i.call(e,{name:"paramType",hash:{},data:a}):i,null!=s&&(p+=s),p+'\n\n'},useData:!0});var ResponseContentTypeView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;ResponseContentTypeView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.initialize=function(){},t.prototype.render=function(){var e;return e=this.template(),$(this.el).html(e(this.model)),$("label[for=responseContentType]",$(this.el)).text("Response Content Type"),this},t.prototype.template=function(){return Handlebars.templates.response_content_type},t}(Backbone.View),this.Handlebars.templates.param_required=Handlebars.template({1:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e.isFile:e,{name:"if",hash:{},fn:this.program(2,a),inverse:this.program(4,a),data:a}),null!=s&&(i+=s),i},2:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return' \n"},4:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(5,a),inverse:this.program(7,a),data:a}),null!=s&&(i+=s),i},5:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n
      \n
      \n'},7:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n
      \n
      \n'},9:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e.isFile:e,{name:"if",hash:{},fn:this.program(10,a),inverse:this.program(12,a),data:a}),null!=s&&(i+=s),i},10:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n"},12:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(13,a),inverse:this.program(15,a),data:a}),null!=s&&(i+=s),i},13:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n"},15:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o=this.escapeExpression,p=""+o((i=null!=(i=t.name||(null!=e?e.name:e))?i:l,typeof i===r?i.call(e,{name:"name",hash:{},data:a}):i))+"\n\n";return s=t["if"].call(e,null!=e?e.isBody:e,{name:"if",hash:{},fn:this.program(1,a),inverse:this.program(9,a),data:a}),null!=s&&(p+=s),p+='\n\n ',i=null!=(i=t.description||(null!=e?e.description:e))?i:l,s=typeof i===r?i.call(e,{name:"description",hash:{},data:a}):i,null!=s&&(p+=s),p+="\n\n",i=null!=(i=t.paramType||(null!=e?e.paramType:e))?i:l,s=typeof i===r?i.call(e,{name:"paramType",hash:{},data:a}):i,null!=s&&(p+=s),p+'\n\n'},useData:!0});var SignatureView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;SignatureView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.events={"click a.description-link":"switchToDescription","click a.snippet-link":"switchToSnippet","mousedown .snippet":"snippetToTextArea"},t.prototype.initialize=function(){},t.prototype.render=function(){var e;return e=this.template(),$(this.el).html(e(this.model)),this.switchToSnippet(),this.isParam=this.model.isParam,this.isParam&&$(".notice",$(this.el)).text("Click to set as parameter value"),this},t.prototype.template=function(){return Handlebars.templates.signature},t.prototype.switchToDescription=function(e){return null!=e&&e.preventDefault(),$(".snippet",$(this.el)).hide(),$(".description",$(this.el)).show(),$(".description-link",$(this.el)).addClass("selected"),$(".snippet-link",$(this.el)).removeClass("selected")},t.prototype.switchToSnippet=function(e){return null!=e&&e.preventDefault(),$(".description",$(this.el)).hide(),$(".snippet",$(this.el)).show(),$(".snippet-link",$(this.el)).addClass("selected"),$(".description-link",$(this.el)).removeClass("selected")},t.prototype.snippetToTextArea=function(e){var t;return this.isParam&&(null!=e&&e.preventDefault(),t=$("textarea",$(this.el.parentNode.parentNode.parentNode)),""===$.trim(t.val()))?t.val(this.model.sampleJSON):void 0},t}(Backbone.View),this.Handlebars.templates.parameter_content_type=Handlebars.template({1:function(e,t,n,a){var s,i="";return s=t.each.call(e,null!=e?e.consumes:e,{name:"each",hash:{},fn:this.program(2,a),inverse:this.noop,data:a}),null!=s&&(i+=s),i},2:function(e){var t,n=this.lambda,a=' \n"},4:function(){return' \n'},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i='\n\n"},useData:!0});var StatusCodeView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;StatusCodeView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.initialize=function(){},t.prototype.render=function(){var e,t,n;return n=this.template(),$(this.el).html(n(this.model)),swaggerUi.api.models.hasOwnProperty(this.model.responseModel)?(e={sampleJSON:JSON.stringify(swaggerUi.api.models[this.model.responseModel].createJSONSample(),null,2),isParam:!1,signature:swaggerUi.api.models[this.model.responseModel].getMockSignature()},t=new SignatureView({model:e,tagName:"div"}),$(".model-signature",this.$el).append(t.render().el)):$(".model-signature",this.$el).html(""),this},t.prototype.template=function(){return Handlebars.templates.status_code},t}(Backbone.View),this.Handlebars.templates.resource=Handlebars.template({1:function(){return" : "},3:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return"
    • \n Raw\n
    • "},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r,l="function",o=t.helperMissing,p=this.escapeExpression,u=t.blockHelperMissing,h="
      \n

      \n '+p((i=null!=(i=t.name||(null!=e?e.name:e))?i:o,typeof i===l?i.call(e,{name:"name",hash:{},data:a}):i))+" ";return i=null!=(i=t.summary||(null!=e?e.summary:e))?i:o,r={name:"summary",hash:{},fn:this.program(1,a),inverse:this.noop,data:a},s=typeof i===l?i.call(e,r):i,t.summary||(s=u.call(e,s,r)),null!=s&&(h+=s),i=null!=(i=t.summary||(null!=e?e.summary:e))?i:o,s=typeof i===l?i.call(e,{name:"summary",hash:{},data:a}):i,null!=s&&(h+=s),h+="\n

      \n
        \n
      • \n Show/Hide\n
      • \n
      • \n \n List Operations\n \n
      • \n
      • \n \n Expand Operations\n \n
      • \n ',i=null!=(i=t.url||(null!=e?e.url:e))?i:o,r={name:"url",hash:{},fn:this.program(3,a),inverse:this.noop,data:a},s=typeof i===l?i.call(e,r):i,t.url||(s=u.call(e,s,r)),null!=s&&(h+=s),h+"\n
      \n
      \n\n"},useData:!0}),Handlebars.registerHelper("sanitize",function(e){return e=e.replace(/)<[^<]*)*<\/script>/gi,""),new Handlebars.SafeString(e)}),this.Handlebars.templates.response_content_type=Handlebars.template({1:function(e,t,n,a){var s,i="";return s=t.each.call(e,null!=e?e.produces:e,{name:"each",hash:{},fn:this.program(2,a),inverse:this.noop,data:a}),null!=s&&(i+=s),i},2:function(e){var t,n=this.lambda,a=' \n"},4:function(){return' \n'},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i='\n\n"},useData:!0}),this.Handlebars.templates.signature=Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o=this.escapeExpression,p='
      \n\n
      \n\n
      \n
      \n ';return i=null!=(i=t.signature||(null!=e?e.signature:e))?i:l,s=typeof i===r?i.call(e,{name:"signature",hash:{},data:a}):i,null!=s&&(p+=s),p+'\n
      \n\n
      \n
      '+o((i=null!=(i=t.sampleJSON||(null!=e?e.sampleJSON:e))?i:l,typeof i===r?i.call(e,{name:"sampleJSON",hash:{},data:a}):i))+'
      \n \n
      \n
      \n\n'},useData:!0}),this.Handlebars.templates.status_code=Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o=this.escapeExpression,p=""+o((i=null!=(i=t.code||(null!=e?e.code:e))?i:l,typeof i===r?i.call(e,{name:"code",hash:{},data:a}):i))+"\n";return i=null!=(i=t.message||(null!=e?e.message:e))?i:l,s=typeof i===r?i.call(e,{name:"message",hash:{},data:a}):i,null!=s&&(p+=s),p+"\n"},useData:!0}); \ No newline at end of file +function clippyCopiedCallback(){$("#api_key_copied").fadeIn().delay(1e3).fadeOut()}$(function(){$.fn.vAlign=function(){return this.each(function(){var e=$(this).height(),t=$(this).parent().height(),n=(t-e)/2;$(this).css("margin-top",n)})},$.fn.stretchFormtasticInputWidthToParent=function(){return this.each(function(){var e=$(this).closest("form").innerWidth(),t=parseInt($(this).closest("form").css("padding-left"),10)+parseInt($(this).closest("form").css("padding-right"),10),n=parseInt($(this).css("padding-left"),10)+parseInt($(this).css("padding-right"),10);$(this).css("width",e-t-n)})},$("form.formtastic li.string input, form.formtastic textarea").stretchFormtasticInputWidthToParent(),$("ul.downplayed li div.content p").vAlign(),$("form.sandbox").submit(function(){var e=!0;return $(this).find("input.required").each(function(){$(this).removeClass("error"),""==$(this).val()&&($(this).addClass("error"),$(this).wiggle(),e=!1)}),e})}),log=function(){log.history=log.history||[],log.history.push(arguments),this.console&&console.log(Array.prototype.slice.call(arguments)[0])},Function.prototype.bind&&console&&"object"==typeof console.log&&["log","info","warn","error","assert","dir","clear","profile","profileEnd"].forEach(function(e){console[e]=this.bind(console[e],console)},Function.prototype.call);var Docs={shebang:function(){var e=$.param.fragment().split("/");switch(e.shift(),e.length){case 1:var t="resource_"+e[0];Docs.expandEndpointListForResource(e[0]),$("#"+t).slideto({highlight:!1});break;case 2:Docs.expandEndpointListForResource(e[0]),$("#"+t).slideto({highlight:!1});var n=e.join("_"),a=n+"_content";Docs.expandOperation($("#"+a)),$("#"+n).slideto({highlight:!1})}},toggleEndpointListForResource:function(e){var t=$("li#resource_"+Docs.escapeResourceName(e)+" ul.endpoints");t.is(":visible")?Docs.collapseEndpointListForResource(e):Docs.expandEndpointListForResource(e)},expandEndpointListForResource:function(e){var e=Docs.escapeResourceName(e);if(""==e)return void $(".resource ul.endpoints").slideDown();$("li#resource_"+e).addClass("active");var t=$("li#resource_"+e+" ul.endpoints");t.slideDown()},collapseEndpointListForResource:function(e){var e=Docs.escapeResourceName(e);if(""==e)return void $(".resource ul.endpoints").slideUp();$("li#resource_"+e).removeClass("active");var t=$("li#resource_"+e+" ul.endpoints");t.slideUp()},expandOperationsForResource:function(e){return Docs.expandEndpointListForResource(e),""==e?void $(".resource ul.endpoints li.operation div.content").slideDown():void $("li#resource_"+Docs.escapeResourceName(e)+" li.operation div.content").each(function(){Docs.expandOperation($(this))})},collapseOperationsForResource:function(e){return Docs.expandEndpointListForResource(e),""==e?void $(".resource ul.endpoints li.operation div.content").slideUp():void $("li#resource_"+Docs.escapeResourceName(e)+" li.operation div.content").each(function(){Docs.collapseOperation($(this))})},escapeResourceName:function(e){return e.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g,"\\$&")},expandOperation:function(e){e.slideDown()},collapseOperation:function(e){e.slideUp()}},SwaggerUi,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;SwaggerUi=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.dom_id="swagger_ui",t.prototype.options=null,t.prototype.api=null,t.prototype.headerView=null,t.prototype.mainView=null,t.prototype.initialize=function(e){return null==e&&(e={}),null!=e.dom_id&&(this.dom_id=e.dom_id,delete e.dom_id),null==$("#"+this.dom_id)&&$("body").append('
      '),this.options=e,this.options.success=function(e){return function(){return e.render()}}(this),this.options.progress=function(e){return function(t){return e.showMessage(t)}}(this),this.options.failure=function(e){return function(t){return e.onLoadFailure(t)}}(this),this.headerView=new HeaderView({el:$("#header")}),this.headerView.on("update-swagger-ui",function(e){return function(t){return e.updateSwaggerUi(t)}}(this))},t.prototype.setOption=function(e,t){return this.options[e]=t},t.prototype.getOption=function(e){return this.options[e]},t.prototype.updateSwaggerUi=function(e){return this.options.url=e.url,this.load()},t.prototype.load=function(){var e,t;return null!=(t=this.mainView)&&t.clear(),e=this.options.url,e&&0!==e.indexOf("http")&&(e=this.buildUrl(window.location.href.toString(),e)),this.options.url=e,this.headerView.update(e),this.api=new SwaggerClient(this.options),this.api.build()},t.prototype.collapseAll=function(){return Docs.collapseEndpointListForResource("")},t.prototype.listAll=function(){return Docs.collapseOperationsForResource("")},t.prototype.expandAll=function(){return Docs.expandOperationsForResource("")},t.prototype.render=function(){switch(this.showMessage("Finished Loading Resource Information. Rendering Swagger UI..."),this.mainView=new MainView({model:this.api,el:$("#"+this.dom_id),swaggerOptions:this.options}).render(),this.showMessage(),this.options.docExpansion){case"full":this.expandAll();break;case"list":this.listAll()}return this.renderGFM(),this.options.onComplete&&this.options.onComplete(this.api,this),setTimeout(function(){return function(){return Docs.shebang()}}(this),400)},t.prototype.buildUrl=function(e,t){var n,a;return 0===t.indexOf("/")?(a=e.split("/"),e=a[0]+"//"+a[2],e+t):(n=e.length,e.indexOf("?")>-1&&(n=Math.min(n,e.indexOf("?"))),e.indexOf("#")>-1&&(n=Math.min(n,e.indexOf("#"))),e=e.substring(0,n),-1!==e.indexOf("/",e.length-1)?e+t:e+"/"+t)},t.prototype.showMessage=function(e){return null==e&&(e=""),$("#message-bar").removeClass("message-fail"),$("#message-bar").addClass("message-success"),$("#message-bar").html(e)},t.prototype.onLoadFailure=function(e){var t;return null==e&&(e=""),$("#message-bar").removeClass("message-success"),$("#message-bar").addClass("message-fail"),t=$("#message-bar").html(e),null!=this.options.onFailure&&this.options.onFailure(e),t},t.prototype.renderGFM=function(e){return null==e&&(e=""),$(".markdown").each(function(){return $(this).html(marked($(this).html()))})},t}(Backbone.Router),window.SwaggerUi=SwaggerUi,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(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return"\n
      \n
      \n
      "+l((s=null!=(s=t.keyName||(null!=e?e.keyName:e))?s:r,typeof s===i?s.call(e,{name:"keyName",hash:{},data:a}):s))+'
      \n \n \n
      \n
      \n\n'},useData:!0}),Handlebars.registerHelper("sanitize",function(e){return e=e.replace(/)<[^<]*)*<\/script>/gi,""),new Handlebars.SafeString(e)}),this.Handlebars.templates.basic_auth_button_view=Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(){return'
      \n
      \n
      \n
      Username
      \n \n
      Password
      \n \n \n
      \n
      \n\n'},useData:!0}),this.Handlebars.templates.content_type=Handlebars.template({1:function(e,t,n,a){var s,i="";return s=t.each.call(e,null!=e?e.produces:e,{name:"each",hash:{},fn:this.program(2,a),inverse:this.noop,data:a}),null!=s&&(i+=s),i},2:function(e){var t,n=this.lambda,a=' \n"},4:function(){return' \n'},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i='\n\n"},useData:!0});var ApiKeyButton,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;ApiKeyButton=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.initialize=function(){},t.prototype.render=function(){var e;return e=this.template(),$(this.el).html(e(this.model)),this},t.prototype.events={"click #apikey_button":"toggleApiKeyContainer","click #apply_api_key":"applyApiKey"},t.prototype.applyApiKey=function(){var e;return window.authorizations.add(this.model.name,new ApiKeyAuthorization(this.model.name,$("#input_apiKey_entry").val(),this.model["in"])),window.swaggerUi.load(),e=$("#apikey_container").show()},t.prototype.toggleApiKeyContainer=function(){var e;return $("#apikey_container").length>0?(e=$("#apikey_container").first(),e.is(":visible")?e.hide():($(".auth_container").hide(),e.show())):void 0},t.prototype.template=function(){return Handlebars.templates.apikey_button_view},t}(Backbone.View),this.Handlebars.templates.main=Handlebars.template({1:function(e,t,n,a){var s,i=this.lambda,r=this.escapeExpression,l='
      '+r(i(null!=(s=null!=e?e.info:e)?s.title:s,e))+'
      \n
      ';return s=i(null!=(s=null!=e?e.info:e)?s.description:s,e),null!=s&&(l+=s),l+="
      \n ",s=t["if"].call(e,null!=(s=null!=e?e.info:e)?s.termsOfServiceUrl:s,{name:"if",hash:{},fn:this.program(2,a),inverse:this.noop,data:a}),null!=s&&(l+=s),l+="\n ",s=t["if"].call(e,null!=(s=null!=(s=null!=e?e.info:e)?s.contact:s)?s.name:s,{name:"if",hash:{},fn:this.program(4,a),inverse:this.noop,data:a}),null!=s&&(l+=s),l+="\n ",s=t["if"].call(e,null!=(s=null!=(s=null!=e?e.info:e)?s.contact:s)?s.url:s,{name:"if",hash:{},fn:this.program(6,a),inverse:this.noop,data:a}),null!=s&&(l+=s),l+="\n ",s=t["if"].call(e,null!=(s=null!=(s=null!=e?e.info:e)?s.contact:s)?s.email:s,{name:"if",hash:{},fn:this.program(8,a),inverse:this.noop,data:a}),null!=s&&(l+=s),l+="\n ",s=t["if"].call(e,null!=(s=null!=e?e.info:e)?s.license:s,{name:"if",hash:{},fn:this.program(10,a),inverse:this.noop,data:a}),null!=s&&(l+=s),l+"\n"},2:function(e){var t,n=this.lambda,a=this.escapeExpression;return''},4:function(e){var t,n=this.lambda,a=this.escapeExpression;return"
      Created by "+a(n(null!=(t=null!=(t=null!=e?e.info:e)?t.contact:t)?t.name:t,e))+"
      "},6:function(e){var t,n=this.lambda,a=this.escapeExpression;return""},8:function(e){var t,n=this.lambda,a=this.escapeExpression;return"'},10:function(e){var t,n=this.lambda,a=this.escapeExpression;return""},12:function(e){var t,n=this.lambda,a=this.escapeExpression;return' , api version: '+a(n(null!=(t=null!=e?e.info:e)?t.version:t,e))+"\n "},14:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return' \n \n'},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o=this.escapeExpression,p="
      \n";return s=t["if"].call(e,null!=e?e.info:e,{name:"if",hash:{},fn:this.program(1,a),inverse:this.noop,data:a}),null!=s&&(p+=s),p+="
      \n
      \n
        \n\n
        \n
        \n
        \n

        [ base url: "+o((i=null!=(i=t.basePath||(null!=e?e.basePath:e))?i:l,typeof i===r?i.call(e,{name:"basePath",hash:{},data:a}):i))+"\n",s=t["if"].call(e,null!=(s=null!=e?e.info:e)?s.version:s,{name:"if",hash:{},fn:this.program(12,a),inverse:this.noop,data:a}),null!=s&&(p+=s),p+="]\n",s=t["if"].call(e,null!=e?e.validatorUrl:e,{name:"if",hash:{},fn:this.program(14,a),inverse:this.noop,data:a}),null!=s&&(p+=s),p+"

        \n
        \n
        \n"},useData:!0});var BasicAuthButton,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;BasicAuthButton=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.initialize=function(){},t.prototype.render=function(){var e;return e=this.template(),$(this.el).html(e(this.model)),this},t.prototype.events={"click #basic_auth_button":"togglePasswordContainer","click #apply_basic_auth":"applyPassword"},t.prototype.applyPassword=function(){var e,t,n;return console.log("applying password"),n=$(".input_username").val(),t=$(".input_password").val(),window.authorizations.add(this.model.type,new PasswordAuthorization("basic",n,t)),window.swaggerUi.load(),e=$("#basic_auth_container").hide()},t.prototype.togglePasswordContainer=function(){var e;return $("#basic_auth_container").length>0?(e=$("#basic_auth_container").show(),e.is(":visible")?e.slideUp():($(".auth_container").hide(),e.show())):void 0},t.prototype.template=function(){return Handlebars.templates.basic_auth_button_view},t}(Backbone.View),this.Handlebars.templates.operation=Handlebars.template({1:function(){return"deprecated"},3:function(){return"

        Warning: Deprecated

        \n"},5:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o='

        Implementation Notes

        \n

        ';return i=null!=(i=t.description||(null!=e?e.description:e))?i:l,s=typeof i===r?i.call(e,{name:"description",hash:{},data:a}):i,null!=s&&(o+=s),o+"

        \n"},7:function(){return'
        \n '},9:function(e,t,n,a){var s,i=' \n"},10:function(e){var t,n=this.lambda,a=this.escapeExpression,s="
        "+a(n(null!=e?e.scope:e,e))+"
        \n"},12:function(){return"
        "},14:function(){return'
        \n \n
        \n'},16:function(){return'

        Response Class

        \n

        \n
        \n
        \n'},18:function(){return'

        Parameters

        \n \n \n \n \n \n \n \n \n \n \n \n\n \n
        ParameterValueDescriptionParameter TypeData Type
        \n'},20:function(){return"
        \n

        Response Messages

        \n \n \n \n \n \n \n \n \n \n \n \n
        HTTP Status CodeReasonResponse Model
        \n"},22:function(){return""},24:function(){return"
        \n \n \n \n
        \n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r,l="function",o=t.helperMissing,p=this.escapeExpression,u=t.blockHelperMissing,h="\n
          \n
        • \n \n \n
        • \n
        \n"},useData:!0});var ContentTypeView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;ContentTypeView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.initialize=function(){},t.prototype.render=function(){var e;return e=this.template(),$(this.el).html(e(this.model)),$("label[for=contentType]",$(this.el)).text("Response Content Type"),this},t.prototype.template=function(){return Handlebars.templates.content_type},t}(Backbone.View),this.Handlebars.templates.param=Handlebars.template({1:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e.isFile:e,{name:"if",hash:{},fn:this.program(2,a),inverse:this.program(4,a),data:a}),null!=s&&(i+=s),i},2:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return' \n
        \n'},4:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(5,a),inverse:this.program(7,a),data:a}),null!=s&&(i+=s),i},5:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n
        \n
        \n'},7:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n
        \n
        \n'},9:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e.isFile:e,{name:"if",hash:{},fn:this.program(2,a),inverse:this.program(10,a),data:a}),null!=s&&(i+=s),i},10:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(11,a),inverse:this.program(13,a),data:a}),null!=s&&(i+=s),i},11:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n"},13:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o=this.escapeExpression,p=""+o((i=null!=(i=t.name||(null!=e?e.name:e))?i:l,typeof i===r?i.call(e,{name:"name",hash:{},data:a}):i))+"\n\n\n";return s=t["if"].call(e,null!=e?e.isBody:e,{name:"if",hash:{},fn:this.program(1,a),inverse:this.program(9,a),data:a}),null!=s&&(p+=s),p+='\n\n',i=null!=(i=t.description||(null!=e?e.description:e))?i:l,s=typeof i===r?i.call(e,{name:"description",hash:{},data:a}):i,null!=s&&(p+=s),p+="\n",i=null!=(i=t.paramType||(null!=e?e.paramType:e))?i:l,s=typeof i===r?i.call(e,{name:"paramType",hash:{},data:a}):i,null!=s&&(p+=s),p+'\n\n \n\n'},useData:!0});var HeaderView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;HeaderView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.events={"click #show-pet-store-icon":"showPetStore","click #show-wordnik-dev-icon":"showWordnikDev","click #explore":"showCustom","keyup #input_baseUrl":"showCustomOnKeyup","keyup #input_apiKey":"showCustomOnKeyup"},t.prototype.initialize=function(){},t.prototype.showPetStore=function(){return this.trigger("update-swagger-ui",{url:"http://petstore.swagger.wordnik.com/api/api-docs"})},t.prototype.showWordnikDev=function(){return this.trigger("update-swagger-ui",{url:"http://api.wordnik.com/v4/resources.json"})},t.prototype.showCustomOnKeyup=function(e){return 13===e.keyCode?this.showCustom():void 0},t.prototype.showCustom=function(e){return null!=e&&e.preventDefault(),this.trigger("update-swagger-ui",{url:$("#input_baseUrl").val(),apiKey:$("#input_apiKey").val()})},t.prototype.update=function(e,t,n){return null==n&&(n=!1),$("#input_baseUrl").val(e),n?this.trigger("update-swagger-ui",{url:e}):void 0},t}(Backbone.View),this.Handlebars.templates.param_list=Handlebars.template({1:function(){return" multiple='multiple'"},3:function(){return""},5:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(3,a),inverse:this.program(6,a),data:a}),null!=s&&(i+=s),i},6:function(e,t,n,a){var s,i=t.helperMissing,r="";return s=(t.isArray||e&&e.isArray||i).call(e,e,{name:"isArray",hash:{},fn:this.program(3,a),inverse:this.program(7,a),data:a}),null!=s&&(r+=s),r},7:function(){return" \n"},9:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e.isDefault:e,{name:"if",hash:{},fn:this.program(10,a),inverse:this.program(12,a),data:a}),null!=s&&(i+=s),i},10:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return' \n"},12:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o=this.escapeExpression,p=""+o((i=null!=(i=t.name||(null!=e?e.name:e))?i:l,typeof i===r?i.call(e,{name:"name",hash:{},data:a}):i))+"\n\n \n\n',i=null!=(i=t.description||(null!=e?e.description:e))?i:l,s=typeof i===r?i.call(e,{name:"description",hash:{},data:a}):i,null!=s&&(p+=s),p+="\n",i=null!=(i=t.paramType||(null!=e?e.paramType:e))?i:l,s=typeof i===r?i.call(e,{name:"paramType",hash:{},data:a}):i,null!=s&&(p+=s),p+'\n'},useData:!0});var MainView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;MainView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}var n;return __extends(t,e),n={alpha:function(e,t){return e.path.localeCompare(t.path)},method:function(e,t){return e.method.localeCompare(t.method)}},t.prototype.initialize=function(e){var t,n,a,s;null==e&&(e={}),this.model.auths=[],s=this.model.securityDefinitions;for(n in s)a=s[n],t={name:n,type:a.type,value:a},this.model.auths.push(t);return"2.0"===this.model.swaggerVersion?this.model.validatorUrl="validatorUrl"in e.swaggerOptions?e.swaggerOptions.validatorUrl:this.model.url.indexOf("localhost")>0?null:"http://online.swagger.io/validator":void 0},t.prototype.render=function(){var e,t,n,a,s,i,r,l,o,p;if(this.model.securityDefinitions)for(s in this.model.securityDefinitions)e=this.model.securityDefinitions[s],"apiKey"===e.type&&0===$("#apikey_button").length&&(t=new ApiKeyButton({model:e}).render().el,$(".auth_main_container").append(t)),"basicAuth"===e.type&&0===$("#basic_auth_button").length&&(t=new BasicAuthButton({model:e}).render().el,$(".auth_main_container").append(t));for($(this.el).html(Handlebars.templates.main(this.model)),r={},n=0,p=this.model.apisArray,l=0,o=p.length;o>l;l++){for(i=p[l],a=i.name;"undefined"!=typeof r[a];)a=a+"_"+n,n+=1;i.id=a,r[a]=i,this.addResource(i,this.model.auths)}return $(".propWrap").hover(function(){return $(".optionsWrapper",$(this)).show() +},function(){return $(".optionsWrapper",$(this)).hide()}),this},t.prototype.addResource=function(e,t){var n;return e.id=e.id.replace(/\s/g,"_"),n=new ResourceView({model:e,tagName:"li",id:"resource_"+e.id,className:"resource",auths:t,swaggerOptions:this.options.swaggerOptions}),$("#resources").append(n.render().el)},t.prototype.clear=function(){return $(this.el).html("")},t}(Backbone.View),this.Handlebars.templates.param_readonly=Handlebars.template({1:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n"},3:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(4,a),inverse:this.program(6,a),data:a}),null!=s&&(i+=s),i},4:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" "+l((s=null!=(s=t["default"]||(null!=e?e["default"]:e))?s:r,typeof s===i?s.call(e,{name:"default",hash:{},data:a}):s))+"\n"},6:function(){return" (empty)\n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o=this.escapeExpression,p=""+o((i=null!=(i=t.name||(null!=e?e.name:e))?i:l,typeof i===r?i.call(e,{name:"name",hash:{},data:a}):i))+"\n\n";return s=t["if"].call(e,null!=e?e.isBody:e,{name:"if",hash:{},fn:this.program(1,a),inverse:this.program(3,a),data:a}),null!=s&&(p+=s),p+='\n',i=null!=(i=t.description||(null!=e?e.description:e))?i:l,s=typeof i===r?i.call(e,{name:"description",hash:{},data:a}):i,null!=s&&(p+=s),p+="\n",i=null!=(i=t.paramType||(null!=e?e.paramType:e))?i:l,s=typeof i===r?i.call(e,{name:"paramType",hash:{},data:a}):i,null!=s&&(p+=s),p+'\n\n'},useData:!0});var OperationView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;OperationView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.invocationUrl=null,t.prototype.events={"submit .sandbox":"submitOperation","click .submit":"submitOperation","click .response_hider":"hideResponse","click .toggleOperation":"toggleOperationContent","mouseenter .api-ic":"mouseEnter","mouseout .api-ic":"mouseExit"},t.prototype.initialize=function(e){return null==e&&(e={}),this.auths=e.auths,this},t.prototype.mouseEnter=function(e){var t,n,a,s,i,r,l,o,p,u;return t=$(this.el).find(".content"),p=e.pageX,u=e.pageY,r=$(window).scrollLeft(),l=$(window).scrollTop(),s=r+$(window).width(),i=l+$(window).height(),o=t.width(),n=t.height(),p+o>s&&(p=s-o),r>p&&(p=r),u+n>i&&(u=i-n),l>u&&(u=l),a={},a.top=u,a.left=p,t.css(a),$(e.currentTarget.parentNode).find("#api_information_panel").show()},t.prototype.mouseExit=function(e){return $(e.currentTarget.parentNode).find("#api_information_panel").hide()},t.prototype.render=function(){var e,t,n,a,s,i,r,l,o,p,u,h,c,d,m,f,y,g,v,_,w,b,x,k,O,C,P,S,T,D,H,R,E,M,V,N,U,A,F;if(r=!0,r||(this.model.isReadOnly=!0),this.model.description=this.model.description||this.model.notes,this.model.description&&(this.model.description=this.model.description.replace(/(?:\r\n|\r|\n)/g,"
        ")),this.model.oauth=null,p=this.model.authorizations||this.model.security)if(Array.isArray(p))for(O=0,T=p.length;T>O;O++){n=p[O];for(o in n){t=n[o];for(e in this.auths)if(t=this.auths[e],"oauth2"===t.type){this.model.oauth={},this.model.oauth.scopes=[],V=t.value.scopes;for(l in V)x=V[l],g=n[o].indexOf(l),g>=0&&(u={scope:l,description:x},this.model.oauth.scopes.push(u))}}}else for(l in p)if(x=p[l],"oauth2"===l)for(null===this.model.oauth&&(this.model.oauth={}),void 0===this.model.oauth.scopes&&(this.model.oauth.scopes=[]),C=0,D=x.length;D>C;C++)u=x[C],this.model.oauth.scopes.push(u);if("undefined"!=typeof this.model.responses){this.model.responseMessages=[],N=this.model.responses;for(a in N)k=N[a],f=null,y=this.model.responses[a].schema,y&&y.$ref&&(f=y.$ref,0===f.indexOf("#/definitions/")&&(f=f.substring("#/definitions/".length))),this.model.responseMessages.push({code:a,message:k.description,responseModel:f})}if("undefined"==typeof this.model.responseMessages&&(this.model.responseMessages=[]),$(this.el).html(Handlebars.templates.operation(this.model)),v=null,this.model.successResponse){w=this.model.successResponse;for(o in w)k=w[o],"object"==typeof k&&"function"==typeof k.createJSONSample&&(i="bar",v={sampleJSON:JSON.stringify(k.createJSONSample(),void 0,2),isParam:!1,signature:k.getMockSignature()})}else this.model.responseClassSignature&&"string"!==this.model.responseClassSignature&&(v={sampleJSON:this.model.responseSampleJSON,isParam:!1,signature:this.model.responseClassSignature});for(v?(m=new SignatureView({model:v,tagName:"div"}),$(".model-signature",$(this.el)).append(m.render().el)):(this.model.responseClassSignature="string",$(".model-signature",$(this.el)).html(this.model.type)),s={isParam:!1},s.consumes=this.model.consumes,s.produces=this.model.produces,U=this.model.parameters,P=0,H=U.length;H>P;P++)h=U[P],b=h.type||h.dataType||"","undefined"==typeof b&&(f=h.schema,f&&f.$ref&&(c=f.$ref,b=0===c.indexOf("#/definitions/")?c.substring("#/definitions/".length):c)),b&&"file"===b.toLowerCase()&&(s.consumes||(s.consumes="multipart/form-data")),h.type=b;for(d=new ResponseContentTypeView({model:s}),$(".response-content-type",$(this.el)).append(d.render().el),A=this.model.parameters,S=0,R=A.length;R>S;S++)h=A[S],this.addParameter(h,s.consumes);for(F=this.model.responseMessages,M=0,E=F.length;E>M;M++)_=F[M],this.addStatusCode(_);return this},t.prototype.addParameter=function(e,t){var n;return e.consumes=t,n=new ParameterView({model:e,tagName:"tr",readOnly:this.model.isReadOnly}),$(".operation-params",$(this.el)).append(n.render().el)},t.prototype.addStatusCode=function(e){var t;return t=new StatusCodeView({model:e,tagName:"tr"}),$(".operation-status",$(this.el)).append(t.render().el)},t.prototype.submitOperation=function(e){var t,n,a,s,i,r,l,o,p,u,h,c,d,m,f,y;if(null!=e&&e.preventDefault(),n=$(".sandbox",$(this.el)),t=!0,n.find("input.required").each(function(){return $(this).removeClass("error"),""===jQuery.trim($(this).val())?($(this).addClass("error"),$(this).wiggle({callback:function(e){return function(){return $(e).focus()}}(this)}),t=!1):void 0}),n.find("textarea.required").each(function(){return $(this).removeClass("error"),""===jQuery.trim($(this).val())?($(this).addClass("error"),$(this).wiggle({callback:function(e){return function(){return $(e).focus()}}(this)}),t=!1):void 0}),t){for(s={},r={parent:this},a=!1,m=n.find("input"),o=0,h=m.length;h>o;o++)i=m[o],null!=i.value&&jQuery.trim(i.value).length>0&&(s[i.name]=i.value),"file"===i.type&&(a=!0);for(f=n.find("textarea"),p=0,c=f.length;c>p;p++)i=f[p],null!=i.value&&jQuery.trim(i.value).length>0&&(s[i.name]=i.value);for(y=n.find("select"),u=0,d=y.length;d>u;u++)i=y[u],l=this.getSelectedValue(i),null!=l&&jQuery.trim(l).length>0&&(s[i.name]=l);return r.responseContentType=$("div select[name=responseContentType]",$(this.el)).val(),r.requestContentType=$("div select[name=parameterContentType]",$(this.el)).val(),$(".response_throbber",$(this.el)).show(),a?this.handleFileUpload(s,n):this.model["do"](s,r,this.showCompleteStatus,this.showErrorStatus,this)}},t.prototype.success=function(e,t){return t.showCompleteStatus(e)},t.prototype.handleFileUpload=function(e,t){var n,a,s,i,r,l,o,p,u,h,c,d,m,f,y,g,v,_,w;for(g=t.serializeArray(),p=0,d=g.length;d>p;p++)i=g[p],null!=i.value&&jQuery.trim(i.value).length>0&&(e[i.name]=i.value);for(n=new FormData,o=0,v=this.model.parameters,u=0,m=v.length;m>u;u++)l=v[u],"form"===l.paramType&&"file"!==l.type.toLowerCase()&&void 0!==e[l.name]&&n.append(l.name,e[l.name]);for(s={},_=this.model.parameters,h=0,f=_.length;f>h;h++)l=_[h],"header"===l.paramType&&(s[l.name]=e[l.name]);for(w=t.find('input[type~="file"]'),c=0,y=w.length;y>c;c++)a=w[c],"undefined"!=typeof a.files[0]&&(n.append($(a).attr("name"),a.files[0]),o+=1);return this.invocationUrl=this.model.supportHeaderParams()?(s=this.model.getHeaderParams(e),delete s["Content-Type"],this.model.urlify(e,!1)):this.model.urlify(e,!0),$(".request_url",$(this.el)).html("
        "),$(".request_url pre",$(this.el)).text(this.invocationUrl),r={type:this.model.method,url:this.invocationUrl,headers:s,data:n,dataType:"json",contentType:!1,processData:!1,error:function(e){return function(t){return e.showErrorStatus(e.wrap(t),e)}}(this),success:function(e){return function(t){return e.showResponse(t,e)}}(this),complete:function(e){return function(t){return e.showCompleteStatus(e.wrap(t),e)}}(this)},window.authorizations&&window.authorizations.apply(r),0===o&&r.data.append("fake","true"),jQuery.ajax(r),!1},t.prototype.wrap=function(e){var t,n,a,s,i,r,l;for(a={},n=e.getAllResponseHeaders().split("\r"),r=0,l=n.length;l>r;r++)s=n[r],t=s.match(/^([^:]*?):(.*)$/),t||(t=[]),t.shift(),void 0!==t[0]&&void 0!==t[1]&&(a[t[0].trim()]=t[1].trim());return i={},i.content={},i.content.data=e.responseText,i.headers=a,i.request={},i.request.url=this.invocationUrl,i.status=e.status,i},t.prototype.getSelectedValue=function(e){var t,n,a,s,i;if(e.multiple){for(n=[],i=e.options,a=0,s=i.length;s>a;a++)t=i[a],t.selected&&n.push(t.value);return n.length>0?n:null}return e.value},t.prototype.hideResponse=function(e){return null!=e&&e.preventDefault(),$(".response",$(this.el)).slideUp(),$(".response_hider",$(this.el)).fadeOut()},t.prototype.showResponse=function(e){var t;return t=JSON.stringify(e,null,"	").replace(/\n/g,"
        "),$(".response_body",$(this.el)).html(escape(t))},t.prototype.showErrorStatus=function(e,t){return t.showStatus(e)},t.prototype.showCompleteStatus=function(e,t){return t.showStatus(e)},t.prototype.formatXml=function(e){var t,n,a,s,i,r,l,o,p,u,h,c,d;for(o=/(>)(<)(\/*)/g,u=/[ ]*(.*)[ ]+\n/g,t=/(<.+>)(.+\n)/g,e=e.replace(o,"$1\n$2$3").replace(u,"$1\n").replace(t,"$1\n$2"),l=0,n="",i=e.split("\n"),a=0,s="other",p={"single->single":0,"single->closing":-1,"single->opening":0,"single->other":0,"closing->single":0,"closing->closing":-1,"closing->opening":0,"closing->other":0,"opening->single":1,"opening->closing":0,"opening->opening":1,"opening->other":1,"other->single":0,"other->closing":-1,"other->opening":0,"other->other":0},h=function(e){var t,i,r,l,o,u,h;return u={single:Boolean(e.match(/<.+\/>/)),closing:Boolean(e.match(/<\/.+>/)),opening:Boolean(e.match(/<[^!?].*>/))},o=function(){var e;e=[];for(r in u)h=u[r],h&&e.push(r);return e}()[0],o=void 0===o?"other":o,t=s+"->"+o,s=o,l="",a+=p[t],l=function(){var e,t,n;for(n=[],i=e=0,t=a;t>=0?t>e:e>t;i=t>=0?++e:--e)n.push(" ");return n}().join(""),"opening->closing"===t?n=n.substr(0,n.length-1)+e+"\n":n+=l+e+"\n"},c=0,d=i.length;d>c;c++)r=i[c],h(r);return n},t.prototype.showStatus=function(e){var t,n,a,s,i,r,l,o,p,u,h;if(void 0===e.content?(n=e.data,h=e.url):(n=e.content.data,h=e.request.url),i=e.headers,a=null,i&&(a=i["Content-Type"]||i["content-type"],a&&(a=a.split(";")[0].trim())),$(".response_body",$(this.el)).removeClass("json"),$(".response_body",$(this.el)).removeClass("xml"),n)if("application/json"===a||/\+json$/.test(a)){r=null;try{r=JSON.stringify(JSON.parse(n),null," ")}catch(c){s=c,r="can't parse JSON. Raw result:\n\n"+n}t=$("").text(r),o=$('
        ').append(t)}else"application/xml"===a||/\+xml$/.test(a)?(t=$("").text(this.formatXml(n)),o=$('
        ').append(t)):"text/html"===a?(t=$("").html(_.escape(n)),o=$('
        ').append(t)):/^image\//.test(a)?o=$("").attr("src",h):(t=$("").text(n),o=$('
        ').append(t));else t=$("").text("no content"),o=$('
        ').append(t);return p=o,$(".request_url",$(this.el)).html("
        "),$(".request_url pre",$(this.el)).text(h),$(".response_code",$(this.el)).html("
        "+e.status+"
        "),$(".response_body",$(this.el)).html(p),$(".response_headers",$(this.el)).html("
        "+_.escape(JSON.stringify(e.headers,null,"  ")).replace(/\n/g,"
        ")+"
        "),$(".response",$(this.el)).slideDown(),$(".response_hider",$(this.el)).show(),$(".response_throbber",$(this.el)).hide(),u=$(".response_body",$(this.el))[0],l=this.options.swaggerOptions,l.highlightSizeThreshold&&e.data.length>l.highlightSizeThreshold?u:hljs.highlightBlock(u)},t.prototype.toggleOperationContent=function(){var e;return e=$("#"+Docs.escapeResourceName(this.model.parentId+"_"+this.model.nickname+"_content")),e.is(":visible")?Docs.collapseOperation(e):Docs.expandOperation(e)},t}(Backbone.View),this.Handlebars.templates.param_readonly_required=Handlebars.template({1:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n"},3:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(4,a),inverse:this.program(6,a),data:a}),null!=s&&(i+=s),i},4:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" "+l((s=null!=(s=t["default"]||(null!=e?e["default"]:e))?s:r,typeof s===i?s.call(e,{name:"default",hash:{},data:a}):s))+"\n"},6:function(){return" (empty)\n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o=this.escapeExpression,p=""+o((i=null!=(i=t.name||(null!=e?e.name:e))?i:l,typeof i===r?i.call(e,{name:"name",hash:{},data:a}):i))+"\n\n";return s=t["if"].call(e,null!=e?e.isBody:e,{name:"if",hash:{},fn:this.program(1,a),inverse:this.program(3,a),data:a}),null!=s&&(p+=s),p+='\n',i=null!=(i=t.description||(null!=e?e.description:e))?i:l,s=typeof i===r?i.call(e,{name:"description",hash:{},data:a}):i,null!=s&&(p+=s),p+="\n",i=null!=(i=t.paramType||(null!=e?e.paramType:e))?i:l,s=typeof i===r?i.call(e,{name:"paramType",hash:{},data:a}):i,null!=s&&(p+=s),p+'\n\n'},useData:!0});var ParameterContentTypeView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;ParameterContentTypeView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.initialize=function(){},t.prototype.render=function(){var e;return e=this.template(),$(this.el).html(e(this.model)),$("label[for=parameterContentType]",$(this.el)).text("Parameter content type:"),this},t.prototype.template=function(){return Handlebars.templates.parameter_content_type},t}(Backbone.View),this.Handlebars.templates.param_required=Handlebars.template({1:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e.isFile:e,{name:"if",hash:{},fn:this.program(2,a),inverse:this.program(4,a),data:a}),null!=s&&(i+=s),i},2:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return' \n"},4:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(5,a),inverse:this.program(7,a),data:a}),null!=s&&(i+=s),i},5:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n
        \n
        \n'},7:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n
        \n
        \n'},9:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e.isFile:e,{name:"if",hash:{},fn:this.program(10,a),inverse:this.program(12,a),data:a}),null!=s&&(i+=s),i},10:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n"},12:function(e,t,n,a){var s,i="";return s=t["if"].call(e,null!=e?e["default"]:e,{name:"if",hash:{},fn:this.program(13,a),inverse:this.program(15,a),data:a}),null!=s&&(i+=s),i},13:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n"},15:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return" \n"},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o=this.escapeExpression,p=""+o((i=null!=(i=t.name||(null!=e?e.name:e))?i:l,typeof i===r?i.call(e,{name:"name",hash:{},data:a}):i))+"\n\n";return s=t["if"].call(e,null!=e?e.isBody:e,{name:"if",hash:{},fn:this.program(1,a),inverse:this.program(9,a),data:a}),null!=s&&(p+=s),p+='\n\n ',i=null!=(i=t.description||(null!=e?e.description:e))?i:l,s=typeof i===r?i.call(e,{name:"description",hash:{},data:a}):i,null!=s&&(p+=s),p+="\n\n",i=null!=(i=t.paramType||(null!=e?e.paramType:e))?i:l,s=typeof i===r?i.call(e,{name:"paramType",hash:{},data:a}):i,null!=s&&(p+=s),p+'\n\n'},useData:!0});var ParameterView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;ParameterView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.initialize=function(){return Handlebars.registerHelper("isArray",function(e,t){return"array"===e.type.toLowerCase()||e.allowMultiple?t.fn(this):t.inverse(this)})},t.prototype.render=function(){var e,t,n,a,s,i,r,l,o,p;return p=this.model.type||this.model.dataType,"undefined"==typeof p&&(i=this.model.schema,i&&i.$ref&&(a=i.$ref,p=0===a.indexOf("#/definitions/")?a.substring("#/definitions/".length):a)),this.model.type=p,this.model.paramType=this.model["in"]||this.model.paramType,"body"===this.model.paramType&&(this.model.isBody=!0),p&&"file"===p.toLowerCase()&&(this.model.isFile=!0),this.model["default"]=this.model["default"]||this.model.defaultValue,this.model.allowableValues&&(this.model.isList=!0),o=this.template(),$(this.el).html(o(this.model)),r={sampleJSON:this.model.sampleJSON,isParam:!0,signature:this.model.signature},this.model.sampleJSON?(l=new SignatureView({model:r,tagName:"div"}),$(".model-signature",$(this.el)).append(l.render().el)):$(".model-signature",$(this.el)).html(this.model.signature),t=!1,this.model.isBody&&(t=!0),e={isParam:t},e.consumes=this.model.consumes,t?(n=new ParameterContentTypeView({model:e}),$(".parameter-content-type",$(this.el)).append(n.render().el)):(s=new ResponseContentTypeView({model:e}),$(".response-content-type",$(this.el)).append(s.render().el)),this},t.prototype.template=function(){return this.model.isList?Handlebars.templates.param_list:this.options.readOnly?this.model.required?Handlebars.templates.param_readonly_required:Handlebars.templates.param_readonly:this.model.required?Handlebars.templates.param_required:Handlebars.templates.param},t}(Backbone.View),this.Handlebars.templates.parameter_content_type=Handlebars.template({1:function(e,t,n,a){var s,i="";return s=t.each.call(e,null!=e?e.consumes:e,{name:"each",hash:{},fn:this.program(2,a),inverse:this.noop,data:a}),null!=s&&(i+=s),i},2:function(e){var t,n=this.lambda,a=' \n"},4:function(){return' \n'},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i='\n\n"},useData:!0});var ResourceView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;ResourceView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.initialize=function(e){return null==e&&(e={}),this.auths=e.auths,""===this.model.description?this.model.description=null:void 0},t.prototype.render=function(){var e,t,n,a,s,i,r;for($(this.el).html(Handlebars.templates.resource(this.model)),n={},this.model.description&&(this.model.summary=this.model.description),r=this.model.operationsArray,s=0,i=r.length;i>s;s++){for(a=r[s],e=0,t=a.nickname;"undefined"!=typeof n[t];)t=t+"_"+e,e+=1;n[t]=a,a.nickname=t,a.parentId=this.model.id,this.addOperation(a)}return $(".toggleEndpointList",this.el).click(this.callDocs.bind(this,"toggleEndpointListForResource")),$(".collapseResource",this.el).click(this.callDocs.bind(this,"collapseOperationsForResource")),$(".expandResource",this.el).click(this.callDocs.bind(this,"expandOperationsForResource")),this},t.prototype.addOperation=function(e){var t;return e.number=this.number,t=new OperationView({model:e,tagName:"li",className:"endpoint",swaggerOptions:this.options.swaggerOptions,auths:this.auths}),$(".endpoints",$(this.el)).append(t.render().el),this.number++},t.prototype.callDocs=function(e,t){return t.preventDefault(),Docs[e](t.currentTarget.getAttribute("data-id"))},t}(Backbone.View),this.Handlebars.templates.resource=Handlebars.template({1:function(){return" : "},3:function(e,t,n,a){var s,i="function",r=t.helperMissing,l=this.escapeExpression;return"
      • \n Raw\n
      • "},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r,l="function",o=t.helperMissing,p=this.escapeExpression,u=t.blockHelperMissing,h="
        \n

        \n '+p((i=null!=(i=t.name||(null!=e?e.name:e))?i:o,typeof i===l?i.call(e,{name:"name",hash:{},data:a}):i))+" ";return i=null!=(i=t.summary||(null!=e?e.summary:e))?i:o,r={name:"summary",hash:{},fn:this.program(1,a),inverse:this.noop,data:a},s=typeof i===l?i.call(e,r):i,t.summary||(s=u.call(e,s,r)),null!=s&&(h+=s),i=null!=(i=t.summary||(null!=e?e.summary:e))?i:o,s=typeof i===l?i.call(e,{name:"summary",hash:{},data:a}):i,null!=s&&(h+=s),h+="\n

        \n
          \n
        • \n Show/Hide\n
        • \n
        • \n \n List Operations\n \n
        • \n
        • \n \n Expand Operations\n \n
        • \n ',i=null!=(i=t.url||(null!=e?e.url:e))?i:o,r={name:"url",hash:{},fn:this.program(3,a),inverse:this.noop,data:a},s=typeof i===l?i.call(e,r):i,t.url||(s=u.call(e,s,r)),null!=s&&(h+=s),h+"\n
        \n
        \n\n"},useData:!0});var ResponseContentTypeView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;ResponseContentTypeView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.initialize=function(){},t.prototype.render=function(){var e;return e=this.template(),$(this.el).html(e(this.model)),$("label[for=responseContentType]",$(this.el)).text("Response Content Type"),this},t.prototype.template=function(){return Handlebars.templates.response_content_type},t}(Backbone.View),this.Handlebars.templates.response_content_type=Handlebars.template({1:function(e,t,n,a){var s,i="";return s=t.each.call(e,null!=e?e.produces:e,{name:"each",hash:{},fn:this.program(2,a),inverse:this.noop,data:a}),null!=s&&(i+=s),i},2:function(e){var t,n=this.lambda,a=' \n"},4:function(){return' \n'},compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i='\n\n"},useData:!0});var SignatureView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;SignatureView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.events={"click a.description-link":"switchToDescription","click a.snippet-link":"switchToSnippet","mousedown .snippet":"snippetToTextArea"},t.prototype.initialize=function(){},t.prototype.render=function(){var e;return e=this.template(),$(this.el).html(e(this.model)),this.switchToSnippet(),this.isParam=this.model.isParam,this.isParam&&$(".notice",$(this.el)).text("Click to set as parameter value"),this},t.prototype.template=function(){return Handlebars.templates.signature},t.prototype.switchToDescription=function(e){return null!=e&&e.preventDefault(),$(".snippet",$(this.el)).hide(),$(".description",$(this.el)).show(),$(".description-link",$(this.el)).addClass("selected"),$(".snippet-link",$(this.el)).removeClass("selected")},t.prototype.switchToSnippet=function(e){return null!=e&&e.preventDefault(),$(".description",$(this.el)).hide(),$(".snippet",$(this.el)).show(),$(".snippet-link",$(this.el)).addClass("selected"),$(".description-link",$(this.el)).removeClass("selected")},t.prototype.snippetToTextArea=function(e){var t;return this.isParam&&(null!=e&&e.preventDefault(),t=$("textarea",$(this.el.parentNode.parentNode.parentNode)),""===$.trim(t.val()))?t.val(this.model.sampleJSON):void 0},t}(Backbone.View),this.Handlebars.templates.signature=Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o=this.escapeExpression,p='
        \n\n
        \n\n
        \n
        \n ';return i=null!=(i=t.signature||(null!=e?e.signature:e))?i:l,s=typeof i===r?i.call(e,{name:"signature",hash:{},data:a}):i,null!=s&&(p+=s),p+'\n
        \n\n
        \n
        '+o((i=null!=(i=t.sampleJSON||(null!=e?e.sampleJSON:e))?i:l,typeof i===r?i.call(e,{name:"sampleJSON",hash:{},data:a}):i))+'
        \n \n
        \n
        \n\n'},useData:!0});var StatusCodeView,__extends=function(e,t){function n(){this.constructor=e}for(var a in t)__hasProp.call(t,a)&&(e[a]=t[a]);return n.prototype=t.prototype,e.prototype=new n,e.__super__=t.prototype,e},__hasProp={}.hasOwnProperty;StatusCodeView=function(e){function t(){return t.__super__.constructor.apply(this,arguments)}return __extends(t,e),t.prototype.initialize=function(){},t.prototype.render=function(){var e,t,n;return n=this.template(),$(this.el).html(n(this.model)),swaggerUi.api.models.hasOwnProperty(this.model.responseModel)?(e={sampleJSON:JSON.stringify(swaggerUi.api.models[this.model.responseModel].createJSONSample(),null,2),isParam:!1,signature:swaggerUi.api.models[this.model.responseModel].getMockSignature()},t=new SignatureView({model:e,tagName:"div"}),$(".model-signature",this.$el).append(t.render().el)):$(".model-signature",this.$el).html(""),this},t.prototype.template=function(){return Handlebars.templates.status_code},t}(Backbone.View),this.Handlebars.templates.status_code=Handlebars.template({compiler:[6,">= 2.0.0-beta.1"],main:function(e,t,n,a){var s,i,r="function",l=t.helperMissing,o=this.escapeExpression,p=""+o((i=null!=(i=t.code||(null!=e?e.code:e))?i:l,typeof i===r?i.call(e,{name:"code",hash:{},data:a}):i))+"\n";return i=null!=(i=t.message||(null!=e?e.message:e))?i:l,s=typeof i===r?i.call(e,{name:"message",hash:{},data:a}):i,null!=s&&(p+=s),p+"\n"},useData:!0}); \ No newline at end of file diff --git a/lib/swagger-client.js b/lib/swagger-client.js index 2b5b850b..84c13f8f 100644 --- a/lib/swagger-client.js +++ b/lib/swagger-client.js @@ -273,33 +273,33 @@ PrimitiveModel.prototype.getMockSignature = function(modelsToIgnore) { } return returnVal; }; -/** - * Provides support for 1.x versions of swagger - */ -var SwaggerApi = function (url, options) { +var SwaggerClient = function(url, options) { this.isBuilt = false; this.url = null; this.debug = false; this.basePath = null; + this.modelsArray = []; this.authorizations = null; this.authorizationScheme = null; + this.isValid = false; this.info = null; this.useJQuery = false; - this.modelsArray = []; - this.isValid = false; - options = (options || {}); - if (url) - if (url.url) - options = url; - else - this.url = url; - else + if(typeof url !== 'undefined') + return this.initialize(url, options); +}; + +SwaggerClient.prototype.initialize = function (url, options) { + this.models = models; + + options = (options||{}); + + if(typeof url === 'string') + this.url = url; + else if(typeof url === 'object') { options = url; - - if (typeof options.url === 'string') this.url = options.url; - + } this.swaggerRequstHeaders = options.swaggerRequstHeaders || 'application/json;charset=utf-8,*/*'; this.defaultSuccessCallback = options.defaultSuccessCallback || null; this.defaultErrorCallback = options.defaultErrorCallback || null; @@ -307,7 +307,7 @@ var SwaggerApi = function (url, options) { if (typeof options.success === 'function') this.success = options.success; - if (typeof options.useJQuery === 'boolean') + if (options.useJQuery) this.useJQuery = options.useJQuery; if (options.authorizations) { @@ -318,59 +318,1166 @@ var SwaggerApi = function (url, options) { } this.supportedSubmitMethods = options.supportedSubmitMethods || []; - this.failure = typeof options.failure === 'function' ? options.failure : function () { }; - this.progress = typeof options.progress === 'function' ? options.progress : function () { }; + this.failure = options.failure || function() {}; + this.progress = options.progress || function() {}; + this.spec = options.spec; + this.options = options; + if (typeof options.success === 'function') { this.build(); - this.isBuilt = true; + // this.isBuilt = true; } }; -SwaggerApi.prototype.build = function (mock) { - if (this.isBuilt) - return this; - var _this = this; +SwaggerClient.prototype.build = function(mock) { + if (this.isBuilt) return this; + var self = this; this.progress('fetching resource list: ' + this.url); var obj = { useJQuery: this.useJQuery, url: this.url, - method: 'GET', + method: "get", headers: { - accept: _this.swaggerRequstHeaders + accept: this.swaggerRequstHeaders }, on: { - error: function (response) { - if (_this.url.substring(0, 4) !== 'http') { - return _this.fail('Please specify the protocol for ' + _this.url); - } else if (response.status === 0) { - return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.'); - } else if (response.status === 404) { - return _this.fail('Can\'t read swagger JSON from ' + _this.url); - } else { - return _this.fail(response.status + ' : ' + response.statusText + ' ' + _this.url); - } + error: function(response) { + if (self.url.substring(0, 4) !== 'http') + return self.fail('Please specify the protocol for ' + self.url); + else if (response.status === 0) + return self.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.'); + else if (response.status === 404) + return self.fail('Can\'t read swagger JSON from ' + self.url); + else + return self.fail(response.status + ' : ' + response.statusText + ' ' + self.url); }, - response: function (resp) { + response: function(resp) { var responseObj = resp.obj || JSON.parse(resp.data); - _this.swaggerVersion = responseObj.swaggerVersion; - if (_this.swaggerVersion === '1.2') { - return _this.buildFromSpec(responseObj); - } else { - return _this.buildFrom1_1Spec(responseObj); + self.swaggerVersion = responseObj.swaggerVersion; + + if(responseObj.swagger && parseInt(responseObj.swagger) === 2) { + self.swaggerVersion = responseObj.swagger; + self.buildFromSpec(responseObj); + self.isValid = true; + } + else { + if (self.swaggerVersion === '1.2') { + return self.buildFrom1_2Spec(responseObj); + } else { + return self.buildFrom1_1Spec(responseObj); + } } } } }; - var e = (typeof window !== 'undefined' ? window : exports); - e.authorizations.apply(obj); - if (mock === true) - return obj; + if(this.spec) { + setTimeout(function() { self.buildFromSpec(self.spec); }, 10); + } + else { + var e = (typeof window !== 'undefined' ? window : exports); + var status = e.authorizations.apply(obj); + if(mock) + return obj; + new SwaggerHttp().execute(obj); + } - new SwaggerHttp().execute(obj); return this; }; -SwaggerApi.prototype.buildFromSpec = function (response) { +SwaggerClient.prototype.buildFromSpec = function(response) { + if(this.isBuilt) return this; + + this.info = response.info || {}; + this.title = response.title || ''; + this.host = response.host || ''; + this.schemes = response.schemes || []; + this.basePath = response.basePath || ''; + this.apis = {}; + this.apisArray = []; + this.consumes = response.consumes; + this.produces = response.produces; + this.securityDefinitions = response.securityDefinitions; + + // legacy support + this.authSchemes = response.securityDefinitions; + + var location; + + if(typeof this.url === 'string') { + location = this.parseUri(this.url); + } + + if(typeof this.schemes === 'undefined' || this.schemes.length === 0) { + this.scheme = location.scheme || 'http'; + } + else { + this.scheme = this.schemes[0]; + } + + if(typeof this.host === 'undefined' || this.host === '') { + this.host = location.host; + if (location.port) { + this.host = this.host + ':' + location.port; + } + } + + this.definitions = response.definitions; + var key; + for(key in this.definitions) { + var model = new Model(key, this.definitions[key]); + if(model) { + models[key] = model; + } + } + + // get paths, create functions for each operationId + var path; + var operations = []; + for(path in response.paths) { + if(typeof response.paths[path] === 'object') { + var httpMethod; + for(httpMethod in response.paths[path]) { + if(['delete', 'get', 'head', 'options', 'patch', 'post', 'put'].indexOf(httpMethod) === -1) { + continue; + } + var operation = response.paths[path][httpMethod]; + var tags = operation.tags; + if(typeof tags === 'undefined') { + operation.tags = [ 'default' ]; + tags = operation.tags; + } + var operationId = this.idFromOp(path, httpMethod, operation); + var operationObject = new Operation ( + this, + operation.scheme, + operationId, + httpMethod, + path, + operation, + this.definitions + ); + // bind this operation's execute command to the api + if(tags.length > 0) { + var i; + for(i = 0; i < tags.length; i++) { + var tag = this.tagFromLabel(tags[i]); + var operationGroup = this[tag]; + if(typeof operationGroup === 'undefined') { + this[tag] = []; + operationGroup = this[tag]; + operationGroup.operations = {}; + operationGroup.label = tag; + operationGroup.apis = []; + this[tag].help = this.help.bind(operationGroup); + this.apisArray.push(new OperationGroup(tag, operationObject)); + } + operationGroup[operationId] = operationObject.execute.bind(operationObject); + operationGroup[operationId].help = operationObject.help.bind(operationObject); + operationGroup.apis.push(operationObject); + operationGroup.operations[operationId] = operationObject; + + // legacy UI feature + var j; + var api; + for(j = 0; j < this.apisArray.length; j++) { + if(this.apisArray[j].tag === tag) { + api = this.apisArray[j]; + } + } + if(api) { + api.operationsArray.push(operationObject); + } + } + } + else { + log('no group to bind to'); + } + } + } + } + this.isBuilt = true; + if (this.success) + this.success(); + return this; +}; + +SwaggerClient.prototype.parseUri = function(uri) { + var urlParseRE = /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/; + var parts = urlParseRE.exec(uri); + return { + scheme: parts[4].replace(':',''), + host: parts[11], + port: parts[12], + path: parts[15] + }; +}; + +SwaggerClient.prototype.help = function() { + var i; + log('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); + } +}; + +SwaggerClient.prototype.tagFromLabel = function(label) { + return label; +}; + +SwaggerClient.prototype.idFromOp = function(path, httpMethod, op) { + var opId = op.operationId || (path.substring(1) + '_' + httpMethod); + return opId.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()\+\s]/g,'_'); +}; + +SwaggerClient.prototype.fail = function(message) { + this.failure(message); + throw message; +}; + +var OperationGroup = function(tag, operation) { + this.tag = tag; + this.path = tag; + this.name = tag; + this.operation = operation; + this.operationsArray = []; + + this.description = operation.description || ""; +}; + +var Operation = function(parent, scheme, operationId, httpMethod, path, args, definitions) { + var errors = []; + parent = parent||{}; + args = args||{}; + + this.operations = {}; + this.operation = args; + this.deprecated = args.deprecated; + this.consumes = args.consumes; + this.produces = args.produces; + this.parent = parent; + this.host = parent.host || 'localhost'; + this.schemes = parent.schemes; + this.scheme = scheme || parent.scheme || 'http'; + this.basePath = parent.basePath || '/'; + this.nickname = (operationId||errors.push('Operations must have a nickname.')); + this.method = (httpMethod||errors.push('Operation ' + operationId + ' is missing method.')); + this.path = (path||errors.push('Operation ' + this.nickname + ' is missing path.')); + this.parameters = args !== null ? (args.parameters||[]) : {}; + this.summary = args.summary || ''; + this.responses = (args.responses||{}); + this.type = null; + this.security = args.security; + this.authorizations = args.security; + this.description = args.description; + this.useJQuery = parent.useJQuery; + + if(definitions) { + // add to global models + var key; + for(key in this.definitions) { + var model = new Model(key, definitions[key]); + if(model) { + models[key] = model; + } + } + } + + var i; + for(i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + if(param.type === 'array') { + param.isList = true; + param.allowMultiple = true; + } + var innerType = this.getType(param); + if(innerType && innerType.toString().toLowerCase() === 'boolean') { + param.allowableValues = {}; + param.isList = true; + param['enum'] = ["true", "false"]; + } + if(typeof param['enum'] !== 'undefined') { + var id; + param.allowableValues = {}; + param.allowableValues.values = []; + param.allowableValues.descriptiveValues = []; + for(id = 0; id < param['enum'].length; id++) { + var value = param['enum'][id]; + var isDefault = (value === param.default) ? true : false; + param.allowableValues.values.push(value); + param.allowableValues.descriptiveValues.push({value : value, isDefault: isDefault}); + } + } + if(param.type === 'array' && typeof param.allowableValues === 'undefined') { + // can't show as a list if no values to select from + delete param.isList; + delete param.allowMultiple; + } + param.signature = this.getModelSignature(innerType, models); + param.sampleJSON = this.getModelSampleJSON(innerType, models); + param.responseClassSignature = param.signature; + } + + var defaultResponseCode, response, model, responses = this.responses; + + if(responses['200']) { + response = responses['200']; + defaultResponseCode = '200'; + } + else if(responses['201']) { + response = responses['201']; + defaultResponseCode = '201'; + } + else if(responses['202']) { + response = responses['202']; + defaultResponseCode = '202'; + } + else if(responses['203']) { + response = responses['203']; + defaultResponseCode = '203'; + } + else if(responses['204']) { + response = responses['204']; + defaultResponseCode = '204'; + } + else if(responses['205']) { + response = responses['205']; + defaultResponseCode = '205'; + } + else if(responses['206']) { + response = responses['206']; + defaultResponseCode = '206'; + } + else if(responses['default']) { + response = responses['default']; + defaultResponseCode = 'default'; + } + + if(response && response.schema) { + var resolvedModel = this.resolveModel(response.schema, definitions); + delete responses[defaultResponseCode]; + if(resolvedModel) { + this.successResponse = {}; + this.successResponse[defaultResponseCode] = resolvedModel; + } + else { + this.successResponse = {}; + this.successResponse[defaultResponseCode] = response.schema.type; + } + this.type = response; + } + + if (errors.length > 0) { + if(this.resource && this.resource.api && this.resource.api.fail) + this.resource.api.fail(errors); + } + + return this; +}; + +OperationGroup.prototype.sort = function(sorter) { + +}; + +Operation.prototype.getType = function (param) { + var type = param.type; + var format = param.format; + var isArray = false; + var str; + if(type === 'integer' && format === 'int32') + str = 'integer'; + else if(type === 'integer' && format === 'int64') + str = 'long'; + else if(type === 'integer') + str = 'integer'; + else if(type === 'string' && format === 'date-time') + str = 'date-time'; + else if(type === 'string' && format === 'date') + str = 'date'; + else if(type === 'number' && format === 'float') + str = 'float'; + else if(type === 'number' && format === 'double') + str = 'double'; + else if(type === 'number') + str = 'double'; + else if(type === 'boolean') + str = 'boolean'; + else if(type === 'string') + str = 'string'; + else if(type === 'array') { + isArray = true; + if(param.items) + str = this.getType(param.items); + } + if(param.$ref) + str = param.$ref; + + var schema = param.schema; + if(schema) { + var ref = schema.$ref; + if(ref) { + ref = simpleRef(ref); + if(isArray) + return [ ref ]; + else + return ref; + } + else + return this.getType(schema); + } + if(isArray) + return [ str ]; + else + return str; +}; + +Operation.prototype.resolveModel = function (schema, definitions) { + if(typeof schema.$ref !== 'undefined') { + var ref = schema.$ref; + if(ref.indexOf('#/definitions/') === 0) + ref = ref.substring('#/definitions/'.length); + if(definitions[ref]) { + return new Model(ref, definitions[ref]); + } + } + if(schema.type === 'array') + return new ArrayModel(schema); + else + return null; +}; + +Operation.prototype.help = function(dontPrint) { + var out = this.nickname + ': ' + this.summary + '\n'; + for(var i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + var typeInfo = typeFromJsonSchema(param.type, param.format); + out += '\n * ' + param.name + ' (' + typeInfo + '): ' + param.description; + } + if(typeof dontPrint === 'undefined') + log(out); + return out; +}; + +Operation.prototype.getModelSignature = function(type, definitions) { + var isPrimitive, listType; + + if(type instanceof Array) { + listType = true; + type = type[0]; + } + + if(type === 'string') + isPrimitive = true; + else + isPrimitive = (listType && definitions[listType]) || (definitions[type]) ? false : true; + if (isPrimitive) { + return type; + } else { + if (listType) + return definitions[type].getMockSignature(); + else + return definitions[type].getMockSignature(); + } +}; + +Operation.prototype.supportHeaderParams = function () { + return true; +}; + +Operation.prototype.supportedSubmitMethods = function () { + return this.parent.supportedSubmitMethods; +}; + +Operation.prototype.getHeaderParams = function (args) { + var headers = this.setContentTypes(args, {}); + for(var i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + if(typeof args[param.name] !== 'undefined') { + if (param.in === 'header') { + var value = args[param.name]; + if(Array.isArray(value)) + value = this.encodePathCollection(param.collectionFormat, param.name, value); + else + value = this.encodePathParam(value); + headers[param.name] = value; + } + } + } + return headers; +}; + +Operation.prototype.urlify = function (args) { + var formParams = {}; + var requestUrl = this.path; + + // grab params from the args, build the querystring along the way + var querystring = ''; + for(var i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + if(typeof args[param.name] !== 'undefined') { + if(param.in === 'path') { + var reg = new RegExp('\{' + param.name + '\}', 'gi'); + var value = args[param.name]; + if(Array.isArray(value)) + value = this.encodePathCollection(param.collectionFormat, param.name, value); + else + value = this.encodePathParam(value); + requestUrl = requestUrl.replace(reg, value); + } + else if (param.in === 'query' && typeof args[param.name] !== 'undefined') { + if(querystring === '') + querystring += '?'; + else + querystring += '&'; + if(typeof param.collectionFormat !== 'undefined') { + var qp = args[param.name]; + if(Array.isArray(qp)) + querystring += this.encodeQueryCollection(param.collectionFormat, param.name, qp); + else + querystring += this.encodeQueryParam(param.name) + '=' + this.encodeQueryParam(args[param.name]); + } + else + querystring += this.encodeQueryParam(param.name) + '=' + this.encodeQueryParam(args[param.name]); + } + else if (param.in === 'formData') + formParams[param.name] = args[param.name]; + } + } + var url = this.scheme + '://' + this.host; + + if(this.basePath !== '/') + url += this.basePath; + + return url + requestUrl + querystring; +}; + +Operation.prototype.getMissingParams = function(args) { + var missingParams = []; + // check required params, track the ones that are missing + var i; + for(i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + if(param.required === true) { + if(typeof args[param.name] === 'undefined') + missingParams = param.name; + } + } + return missingParams; +}; + +Operation.prototype.getBody = function(headers, args) { + var formParams = {}; + var body; + + for(var i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + if(typeof args[param.name] !== 'undefined') { + if (param.in === 'body') { + body = args[param.name]; + } else if(param.in === 'formData') { + formParams[param.name] = args[param.name]; + } + } + } + + // handle form params + if(headers['Content-Type'] === 'application/x-www-form-urlencoded') { + var encoded = ""; + var key; + for(key in formParams) { + value = formParams[key]; + if(typeof value !== 'undefined'){ + if(encoded !== "") + encoded += "&"; + encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value); + } + } + body = encoded; + } + + return body; +}; + +/** + * gets sample response for a single operation + **/ +Operation.prototype.getModelSampleJSON = function(type, models) { + var isPrimitive, listType, sampleJson; + + listType = (type instanceof Array); + isPrimitive = models[type] ? false : true; + sampleJson = isPrimitive ? void 0 : models[type].createJSONSample(); + if (sampleJson) { + sampleJson = listType ? [sampleJson] : sampleJson; + if(typeof sampleJson == 'string') + return sampleJson; + else if(typeof sampleJson === 'object') { + var t = sampleJson; + if(sampleJson instanceof Array && sampleJson.length > 0) { + t = sampleJson[0]; + } + if(t.nodeName) { + var xmlString = new XMLSerializer().serializeToString(t); + return this.formatXml(xmlString); + } + else + return JSON.stringify(sampleJson, null, 2); + } + else + return sampleJson; + } +}; + +/** + * legacy binding + **/ +Operation.prototype["do"] = function(args, opts, callback, error, parent) { + return this.execute(args, opts, callback, error, parent); +}; + + +/** + * executes an operation + **/ +Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) { + var args = arg1 || {}; + var opts = {}, success, error; + if(typeof arg2 === 'object') { + opts = arg2; + success = arg3; + error = arg4; + } + + if(typeof arg2 === 'function') { + success = arg2; + error = arg3; + } + + success = (success||log); + error = (error||log); + + if(typeof opts.useJQuery === 'boolean') { + this.useJQuery = opts.useJQuery; + } + + var missingParams = this.getMissingParams(args); + if(missingParams.length > 0) { + var message = 'missing required params: ' + missingParams; + fail(message); + return; + } + var headers = this.getHeaderParams(args); + headers = this.setContentTypes(args, opts); + var body = this.getBody(headers, args); + var url = this.urlify(args); + + var obj = { + url: url, + method: this.method.toUpperCase(), + body: body, + useJQuery: this.useJQuery, + headers: headers, + on: { + response: function(response) { + return success(response, parent); + }, + error: function(response) { + return error(response, parent); + } + } + }; + var status = e.authorizations.apply(obj, this.operation.security); + if(opts.mock === true) + return obj; + else + new SwaggerHttp().execute(obj); +}; + +Operation.prototype.setContentTypes = function(args, opts) { + // default type + var accepts = 'application/json'; + var consumes = args.parameterContentType || 'application/json'; + + var allDefinedParams = this.parameters; + var definedFormParams = []; + var definedFileParams = []; + var body; + var headers = {}; + + // get params from the operation and set them in definedFileParams, definedFormParams, headers + var i; + for(i = 0; i < allDefinedParams.length; i++) { + var param = allDefinedParams[i]; + if(param.in === 'formData') { + if(param.type === 'file') + definedFileParams.push(param); + else + definedFormParams.push(param); + } + else if(param.in === 'header' && this.headers) { + var key = param.name; + var headerValue = this.headers[param.name]; + if(typeof this.headers[param.name] !== 'undefined') + headers[key] = headerValue; + } + else if(param.in === 'body' && typeof args[param.name] !== 'undefined') { + body = args[param.name]; + } + } + + // if there's a body, need to set the consumes header via requestContentType + if (body && (this.method === 'post' || this.method === 'put' || this.method === 'patch' || this.method === 'delete')) { + if (opts.requestContentType) + consumes = opts.requestContentType; + } else { + // if any form params, content type must be set + if(definedFormParams.length > 0) { + if(opts.requestContentType) // override if set + consumes = opts.requestContentType; + else if(definedFileParams.length > 0) // if a file, must be multipart/form-data + consumes = 'multipart/form-data'; + else // default to x-www-from-urlencoded + consumes = 'application/x-www-form-urlencoded'; + } + else if (this.type == 'DELETE') + body = '{}'; + else if (this.type != 'DELETE') + consumes = null; + } + + if (consumes && this.consumes) { + if (this.consumes.indexOf(consumes) === -1) { + log('server doesn\'t consume ' + consumes + ', try ' + JSON.stringify(this.consumes)); + } + } + + if (opts.responseContentType) { + accepts = opts.responseContentType; + } else { + accepts = 'application/json'; + } + if (accepts && this.produces) { + if (this.produces.indexOf(accepts) === -1) { + log('server can\'t produce ' + accepts); + } + } + + if ((consumes && body !== '') || (consumes === 'application/x-www-form-urlencoded')) + headers['Content-Type'] = consumes; + if (accepts) + headers.Accept = accepts; + return headers; +}; + +Operation.prototype.asCurl = function (args) { + var results = []; + var headers = this.getHeaderParams(args); + if (headers) { + var key; + for (key in headers) + results.push("--header \"" + key + ": " + headers[key] + "\""); + } + return "curl " + (results.join(" ")) + " " + this.urlify(args); +}; + +Operation.prototype.encodePathCollection = function(type, name, value) { + var encoded = ''; + var i; + var separator = ''; + if(type === 'ssv') + separator = '%20'; + else if(type === 'tsv') + separator = '\\t'; + else if(type === 'pipes') + separator = '|'; + else + separator = ','; + + for(i = 0; i < value.length; i++) { + if(i === 0) + encoded = this.encodeQueryParam(value[i]); + else + encoded += separator + this.encodeQueryParam(value[i]); + } + return encoded; +}; + +Operation.prototype.encodeQueryCollection = function(type, name, value) { + var encoded = ''; + var i; + if(type === 'default' || type === 'multi') { + for(i = 0; i < value.length; i++) { + if(i > 0) encoded += '&'; + encoded += this.encodeQueryParam(name) + '=' + this.encodeQueryParam(value[i]); + } + } + else { + var separator = ''; + if(type === 'csv') + separator = ','; + else if(type === 'ssv') + separator = '%20'; + else if(type === 'tsv') + separator = '\\t'; + else if(type === 'pipes') + separator = '|'; + else if(type === 'brackets') { + for(i = 0; i < value.length; i++) { + if(i !== 0) + encoded += '&'; + encoded += this.encodeQueryParam(name) + '[]=' + this.encodeQueryParam(value[i]); + } + } + if(separator !== '') { + for(i = 0; i < value.length; i++) { + if(i === 0) + encoded = this.encodeQueryParam(name) + '=' + this.encodeQueryParam(value[i]); + else + encoded += separator + this.encodeQueryParam(value[i]); + } + } + } + return encoded; +}; + +Operation.prototype.encodeQueryParam = function(arg) { + return encodeURIComponent(arg); +}; + +/** + * TODO revisit, might not want to leave '/' + **/ +Operation.prototype.encodePathParam = function(pathParam) { + var encParts, part, parts, i, len; + pathParam = pathParam.toString(); + if (pathParam.indexOf('/') === -1) { + return encodeURIComponent(pathParam); + } else { + parts = pathParam.split('/'); + encParts = []; + for (i = 0, len = parts.length; i < len; i++) { + encParts.push(encodeURIComponent(parts[i])); + } + return encParts.join('/'); + } +}; + +var Model = function(name, definition) { + this.name = name; + this.definition = definition || {}; + this.properties = []; + var requiredFields = definition.required || []; + if(definition.type === 'array') { + var out = new ArrayModel(definition); + return out; + } + var key; + var props = definition.properties; + if(props) { + for(key in props) { + var required = false; + var property = props[key]; + if(requiredFields.indexOf(key) >= 0) + required = true; + this.properties.push(new Property(key, property, required)); + } + } +}; + +Model.prototype.createJSONSample = function(modelsToIgnore) { + var result = {}; + modelsToIgnore = (modelsToIgnore||{}); + modelsToIgnore[this.name] = this; + var i; + for (i = 0; i < this.properties.length; i++) { + prop = this.properties[i]; + result[prop.name] = prop.getSampleValue(modelsToIgnore); + } + delete modelsToIgnore[this.name]; + return result; +}; + +Model.prototype.getSampleValue = function(modelsToIgnore) { + var i; + var obj = {}; + for(i = 0; i < this.properties.length; i++ ) { + var property = this.properties[i]; + obj[property.name] = property.sampleValue(false, modelsToIgnore); + } + return obj; +}; + +Model.prototype.getMockSignature = function(modelsToIgnore) { + var propertiesStr = []; + var i, prop; + for (i = 0; i < this.properties.length; i++) { + prop = this.properties[i]; + propertiesStr.push(prop.toString()); + } + + var strong = ''; + var stronger = ''; + var strongClose = ''; + var classOpen = strong + this.name + ' {' + strongClose; + var classClose = strong + '}' + strongClose; + var returnVal = classOpen + '
        ' + propertiesStr.join(',
        ') + '
        ' + classClose; + if (!modelsToIgnore) + modelsToIgnore = {}; + + modelsToIgnore[this.name] = this; + for (i = 0; i < this.properties.length; i++) { + prop = this.properties[i]; + var ref = prop.$ref; + var model = models[ref]; + if (model && typeof modelsToIgnore[model.name] === 'undefined') { + returnVal = returnVal + ('
        ' + model.getMockSignature(modelsToIgnore)); + } + } + return returnVal; +}; + +var Property = function(name, obj, required) { + this.schema = obj; + this.required = required; + if(obj.$ref) + this.$ref = simpleRef(obj.$ref); + else if (obj.type === 'array' && obj.items) { + if(obj.items.$ref) + this.$ref = simpleRef(obj.items.$ref); + else + obj = obj.items; + } + this.name = name; + this.description = obj.description; + this.obj = obj; + this.optional = true; + this.optional = !required; + this.default = obj.default || null; + this.example = obj.example || null; + this.collectionFormat = obj.collectionFormat || null; + this.maximum = obj.maximum || null; + this.exclusiveMaximum = obj.exclusiveMaximum || null; + this.minimum = obj.minimum || null; + this.exclusiveMinimum = obj.exclusiveMinimum || null; + this.maxLength = obj.maxLength || null; + this.minLength = obj.minLength || null; + this.pattern = obj.pattern || null; + this.maxItems = obj.maxItems || null; + this.minItems = obj.minItems || null; + this.uniqueItems = obj.uniqueItems || null; + this['enum'] = obj['enum'] || null; + this.multipleOf = obj.multipleOf || null; +}; + +Property.prototype.getSampleValue = function (modelsToIgnore) { + return this.sampleValue(false, modelsToIgnore); +}; + +Property.prototype.isArray = function () { + var schema = this.schema; + if(schema.type === 'array') + return true; + else + return false; +}; + +Property.prototype.sampleValue = function(isArray, ignoredModels) { + isArray = (isArray || this.isArray()); + ignoredModels = (ignoredModels || {}); + var type = getStringSignature(this.obj); + var output; + + if(this.$ref) { + var refModelName = simpleRef(this.$ref); + var refModel = models[refModelName]; + if(refModel && typeof ignoredModels[type] === 'undefined') { + ignoredModels[type] = this; + output = refModel.getSampleValue(ignoredModels); + } + else + type = refModel; + } + else if(this.example) + output = this.example; + else if(this.default) + output = this.default; + else if(type === 'date-time') + output = new Date().toISOString(); + else if(type === 'string') + output = 'string'; + else if(type === 'integer') + output = 0; + else if(type === 'long') + output = 0; + else if(type === 'float') + output = 0.0; + else if(type === 'double') + output = 0.0; + else if(type === 'boolean') + output = true; + else + output = {}; + ignoredModels[type] = output; + if(isArray) + return [output]; + else + return output; +}; + +getStringSignature = function(obj) { + var str = ''; + if(typeof obj.type === 'undefined') + str += obj; + else if(obj.type === 'array') { + str += 'Array['; + str += getStringSignature((obj.items || obj.$ref || {})); + str += ']'; + } + else if(obj.type === 'integer' && obj.format === 'int32') + str += 'integer'; + else if(obj.type === 'integer' && obj.format === 'int64') + str += 'long'; + else if(obj.type === 'integer' && typeof obj.format === 'undefined') + str += 'long'; + else if(obj.type === 'string' && obj.format === 'date-time') + str += 'date-time'; + else if(obj.type === 'string' && obj.format === 'date') + str += 'date'; + else if(obj.type === 'string' && typeof obj.format === 'undefined') + str += 'string'; + else if(obj.type === 'number' && obj.format === 'float') + str += 'float'; + else if(obj.type === 'number' && obj.format === 'double') + str += 'double'; + else if(obj.type === 'number' && typeof obj.format === 'undefined') + str += 'double'; + else if(obj.type === 'boolean') + str += 'boolean'; + else if(obj.$ref) + str += simpleRef(obj.$ref); + else + str += obj.type; + return str; +}; + +simpleRef = function(name) { + if(typeof name === 'undefined') + return null; + if(name.indexOf("#/definitions/") === 0) + return name.substring('#/definitions/'.length); + else + return name; +}; + +Property.prototype.toString = function() { + var str = getStringSignature(this.obj); + if(str !== '') { + str = '' + this.name + ' (' + str + ''; + if(!this.required) + str += ', optional'; + str += ')'; + } + else + str = this.name + ' (' + JSON.stringify(this.obj) + ')'; + + if(typeof this.description !== 'undefined') + str += ': ' + this.description; + + var options = ''; + var isArray = this.schema.type === 'array'; + var type = isArray ? this.schema.items.type : this.schema.type; + + if (this.default) + options += optionHtml('Default', this.default); + + switch (type) { + case 'string': + if (this.minLength) + options += optionHtml('Min. Length', this.minLength); + if (this.maxLength) + options += optionHtml('Max. Length', this.maxLength); + if (this.pattern) + options += optionHtml('Reg. Exp.', this.pattern); + break; + case 'integer': + case 'number': + if (this.minimum) + options += optionHtml('Min. Value', this.minimum); + if (this.exclusiveMinimum) + options += optionHtml('Exclusive Min.', "true"); + if (this.maximum) + options += optionHtml('Max. Value', this.maximum); + if (this.exclusiveMaximum) + options += optionHtml('Exclusive Max.', "true"); + if (this.multipleOf) + options += optionHtml('Multiple Of', this.multipleOf); + break; + } + + if (isArray) { + if (this.minItems) + options += optionHtml('Min. Items', this.minItems); + if (this.maxItems) + options += optionHtml('Max. Items', this.maxItems); + if (this.uniqueItems) + options += optionHtml('Unique Items', "true"); + if (this.collectionFormat) + options += optionHtml('Coll. Format', this.collectionFormat); + } + + if (this['enum']) { + var enumString; + + if (type === 'number' || type === 'integer') + enumString = this['enum'].join(', '); + else { + enumString = '"' + this['enum'].join('", "') + '"'; + } + + options += optionHtml('Enum', enumString); + } + + if (options.length > 0) + str = '' + str + '' + options + '
        ' + this.name + '
        '; + + return str; +}; + +optionHtml = function(label, value) { + return '' + label + ':' + value + ''; +} + +typeFromJsonSchema = function(type, format) { + var str; + if(type === 'integer' && format === 'int32') + str = 'integer'; + else if(type === 'integer' && format === 'int64') + str = 'long'; + else if(type === 'integer' && typeof format === 'undefined') + str = 'long'; + else if(type === 'string' && format === 'date-time') + str = 'date-time'; + else if(type === 'string' && format === 'date') + str = 'date'; + else if(type === 'number' && format === 'float') + str = 'float'; + else if(type === 'number' && format === 'double') + str = 'double'; + else if(type === 'number' && typeof format === 'undefined') + str = 'double'; + else if(type === 'boolean') + str = 'boolean'; + else if(type === 'string') + str = 'string'; + + return str; +}; + +var sampleModels = {}; +var cookies = {}; +var models = {}; + +SwaggerClient.prototype.buildFrom1_2Spec = function (response) { if (response.apiVersion != null) { this.apiVersion = response.apiVersion; } @@ -421,7 +1528,7 @@ SwaggerApi.prototype.buildFromSpec = function (response) { return this; }; -SwaggerApi.prototype.buildFrom1_1Spec = function (response) { +SwaggerClient.prototype.buildFrom1_1Spec = function (response) { log('This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info'); if (response.apiVersion != null) this.apiVersion = response.apiVersion; @@ -467,7 +1574,7 @@ SwaggerApi.prototype.buildFrom1_1Spec = function (response) { return this; }; -SwaggerApi.prototype.convertInfo = function (resp) { +SwaggerClient.prototype.convertInfo = function (resp) { if(typeof resp == 'object') { var info = {} @@ -484,7 +1591,7 @@ SwaggerApi.prototype.convertInfo = function (resp) { } }; -SwaggerApi.prototype.selfReflect = function () { +SwaggerClient.prototype.selfReflect = function () { var resource, resource_name, ref; if (this.apis === null) { return false; @@ -503,17 +1610,12 @@ SwaggerApi.prototype.selfReflect = function () { } }; -SwaggerApi.prototype.fail = function (message) { - this.failure(message); - throw message; -}; - -SwaggerApi.prototype.setConsolidatedModels = function () { - var model, modelName, resource, resource_name, _i, _len, _ref, _ref1, _results; +SwaggerClient.prototype.setConsolidatedModels = function () { + var model, modelName, resource, resource_name, i, apis, models, results; this.models = {}; - _ref = this.apis; - for (resource_name in _ref) { - resource = _ref[resource_name]; + apis = this.apis; + for (resource_name in apis) { + resource = apis[resource_name]; for (modelName in resource.models) { if (typeof this.models[modelName] === 'undefined') { this.models[modelName] = resource.models[modelName]; @@ -521,33 +1623,13 @@ SwaggerApi.prototype.setConsolidatedModels = function () { } } } - _ref1 = this.modelsArray; - _results = []; - for (_i = 0, _len = _ref1.length; _i < _len; _i++) { - model = _ref1[_i]; - _results.push(model.setReferencedModels(this.models)); + models = this.modelsArray; + results = []; + for (i = 0; i < models.length; i++) { + model = models[i]; + results.push(model.setReferencedModels(this.models)); } - return _results; -}; - -SwaggerApi.prototype.help = function () { - var operation, operation_name, parameter, resource, resource_name, _i, _len, _ref, _ref1, _ref2; - _ref = this.apis; - for (resource_name in _ref) { - resource = _ref[resource_name]; - log(resource_name); - _ref1 = resource.operations; - for (operation_name in _ref1) { - operation = _ref1[operation_name]; - log(' ' + operation.nickname); - _ref2 = operation.parameters; - for (_i = 0, _len = _ref2.length; _i < _len; _i++) { - parameter = _ref2[_i]; - log(' ' + parameter.name + (parameter.required ? ' (required)' : '') + ' - ' + parameter.description); - } - } - } - return this; + return results; }; var SwaggerResource = function (resourceObj, api) { @@ -1552,1173 +2634,6 @@ SwaggerRequest.prototype.setHeaders = function (params, opts, operation) { return headers; }; -var SwaggerClient = function(url, options) { - this.isBuilt = false; - this.url = null; - this.debug = false; - this.basePath = null; - this.authorizations = null; - this.authorizationScheme = null; - this.isValid = false; - this.info = null; - this.useJQuery = false; - this.models = {}; - - options = (options||{}); - - if(typeof url === 'string') - this.url = url; - else if(typeof url === 'object') { - options = url; - this.url = options.url; - } - - if (typeof options.success === 'function') - this.success = options.success; - - if (options.useJQuery) - this.useJQuery = options.useJQuery; - - this.supportedSubmitMethods = options.supportedSubmitMethods || []; - this.failure = options.failure || function() {}; - this.progress = options.progress || function() {}; - this.spec = options.spec; - - if (typeof options.success === 'function') - this.build(); -}; - -SwaggerClient.prototype.build = function() { - var self = this; - this.progress('fetching resource list: ' + this.url); - var obj = { - useJQuery: this.useJQuery, - url: this.url, - method: "get", - headers: { - accept: "application/json, */*" - }, - on: { - error: function(response) { - if (self.url.substring(0, 4) !== 'http') - return self.fail('Please specify the protocol for ' + self.url); - else if (response.status === 0) - return self.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.'); - else if (response.status === 404) - return self.fail('Can\'t read swagger JSON from ' + self.url); - else - return self.fail(response.status + ' : ' + response.statusText + ' ' + self.url); - }, - response: function(resp) { - var responseObj = resp.obj || JSON.parse(resp.data); - self.swaggerVersion = responseObj.swaggerVersion; - - if(responseObj.swagger && parseInt(responseObj.swagger) === 2) { - self.swaggerVersion = responseObj.swagger; - self.buildFromSpec(responseObj); - self.isValid = true; - } - else { - self.isValid = false; - self.failure(); - } - } - } - }; - if(this.spec) { - setTimeout(function() { self.buildFromSpec(self.spec); }, 10); - } - else { - var e = (typeof window !== 'undefined' ? window : exports); - var status = e.authorizations.apply(obj); - new SwaggerHttp().execute(obj); - } - - return this; -}; - -SwaggerClient.prototype.buildFromSpec = function(response) { - if(this.isBuilt) return this; - - this.info = response.info || {}; - this.title = response.title || ''; - this.host = response.host || ''; - this.schemes = response.schemes || []; - this.basePath = response.basePath || ''; - this.apis = {}; - this.apisArray = []; - this.consumes = response.consumes; - this.produces = response.produces; - this.securityDefinitions = response.securityDefinitions; - - // legacy support - this.authSchemes = response.securityDefinitions; - - var location; - - if(typeof this.url === 'string') { - location = this.parseUri(this.url); - } - - if(typeof this.schemes === 'undefined' || this.schemes.length === 0) { - this.scheme = location.scheme || 'http'; - } - else { - this.scheme = this.schemes[0]; - } - - if(typeof this.host === 'undefined' || this.host === '') { - this.host = location.host; - if (location.port) { - this.host = this.host + ':' + location.port; - } - } - - this.definitions = response.definitions; - var key; - for(key in this.definitions) { - var model = new Model(key, this.definitions[key]); - if(model) { - models[key] = model; - } - } - - // get paths, create functions for each operationId - var path; - var operations = []; - for(path in response.paths) { - if(typeof response.paths[path] === 'object') { - var httpMethod; - for(httpMethod in response.paths[path]) { - if(['delete', 'get', 'head', 'options', 'patch', 'post', 'put'].indexOf(httpMethod) === -1) { - continue; - } - var operation = response.paths[path][httpMethod]; - var tags = operation.tags; - if(typeof tags === 'undefined') { - operation.tags = [ 'default' ]; - tags = operation.tags; - } - var operationId = this.idFromOp(path, httpMethod, operation); - var operationObject = new Operation ( - this, - operationId, - httpMethod, - path, - operation, - this.definitions - ); - // bind this operation's execute command to the api - if(tags.length > 0) { - var i; - for(i = 0; i < tags.length; i++) { - var tag = this.tagFromLabel(tags[i]); - var operationGroup = this[tag]; - if(typeof operationGroup === 'undefined') { - this[tag] = []; - operationGroup = this[tag]; - operationGroup.operations = {}; - operationGroup.label = tag; - operationGroup.apis = []; - this[tag].help = this.help.bind(operationGroup); - this.apisArray.push(new OperationGroup(tag, operationObject)); - } - operationGroup[operationId] = operationObject.execute.bind(operationObject); - operationGroup[operationId].help = operationObject.help.bind(operationObject); - operationGroup.apis.push(operationObject); - operationGroup.operations[operationId] = operationObject; - - // legacy UI feature - var j; - var api; - for(j = 0; j < this.apisArray.length; j++) { - if(this.apisArray[j].tag === tag) { - api = this.apisArray[j]; - } - } - if(api) { - api.operationsArray.push(operationObject); - } - } - } - else { - log('no group to bind to'); - } - } - } - } - this.isBuilt = true; - if (this.success) - this.success(); - return this; -}; - -SwaggerClient.prototype.parseUri = function(uri) { - var urlParseRE = /^(((([^:\/#\?]+:)?(?:(\/\/)((?:(([^:@\/#\?]+)(?:\:([^:@\/#\?]+))?)@)?(([^:\/#\?\]\[]+|\[[^\/\]@#?]+\])(?:\:([0-9]+))?))?)?)?((\/?(?:[^\/\?#]+\/+)*)([^\?#]*)))?(\?[^#]+)?)(#.*)?/; - var parts = urlParseRE.exec(uri); - return { - scheme: parts[4].replace(':',''), - host: parts[11], - port: parts[12], - path: parts[15] - }; -}; - -SwaggerClient.prototype.help = function() { - var i; - log('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); - } -}; - -SwaggerClient.prototype.tagFromLabel = function(label) { - return label; -}; - -SwaggerClient.prototype.idFromOp = function(path, httpMethod, op) { - var opId = op.operationId || (path.substring(1) + '_' + httpMethod); - return opId.replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~()\+\s]/g,'_'); -}; - -SwaggerClient.prototype.fail = function(message) { - this.failure(message); - throw message; -}; - -var OperationGroup = function(tag, operation) { - this.tag = tag; - this.path = tag; - this.name = tag; - this.operation = operation; - this.operationsArray = []; - - this.description = operation.description || ""; -}; - -var Operation = function(parent, operationId, httpMethod, path, args, definitions) { - var errors = []; - parent = parent||{}; - args = args||{}; - - this.operations = {}; - this.operation = args; - this.deprecated = args.deprecated; - this.consumes = args.consumes; - this.produces = args.produces; - this.parent = parent; - this.host = parent.host || 'localhost'; - this.schemes = parent.schemes; - this.scheme = parent.scheme || 'http'; - this.basePath = parent.basePath || '/'; - this.nickname = (operationId||errors.push('Operations must have a nickname.')); - this.method = (httpMethod||errors.push('Operation ' + operationId + ' is missing method.')); - this.path = (path||errors.push('Operation ' + this.nickname + ' is missing path.')); - this.parameters = args !== null ? (args.parameters||[]) : {}; - this.summary = args.summary || ''; - this.responses = (args.responses||{}); - this.type = null; - this.security = args.security; - this.authorizations = args.security; - this.description = args.description; - this.useJQuery = parent.useJQuery; - - var i; - for(i = 0; i < this.parameters.length; i++) { - var param = this.parameters[i]; - if(param.type === 'array') { - param.isList = true; - param.allowMultiple = true; - } - var innerType = this.getType(param); - if(innerType && innerType.toString().toLowerCase() === 'boolean') { - param.allowableValues = {}; - param.isList = true; - param['enum'] = ["true", "false"]; - } - if(typeof param['enum'] !== 'undefined') { - var id; - param.allowableValues = {}; - param.allowableValues.values = []; - param.allowableValues.descriptiveValues = []; - for(id = 0; id < param['enum'].length; id++) { - var value = param['enum'][id]; - var isDefault = (value === param.default) ? true : false; - param.allowableValues.values.push(value); - param.allowableValues.descriptiveValues.push({value : value, isDefault: isDefault}); - } - } - if(param.type === 'array' && typeof param.allowableValues === 'undefined') { - // can't show as a list if no values to select from - delete param.isList; - delete param.allowMultiple; - } - param.signature = this.getSignature(innerType, models); - param.sampleJSON = this.getSampleJSON(innerType, models); - param.responseClassSignature = param.signature; - } - - var response; - var model; - var responses = this.responses; - - if(responses['200']) { - response = responses['200']; - defaultResponseCode = '200'; - } - else if(responses['201']) { - response = responses['201']; - defaultResponseCode = '201'; - } - else if(responses['202']) { - response = responses['202']; - defaultResponseCode = '202'; - } - else if(responses['203']) { - response = responses['203']; - defaultResponseCode = '203'; - } - else if(responses['204']) { - response = responses['204']; - defaultResponseCode = '204'; - } - else if(responses['205']) { - response = responses['205']; - defaultResponseCode = '205'; - } - else if(responses['206']) { - response = responses['206']; - defaultResponseCode = '206'; - } - else if(responses['default']) { - response = responses['default']; - defaultResponseCode = 'default'; - } - - if(response && response.schema) { - var resolvedModel = this.resolveModel(response.schema, definitions); - if(resolvedModel) { - this.type = resolvedModel.name; - this.responseSampleJSON = JSON.stringify(resolvedModel.getSampleValue(), null, 2); - this.responseClassSignature = resolvedModel.getMockSignature(); - delete responses[defaultResponseCode]; - } - else { - this.type = response.schema.type; - } - } - - if (errors.length > 0) { - if(this.resource && this.resource.api && this.resource.api.fail) - this.resource.api.fail(errors); - } - - return this; -}; - -OperationGroup.prototype.sort = function(sorter) { - -}; - -Operation.prototype.getType = function (param) { - var type = param.type; - var format = param.format; - var isArray = false; - var str; - if(type === 'integer' && format === 'int32') - str = 'integer'; - else if(type === 'integer' && format === 'int64') - str = 'long'; - else if(type === 'integer') - str = 'integer'; - else if(type === 'string' && format === 'date-time') - str = 'date-time'; - else if(type === 'string' && format === 'date') - str = 'date'; - else if(type === 'number' && format === 'float') - str = 'float'; - else if(type === 'number' && format === 'double') - str = 'double'; - else if(type === 'number') - str = 'double'; - else if(type === 'boolean') - str = 'boolean'; - else if(type === 'string') - str = 'string'; - else if(type === 'array') { - isArray = true; - if(param.items) - str = this.getType(param.items); - } - if(param.$ref) - str = param.$ref; - - var schema = param.schema; - if(schema) { - var ref = schema.$ref; - if(ref) { - ref = simpleRef(ref); - if(isArray) - return [ ref ]; - else - return ref; - } - else - return this.getType(schema); - } - if(isArray) - return [ str ]; - else - return str; -}; - -Operation.prototype.resolveModel = function (schema, definitions) { - if(typeof schema.$ref !== 'undefined') { - var ref = schema.$ref; - if(ref.indexOf('#/definitions/') === 0) - ref = ref.substring('#/definitions/'.length); - if(definitions[ref]) { - return new Model(ref, definitions[ref]); - } - } - if(schema.type === 'array') - return new ArrayModel(schema); - else - return null; -}; - -Operation.prototype.help = function(dontPrint) { - var out = this.nickname + ': ' + this.summary + '\n'; - for(var i = 0; i < this.parameters.length; i++) { - var param = this.parameters[i]; - var typeInfo = typeFromJsonSchema(param.type, param.format); - out += '\n * ' + param.name + ' (' + typeInfo + '): ' + param.description; - } - if(typeof dontPrint === 'undefined') - log(out); - return out; -}; - -Operation.prototype.getSignature = function(type, models) { - var isPrimitive, listType; - - if(type instanceof Array) { - listType = true; - type = type[0]; - } - - if(type === 'string') - isPrimitive = true; - else - isPrimitive = (listType && models[listType]) || (models[type]) ? false : true; - if (isPrimitive) { - return type; - } else { - if (listType) - return models[type].getMockSignature(); - else - return models[type].getMockSignature(); - } -}; - -Operation.prototype.supportHeaderParams = function () { - return true; -}; - -Operation.prototype.supportedSubmitMethods = function () { - return this.parent.supportedSubmitMethods; -}; - -Operation.prototype.getHeaderParams = function (args) { - var headers = this.setContentTypes(args, {}); - for(var i = 0; i < this.parameters.length; i++) { - var param = this.parameters[i]; - if(typeof args[param.name] !== 'undefined') { - if (param.in === 'header') { - var value = args[param.name]; - if(Array.isArray(value)) - value = this.encodePathCollection(param.collectionFormat, param.name, value); - else - value = this.encodePathParam(value); - headers[param.name] = value; - } - } - } - return headers; -}; - -Operation.prototype.urlify = function (args) { - var formParams = {}; - var requestUrl = this.path; - - // grab params from the args, build the querystring along the way - var querystring = ''; - for(var i = 0; i < this.parameters.length; i++) { - var param = this.parameters[i]; - if(typeof args[param.name] !== 'undefined') { - if(param.in === 'path') { - var reg = new RegExp('\{' + param.name + '\}', 'gi'); - var value = args[param.name]; - if(Array.isArray(value)) - value = this.encodePathCollection(param.collectionFormat, param.name, value); - else - value = this.encodePathParam(value); - requestUrl = requestUrl.replace(reg, value); - } - else if (param.in === 'query' && typeof args[param.name] !== 'undefined') { - if(querystring === '') - querystring += '?'; - else - querystring += '&'; - if(typeof param.collectionFormat !== 'undefined') { - var qp = args[param.name]; - if(Array.isArray(qp)) - querystring += this.encodeQueryCollection(param.collectionFormat, param.name, qp); - else - querystring += this.encodeQueryParam(param.name) + '=' + this.encodeQueryParam(args[param.name]); - } - else - querystring += this.encodeQueryParam(param.name) + '=' + this.encodeQueryParam(args[param.name]); - } - else if (param.in === 'formData') - formParams[param.name] = args[param.name]; - } - } - var url = this.scheme + '://' + this.host; - - if(this.basePath !== '/') - url += this.basePath; - - return url + requestUrl + querystring; -}; - -Operation.prototype.getMissingParams = function(args) { - var missingParams = []; - // check required params, track the ones that are missing - var i; - for(i = 0; i < this.parameters.length; i++) { - var param = this.parameters[i]; - if(param.required === true) { - if(typeof args[param.name] === 'undefined') - missingParams = param.name; - } - } - return missingParams; -}; - -Operation.prototype.getBody = function(headers, args) { - var formParams = {}; - var body; - - for(var i = 0; i < this.parameters.length; i++) { - var param = this.parameters[i]; - if(typeof args[param.name] !== 'undefined') { - if (param.in === 'body') { - body = args[param.name]; - } else if(param.in === 'formData') { - formParams[param.name] = args[param.name]; - } - } - } - - // handle form params - if(headers['Content-Type'] === 'application/x-www-form-urlencoded') { - var encoded = ""; - var key; - for(key in formParams) { - value = formParams[key]; - if(typeof value !== 'undefined'){ - if(encoded !== "") - encoded += "&"; - encoded += encodeURIComponent(key) + '=' + encodeURIComponent(value); - } - } - body = encoded; - } - - return body; -}; - -/** - * gets sample response for a single operation - **/ -Operation.prototype.getSampleJSON = function(type, models) { - var isPrimitive, listType, sampleJson; - - listType = (type instanceof Array); - isPrimitive = models[type] ? false : true; - sampleJson = isPrimitive ? void 0 : models[type].createJSONSample(); - if (sampleJson) { - sampleJson = listType ? [sampleJson] : sampleJson; - if(typeof sampleJson == 'string') - return sampleJson; - else if(typeof sampleJson === 'object') { - var t = sampleJson; - if(sampleJson instanceof Array && sampleJson.length > 0) { - t = sampleJson[0]; - } - if(t.nodeName) { - var xmlString = new XMLSerializer().serializeToString(t); - return this.formatXml(xmlString); - } - else - return JSON.stringify(sampleJson, null, 2); - } - else - return sampleJson; - } -}; - -/** - * legacy binding - **/ -Operation.prototype["do"] = function(args, opts, callback, error, parent) { - return this.execute(args, opts, callback, error, parent); -}; - - -/** - * executes an operation - **/ -Operation.prototype.execute = function(arg1, arg2, arg3, arg4, parent) { - var args = arg1 || {}; - var opts = {}, success, error; - if(typeof arg2 === 'object') { - opts = arg2; - success = arg3; - error = arg4; - } - - if(typeof arg2 === 'function') { - success = arg2; - error = arg3; - } - - success = (success||log); - error = (error||log); - - if(typeof opts.useJQuery === 'boolean') { - this.useJQuery = opts.useJQuery; - } - - var missingParams = this.getMissingParams(args); - if(missingParams.length > 0) { - var message = 'missing required params: ' + missingParams; - fail(message); - return; - } - var headers = this.getHeaderParams(args); - headers = this.setContentTypes(args, opts); - var body = this.getBody(headers, args); - var url = this.urlify(args); - - var obj = { - url: url, - method: this.method.toUpperCase(), - body: body, - useJQuery: this.useJQuery, - headers: headers, - on: { - response: function(response) { - return success(response, parent); - }, - error: function(response) { - return error(response, parent); - } - } - }; - var status = e.authorizations.apply(obj, this.operation.security); - if(opts.mock === true) - return obj; - else - new SwaggerHttp().execute(obj); -}; - -Operation.prototype.setContentTypes = function(args, opts) { - // default type - var accepts = 'application/json'; - var consumes = args.parameterContentType || 'application/json'; - - var allDefinedParams = this.parameters; - var definedFormParams = []; - var definedFileParams = []; - var body; - var headers = {}; - - // get params from the operation and set them in definedFileParams, definedFormParams, headers - var i; - for(i = 0; i < allDefinedParams.length; i++) { - var param = allDefinedParams[i]; - if(param.in === 'formData') { - if(param.type === 'file') - definedFileParams.push(param); - else - definedFormParams.push(param); - } - else if(param.in === 'header' && this.headers) { - var key = param.name; - var headerValue = this.headers[param.name]; - if(typeof this.headers[param.name] !== 'undefined') - headers[key] = headerValue; - } - else if(param.in === 'body' && typeof args[param.name] !== 'undefined') { - body = args[param.name]; - } - } - - // if there's a body, need to set the consumes header via requestContentType - if (body && (this.method === 'post' || this.method === 'put' || this.method === 'patch' || this.method === 'delete')) { - if (opts.requestContentType) - consumes = opts.requestContentType; - } else { - // if any form params, content type must be set - if(definedFormParams.length > 0) { - if(opts.requestContentType) // override if set - consumes = opts.requestContentType; - else if(definedFileParams.length > 0) // if a file, must be multipart/form-data - consumes = 'multipart/form-data'; - else // default to x-www-from-urlencoded - consumes = 'application/x-www-form-urlencoded'; - } - else if (this.type == 'DELETE') - body = '{}'; - else if (this.type != 'DELETE') - consumes = null; - } - - if (consumes && this.consumes) { - if (this.consumes.indexOf(consumes) === -1) { - log('server doesn\'t consume ' + consumes + ', try ' + JSON.stringify(this.consumes)); - } - } - - if (opts.responseContentType) { - accepts = opts.responseContentType; - } else { - accepts = 'application/json'; - } - if (accepts && this.produces) { - if (this.produces.indexOf(accepts) === -1) { - log('server can\'t produce ' + accepts); - } - } - - if ((consumes && body !== '') || (consumes === 'application/x-www-form-urlencoded')) - headers['Content-Type'] = consumes; - if (accepts) - headers.Accept = accepts; - return headers; -}; - -Operation.prototype.asCurl = function (args) { - var results = []; - var headers = this.getHeaderParams(args); - if (headers) { - var key; - for (key in headers) - results.push("--header \"" + key + ": " + headers[key] + "\""); - } - return "curl " + (results.join(" ")) + " " + this.urlify(args); -}; - -Operation.prototype.encodePathCollection = function(type, name, value) { - var encoded = ''; - var i; - var separator = ''; - if(type === 'ssv') - separator = '%20'; - else if(type === 'tsv') - separator = '\\t'; - else if(type === 'pipes') - separator = '|'; - else - separator = ','; - - for(i = 0; i < value.length; i++) { - if(i === 0) - encoded = this.encodeQueryParam(value[i]); - else - encoded += separator + this.encodeQueryParam(value[i]); - } - return encoded; -}; - -Operation.prototype.encodeQueryCollection = function(type, name, value) { - var encoded = ''; - var i; - if(type === 'default' || type === 'multi') { - for(i = 0; i < value.length; i++) { - if(i > 0) encoded += '&'; - encoded += this.encodeQueryParam(name) + '=' + this.encodeQueryParam(value[i]); - } - } - else { - var separator = ''; - if(type === 'csv') - separator = ','; - else if(type === 'ssv') - separator = '%20'; - else if(type === 'tsv') - separator = '\\t'; - else if(type === 'pipes') - separator = '|'; - else if(type === 'brackets') { - for(i = 0; i < value.length; i++) { - if(i !== 0) - encoded += '&'; - encoded += this.encodeQueryParam(name) + '[]=' + this.encodeQueryParam(value[i]); - } - } - if(separator !== '') { - for(i = 0; i < value.length; i++) { - if(i === 0) - encoded = this.encodeQueryParam(name) + '=' + this.encodeQueryParam(value[i]); - else - encoded += separator + this.encodeQueryParam(value[i]); - } - } - } - return encoded; -}; - -Operation.prototype.encodeQueryParam = function(arg) { - return encodeURIComponent(arg); -}; - -/** - * TODO revisit, might not want to leave '/' - **/ -Operation.prototype.encodePathParam = function(pathParam) { - var encParts, part, parts, i, len; - pathParam = pathParam.toString(); - if (pathParam.indexOf('/') === -1) { - return encodeURIComponent(pathParam); - } else { - parts = pathParam.split('/'); - encParts = []; - for (i = 0, len = parts.length; i < len; i++) { - encParts.push(encodeURIComponent(parts[i])); - } - return encParts.join('/'); - } -}; - -var Model = function(name, definition) { - this.name = name; - this.definition = definition || {}; - this.properties = []; - var requiredFields = definition.required || []; - if(definition.type === 'array') { - var out = new ArrayModel(definition); - return out; - } - var key; - var props = definition.properties; - if(props) { - for(key in props) { - var required = false; - var property = props[key]; - if(requiredFields.indexOf(key) >= 0) - required = true; - this.properties.push(new Property(key, property, required)); - } - } -}; - -Model.prototype.createJSONSample = function(modelsToIgnore) { - var result = {}; - modelsToIgnore = (modelsToIgnore||{}); - modelsToIgnore[this.name] = this; - var i; - for (i = 0; i < this.properties.length; i++) { - prop = this.properties[i]; - result[prop.name] = prop.getSampleValue(modelsToIgnore); - } - delete modelsToIgnore[this.name]; - return result; -}; - -Model.prototype.getSampleValue = function(modelsToIgnore) { - var i; - var obj = {}; - for(i = 0; i < this.properties.length; i++ ) { - var property = this.properties[i]; - obj[property.name] = property.sampleValue(false, modelsToIgnore); - } - return obj; -}; - -Model.prototype.getMockSignature = function(modelsToIgnore) { - var propertiesStr = []; - var i, prop; - for (i = 0; i < this.properties.length; i++) { - prop = this.properties[i]; - propertiesStr.push(prop.toString()); - } - - var strong = ''; - var stronger = ''; - var strongClose = ''; - var classOpen = strong + this.name + ' {' + strongClose; - var classClose = strong + '}' + strongClose; - var returnVal = classOpen + '
        ' + propertiesStr.join(',
        ') + '
        ' + classClose; - if (!modelsToIgnore) - modelsToIgnore = {}; - - modelsToIgnore[this.name] = this; - for (i = 0; i < this.properties.length; i++) { - prop = this.properties[i]; - var ref = prop.$ref; - var model = models[ref]; - if (model && typeof modelsToIgnore[model.name] === 'undefined') { - returnVal = returnVal + ('
        ' + model.getMockSignature(modelsToIgnore)); - } - } - return returnVal; -}; - -var Property = function(name, obj, required) { - this.schema = obj; - this.required = required; - if(obj.$ref) - this.$ref = simpleRef(obj.$ref); - else if (obj.type === 'array') { - if(obj.items.$ref) - this.$ref = simpleRef(obj.items.$ref); - else - obj = obj.items; - } - this.name = name; - this.description = obj.description; - this.obj = obj; - this.optional = true; - this.optional = !required; - this.default = obj.default || null; - this.example = obj.example || null; - this.collectionFormat = obj.collectionFormat || null; - this.maximum = obj.maximum || null; - this.exclusiveMaximum = obj.exclusiveMaximum || null; - this.minimum = obj.minimum || null; - this.exclusiveMinimum = obj.exclusiveMinimum || null; - this.maxLength = obj.maxLength || null; - this.minLength = obj.minLength || null; - this.pattern = obj.pattern || null; - this.maxItems = obj.maxItems || null; - this.minItems = obj.minItems || null; - this.uniqueItems = obj.uniqueItems || null; - this['enum'] = obj['enum'] || null; - this.multipleOf = obj.multipleOf || null; -}; - -Property.prototype.getSampleValue = function (modelsToIgnore) { - return this.sampleValue(false, modelsToIgnore); -}; - -Property.prototype.isArray = function () { - var schema = this.schema; - if(schema.type === 'array') - return true; - else - return false; -}; - -Property.prototype.sampleValue = function(isArray, ignoredModels) { - isArray = (isArray || this.isArray()); - ignoredModels = (ignoredModels || {}); - var type = getStringSignature(this.obj); - var output; - - if(this.$ref) { - var refModelName = simpleRef(this.$ref); - var refModel = models[refModelName]; - if(refModel && typeof ignoredModels[type] === 'undefined') { - ignoredModels[type] = this; - output = refModel.getSampleValue(ignoredModels); - } - else - type = refModel; - } - else if(this.example) - output = this.example; - else if(this.default) - output = this.default; - else if(type === 'date-time') - output = new Date().toISOString(); - else if(type === 'string') - output = 'string'; - else if(type === 'integer') - output = 0; - else if(type === 'long') - output = 0; - else if(type === 'float') - output = 0.0; - else if(type === 'double') - output = 0.0; - else if(type === 'boolean') - output = true; - else - output = {}; - ignoredModels[type] = output; - if(isArray) - return [output]; - else - return output; -}; - -getStringSignature = function(obj) { - var str = ''; - if(typeof obj.type === 'undefined') - str += obj; - else if(obj.type === 'array') { - str += 'Array['; - str += getStringSignature((obj.items || obj.$ref || {})); - str += ']'; - } - else if(obj.type === 'integer' && obj.format === 'int32') - str += 'integer'; - else if(obj.type === 'integer' && obj.format === 'int64') - str += 'long'; - else if(obj.type === 'integer' && typeof obj.format === 'undefined') - str += 'long'; - else if(obj.type === 'string' && obj.format === 'date-time') - str += 'date-time'; - else if(obj.type === 'string' && obj.format === 'date') - str += 'date'; - else if(obj.type === 'string' && typeof obj.format === 'undefined') - str += 'string'; - else if(obj.type === 'number' && obj.format === 'float') - str += 'float'; - else if(obj.type === 'number' && obj.format === 'double') - str += 'double'; - else if(obj.type === 'number' && typeof obj.format === 'undefined') - str += 'double'; - else if(obj.type === 'boolean') - str += 'boolean'; - else if(obj.$ref) - str += simpleRef(obj.$ref); - else - str += obj.type; - return str; -}; - -simpleRef = function(name) { - if(typeof name === 'undefined') - return null; - if(name.indexOf("#/definitions/") === 0) - return name.substring('#/definitions/'.length); - else - return name; -}; - -Property.prototype.toString = function() { - var str = getStringSignature(this.obj); - if(str !== '') { - str = '' + this.name + ' (' + str + ''; - if(!this.required) - str += ', optional'; - str += ')'; - } - else - str = this.name + ' (' + JSON.stringify(this.obj) + ')'; - - if(typeof this.description !== 'undefined') - str += ': ' + this.description; - - var options = ''; - var isArray = this.schema.type === 'array'; - var type = isArray ? this.schema.items.type : this.schema.type; - - if (this.default) - options += optionHtml('Default', this.default); - - switch (type) { - case 'string': - if (this.minLength) - options += optionHtml('Min. Length', this.minLength); - if (this.maxLength) - options += optionHtml('Max. Length', this.maxLength); - if (this.pattern) - options += optionHtml('Reg. Exp.', this.pattern); - break; - case 'integer': - case 'number': - if (this.minimum) - options += optionHtml('Min. Value', this.minimum); - if (this.exclusiveMinimum) - options += optionHtml('Exclusive Min.', "true"); - if (this.maximum) - options += optionHtml('Max. Value', this.maximum); - if (this.exclusiveMaximum) - options += optionHtml('Exclusive Max.', "true"); - if (this.multipleOf) - options += optionHtml('Multiple Of', this.multipleOf); - break; - } - - if (isArray) { - if (this.minItems) - options += optionHtml('Min. Items', this.minItems); - if (this.maxItems) - options += optionHtml('Max. Items', this.maxItems); - if (this.uniqueItems) - options += optionHtml('Unique Items', "true"); - if (this.collectionFormat) - options += optionHtml('Coll. Format', this.collectionFormat); - } - - if (this['enum']) { - var enumString; - - if (type === 'number' || type === 'integer') - enumString = this['enum'].join(', '); - else { - enumString = '"' + this['enum'].join('", "') + '"'; - } - - options += optionHtml('Enum', enumString); - } - - if (options.length > 0) - str = '' + str + '' + options + '
        ' + this.name + '
        '; - - return str; -}; - -optionHtml = function(label, value) { - return '' + label + ':' + value + ''; -} - -typeFromJsonSchema = function(type, format) { - var str; - if(type === 'integer' && format === 'int32') - str = 'integer'; - else if(type === 'integer' && format === 'int64') - str = 'long'; - else if(type === 'integer' && typeof format === 'undefined') - str = 'long'; - else if(type === 'string' && format === 'date-time') - str = 'date-time'; - else if(type === 'string' && format === 'date') - str = 'date'; - else if(type === 'number' && format === 'float') - str = 'float'; - else if(type === 'number' && format === 'double') - str = 'double'; - else if(type === 'number' && typeof format === 'undefined') - str = 'double'; - else if(type === 'boolean') - str = 'boolean'; - else if(type === 'string') - str = 'string'; - - return str; -}; - -var sampleModels = {}; -var cookies = {}; -var models = {}; - /** * SwaggerHttp is a wrapper for executing requests */ @@ -2970,5 +2885,5 @@ e.CookieAuthorization = CookieAuthorization; e.SwaggerClient = SwaggerClient; e.Operation = Operation; e.Model = Model; -e.SwaggerApi = SwaggerApi; +e.models = models; })(); \ No newline at end of file diff --git a/src/main/coffeescript/SwaggerUi.coffee b/src/main/coffeescript/SwaggerUi.coffee index bea2f3ba..e9d1e469 100644 --- a/src/main/coffeescript/SwaggerUi.coffee +++ b/src/main/coffeescript/SwaggerUi.coffee @@ -26,12 +26,7 @@ class SwaggerUi extends Backbone.Router @render() @options.progress = (d) => @showMessage(d) @options.failure = (d) => - if @api and @api.isValid is false - log "not a valid 2.0 spec, loading legacy client" - @api = new SwaggerApi(@options) - @api.build() - else - @onLoadFailure(d) + @onLoadFailure(d) # Create view to handle the header inputs @headerView = new HeaderView({el: $('#header')}) @@ -41,11 +36,11 @@ class SwaggerUi extends Backbone.Router # Set an option after initializing setOption: (option,value) -> - @options[option] = value + @options[option] = value # Get the value of a previously set option getOption: (option) -> - @options[option] + @options[option] # Event handler for when url/key is received from user updateSwaggerUi: (data) -> diff --git a/src/main/coffeescript/view/OperationView.coffee b/src/main/coffeescript/view/OperationView.coffee index 4093f54d..df069cfa 100644 --- a/src/main/coffeescript/view/OperationView.coffee +++ b/src/main/coffeescript/view/OperationView.coffee @@ -93,12 +93,26 @@ class OperationView extends Backbone.View $(@el).html(Handlebars.templates.operation(@model)) - if @model.responseClassSignature and @model.responseClassSignature != 'string' + # 2.0 + signatureModel = null + if @model.successResponse + successResponse = @model.successResponse + for key of successResponse + value = successResponse[key] + if typeof value is 'object' and typeof value.createJSONSample is 'function' + foo = 'bar' + signatureModel = + sampleJSON: JSON.stringify(value.createJSONSample(), undefined, 2) + isParam: false + signature: value.getMockSignature() + # 1.2 + else if @model.responseClassSignature and @model.responseClassSignature != 'string' signatureModel = sampleJSON: @model.responseSampleJSON isParam: false signature: @model.responseClassSignature + if signatureModel responseSignatureView = new SignatureView({model: signatureModel, tagName: 'div'}) $('.model-signature', $(@el)).append responseSignatureView.render().el else