diff --git a/dist/lib/swagger-client.js b/dist/lib/swagger-client.js new file mode 100644 index 00000000..0f87c1de --- /dev/null +++ b/dist/lib/swagger-client.js @@ -0,0 +1,1321 @@ +// swagger-client.js +// version 2.1.0 + +/** + * SwaggerAuthorizations applys the correct authorization to an operation being executed + */ +var SwaggerAuthorizations = function() { + this.authz = {}; +}; + +SwaggerAuthorizations.prototype.add = function(name, auth) { + this.authz[name] = auth; + return auth; +}; + +SwaggerAuthorizations.prototype.remove = function(name) { + return delete this.authz[name]; +}; + +SwaggerAuthorizations.prototype.apply = function(obj, authorizations) { + var status = null; + var key; + + // if the "authorizations" key is undefined, or has an empty array, add all keys + if(typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) { + for (key in this.authz) { + value = this.authz[key]; + result = value.apply(obj, authorizations); + if (result === true) + status = true; + } + } + else { + for(name in authorizations) { + for (key in this.authz) { + if(key == name) { + value = this.authz[key]; + result = value.apply(obj, authorizations); + if (result === true) + status = true; + } + } + } + } + + return status; +}; + +/** + * ApiKeyAuthorization allows a query param or header to be injected + */ +var ApiKeyAuthorization = function(name, value, type) { + this.name = name; + this.value = value; + this.type = type; +}; + +ApiKeyAuthorization.prototype.apply = function(obj, authorizations) { + if (this.type === "query") { + if (obj.url.indexOf('?') > 0) + obj.url = obj.url + "&" + this.name + "=" + this.value; + else + obj.url = obj.url + "?" + this.name + "=" + this.value; + return true; + } else if (this.type === "header") { + obj.headers[this.name] = this.value; + return true; + } +}; + +var CookieAuthorization = function(cookie) { + this.cookie = cookie; +} + +CookieAuthorization.prototype.apply = function(obj, authorizations) { + obj.cookieJar = obj.cookieJar || CookieJar(); + obj.cookieJar.setCookie(this.cookie); + return true; +} + +/** + * Password Authorization is a basic auth implementation + */ +var PasswordAuthorization = function(name, username, password) { + this.name = name; + this.username = username; + this.password = password; + this._btoa = null; + if (typeof window !== 'undefined') + this._btoa = btoa; + else + this._btoa = require("btoa"); +}; + +PasswordAuthorization.prototype.apply = function(obj, authorizations) { + var base64encoder = this._btoa; + obj.headers["Authorization"] = "Basic " + base64encoder(this.username + ":" + this.password); + return true; +};var __bind = function(fn, me){ + return function(){ + return fn.apply(me, arguments); + }; +}; + +fail = function(message) { + log(message); +} + +log = function(){ + log.history = log.history || []; + log.history.push(arguments); + if(this.console){ + console.log( Array.prototype.slice.call(arguments)[0] ); + } +}; + +if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function(obj, start) { + for (var i = (start || 0), j = this.length; i < j; i++) { + if (this[i] === obj) { return i; } + } + return -1; + } +} + +if (!('filter' in Array.prototype)) { + Array.prototype.filter= function(filter, that /*opt*/) { + var other= [], v; + for (var i=0, n= this.length; i 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.label = tag; + operationGroup.apis = []; + this[tag].help = this.help.bind(operationGroup); + this.apisArray.push(new OperationGroup(tag, operation)); + } + operationGroup[operationId] = operation.execute.bind(operation); + operationGroup[operationId].help = operation.help.bind(operation); + operationGroup.apis.push(operation); + + // legacy UI feature + var j; + var api = null; + for(j = 0; j < this.apisArray.length; j++) { + if(this.apisArray[j].tag === tag) { + api = this.apisArray[j]; + } + } + if(api) { + api.operationsArray.push(operation); + } + } + } + else { + log('no group to bind to'); + } + } + } + this.isBuilt = true; + if (this.success) + this.success(); + return this; +} + +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) { + if(typeof op.operationId !== 'undefined') { + return (op.operationId); + } + else { + return path.substring(1).replace(/\//g, "_").replace(/\{/g, "").replace(/\}/g, "") + "_" + httpMethod; + } +} + +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 = []; + this.operation = args; + this.consumes = args.consumes; + this.produces = args.produces; + this.parent = parent; + this.host = parent.host; + this.schemes = parent.schemes; + 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 ' + nickname + ' is missing path.')); + this.parameters = args != null ? (args.parameters||[]) : {}; + this.summary = args.summary || ''; + this.responses = (args.responses||{}); + this.type = null; + + // this.authorizations = authorizations; + + var i; + for(i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + type = this.getType(param); + + param.signature = this.getSignature(type, models); + param.sampleJSON = this.getSampleJSON(type, models); + param.responseClassSignature = param.signature; + } + + var response; + var model; + var responses = this.responses; + + if(responses['200']) + response = responses['200']; + else if(responses['default']) + response = responses['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(); + } + else { + this.type = response.schema.type; + } + } + // else + // this.responseClassSignature = ''; + + if (errors.length > 0) + 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 === '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 === '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; + // return new PrimitiveModel(schema); + // else + + // var ref = schema.items['$ref']; + // if(ref.indexOf('#/definitions/') === 0) + // ref = ref.substring('#/definitions/'.length); + // return new Model('name', models[ref]); + // } + // else + // return new Model('name', schema); +} + +Operation.prototype.help = function() { + log(this.nickname + ': ' + this.operation.summary); + for(var i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + log(' * ' + param.name + ': ' + param.description); + } +} + +Operation.prototype.getSignature = function(type, models) { + var isPrimitive, listType; + + if(type instanceof Array) { + listType = true; + type = type[0]; + } + + // listType = this.isListType(type); + if(type === 'string') + isPrimitive = true + else + isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true; + if (isPrimitive) { + return type; + } else { + if (listType != null) { + return models[type].getMockSignature(); + } else { + return models[type].getMockSignature(); + } + } +}; + +Operation.prototype.getSampleJSON = function(type, models) { + var isPrimitive, listType, sampleJson; + + listType = (type instanceof Array); + isPrimitive = (models[type] != null) ? 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 support +Operation.prototype["do"] = function(args, opts, callback, error, parent) { + return this.execute(args, opts, callback, error, parent); +} + +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; + } + + var formParams = {}; + var headers = {}; + var requestUrl = this.path; + + success = (success||log) + error = (error||log) + + var requiredParams = []; + var missingParams = []; + // check required params + for(var i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + if(param.required === true) { + requiredParams.push(param.name); + if(typeof args[param.name] === 'undefined') + missingParams = param.name; + } + } + + if(missingParams.length > 0) { + var message = 'missing required params: ' + missingParams; + fail(message); + return; + } + + // set content type negotiation + var consumes = this.consumes || this.parent.consumes || [ 'application/json' ]; + var produces = this.produces || this.parent.produces || [ 'application/json' ]; + + headers = this.setContentTypes(args, opts); + + // 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'); + requestUrl = requestUrl.replace(reg, this.encodePathParam(args[param.name])); + } + else if (param.in === 'query') { + if(querystring === '') + querystring += '?'; + if(typeof param.collectionFormat !== 'undefined') { + var qp = args[param.name]; + if(Array.isArray(qp)) + querystring += this.encodeCollection(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 === 'header') + headers[param.name] = args[param.name]; + else if (param.in === 'form') + formParams[param.name] = args[param.name]; + } + } + var scheme = this.schemes[0]; + var url = scheme + '://' + this.host + this.basePath + requestUrl + querystring; + + var obj = { + url: url, + method: args.method, + useJQuery: this.useJQuery, + headers: headers, + on: { + response: function(response) { + return success(response, parent); + }, + error: function(response) { + return error(response, parent); + } + } + }; + new SwaggerHttp().execute(obj); +} + +Operation.prototype.setContentTypes = function(args, opts) { + // default type + var accepts = 'application/json'; + var consumes = 'application/json'; + + var allDefinedParams = this.parameters; + var definedFormParams = []; + var definedFileParams = []; + var body = args.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 === 'form') + definedFormParams.push(param); + else if(param.in === 'file') + definedFileParams.push(param); + else if(param.in === 'header' && this.params.headers) { + var key = param.name; + var headerValue = this.params.headers[param.name]; + if(typeof this.params.headers[param.name] !== 'undefined') + headers[key] = headerValue; + } + } + + // if there's a body, need to set the accepts header via requestContentType + if (body && (this.type === 'post' || this.type === 'put' || this.type === 'patch' || this.type === 'delete')) { + if (opts.requestContentType) + consumes = opts.requestContentType; + } else { + // if any form params, content type must be set + if(definedFormParams.length > 0) { + if(definedFileParams.length > 0) + consumes = 'multipart/form-data'; + else + consumes = 'application/x-www-form-urlencoded'; + } + else if (this.type == 'DELETE') + body = '{}'; + else if (this.type != 'DELETE') + accepts = null; + } + + if (consumes && this.consumes) { + if (this.consumes.indexOf(consumes) === -1) { + log('server doesn\'t consume ' + consumes + ', try ' + JSON.stringify(this.consumes)); + consumes = this.operation.consumes[0]; + } + } + + 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); + accepts = this.produces[0]; + } + } + + if ((consumes && body !== '') || (consumes === 'application/x-www-form-urlencoded')) + headers['Content-Type'] = consumes; + if (accepts) + headers['Accept'] = accepts; + return headers; +} + +Operation.prototype.encodeCollection = function(type, name, value) { + var encoded = ''; + var i; + if(type === 'jaxrs') { + for(i = 0; i < value.length; i++) { + if(i > 0) encoded += '&' + encoded += this.encodeQueryParam(name) + '=' + this.encodeQueryParam(value[i]); + } + } + return encoded; +} + +Operation.prototype.encodeQueryParam = function(arg) { + return escape(arg); +} + +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++) { + part = parts[_i]; + encParts.push(encodeURIComponent(part)); + } + return encParts.join('/'); + } +}; + +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++) { + part = parts[_i]; + encParts.push(encodeURIComponent(part)); + } + return encParts.join('/'); + } +}; + +var ArrayModel = function(definition) { + this.name = "name"; + this.definition = definition || {}; + this.properties = []; + this.type; + this.ref; + + var requiredFields = definition.enum || []; + var items = definition.items; + if(items) { + var type = items.type; + if(items.type) { + this.type = typeFromJsonSchema(type.type, type.format); + } + else { + this.ref = items['$ref']; + } + } +} + +ArrayModel.prototype.createJSONSample = function(modelsToIgnore) { + var result; + var modelsToIgnore = (modelsToIgnore||[]) + if(this.type) { + result = type; + } + else if (this.ref) { + var name = simpleRef(this.ref); + result = models[name].createJSONSample(); + } + return [ result ]; +}; + +ArrayModel.prototype.getSampleValue = function() { + var result; + var modelsToIgnore = (modelsToIgnore||[]) + if(this.type) { + result = type; + } + else if (this.ref) { + var name = simpleRef(this.ref); + result = models[name].getSampleValue(); + } + return [ result ]; +} + +ArrayModel.prototype.getMockSignature = function(modelsToIgnore) { + var propertiesStr = []; + + if(this.ref) { + return models[simpleRef(this.ref)].getMockSignature(); + } +}; + + +var PrimitiveModel = function(definition) { + this.name = "name"; + this.definition = definition || {}; + this.properties = []; + this.type; + + var requiredFields = definition.enum || []; + this.type = typeFromJsonSchema(definition.type, definition.format); +} + +PrimitiveModel.prototype.createJSONSample = function(modelsToIgnore) { + var result = this.type; + return result; +}; + +PrimitiveModel.prototype.getSampleValue = function() { + var result = this.type; + return null; +} + +PrimitiveModel.prototype.getMockSignature = function(modelsToIgnore) { + var propertiesStr = []; + var i; + for (i = 0; i < this.properties.length; i++) { + var 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.push(this.name); + var i; + for (i = 0; i < this.properties.length; i++) { + var prop = this.properties[i]; + var ref = prop['$ref']; + var model = models[ref]; + if (model && modelsToIgnore.indexOf(ref) === -1) { + returnVal = returnVal + ('
' + model.getMockSignature(modelsToIgnore)); + } + } + return returnVal; +}; + +var Model = function(name, definition) { + this.name = name; + this.definition = definition || {}; + this.properties = []; + var requiredFields = definition.enum || []; + + 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 = {}; + var modelsToIgnore = (modelsToIgnore||[]) + modelsToIgnore.push(this.name); + for (var i = 0; i < this.properties.length; i++) { + prop = this.properties[i]; + result[prop.name] = prop.getSampleValue(modelsToIgnore); + } + modelsToIgnore.pop(this.name); + return result; +}; + +Model.prototype.getSampleValue = function() { + var i; + var obj = {}; + for(i = 0; i < this.properties.length; i++ ) { + var property = this.properties[i]; + obj[property.name] = property.sampleValue(); + } + return obj; +} + +Model.prototype.getMockSignature = function(modelsToIgnore) { + var propertiesStr = []; + var i; + for (i = 0; i < this.properties.length; i++) { + var 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.push(this.name); + var i; + for (i = 0; i < this.properties.length; i++) { + var prop = this.properties[i]; + var ref = prop['$ref']; + var model = models[ref]; + if (model && modelsToIgnore.indexOf(ref) === -1) { + returnVal = returnVal + ('
' + model.getMockSignature(modelsToIgnore)); + } + } + return returnVal; +}; + +var Property = function(name, obj, required) { + this.schema = obj; + this.required = required; + if(obj['$ref']) { + var refType = obj['$ref']; + refType = refType.indexOf('#/definitions') === -1 ? refType : refType.substring('#/definitions').length; + this['$ref'] = refType; + } + else if (obj.type === 'array') { + if(obj.items['$ref']) + this['$ref'] = obj.items['$ref']; + else + obj = obj.items; + } + this.name = name; + this.obj = obj; + this.optional = true; + this.example = obj.example || null; +} + +Property.prototype.getSampleValue = function () { + return this.sampleValue(false); +} + +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 refModel = models[this['$ref']]; + if(refModel && typeof ignoredModels[refModel] === 'undefined') { + output = refModel.getSampleValue(ignoredModels); + } + else + type = refModel; + } + else if(this.example) + output = this.example; + 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 = {}; + if(isArray) return [output]; + else return output; +} + +getStringSignature = function(obj) { + var str = ''; + if(obj.type === 'array') { + obj = (obj.items || obj['$ref'] || {}); + str += 'Array['; + } + if(obj.type === 'integer' && obj.format === 'int32') + str += 'integer'; + else if(obj.type === 'integer' && obj.format === 'int64') + 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 === 'number' && obj.format === 'float') + str += 'float'; + else if(obj.type === 'number' && obj.format === 'double') + str += 'double'; + else if(obj.type === 'boolean') + str += 'boolean'; + else + str += obj.type || obj['$ref']; + if(obj.type === 'array') + str += ']'; + return str; +} + +simpleRef = function(name) { + 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; + else + str = this.name + ' : ' + JSON.stringify(this.obj); + if(!this.required) + str += ' (optional)'; + return str; +} + +typeFromJsonSchema = function(type, format) { + var str; + if(type === 'integer' && format === 'int32') + str = 'integer'; + else if(type === 'integer' && format === 'int64') + 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 === 'boolean') + str = 'boolean'; + else if(type === 'string') + str = 'string'; + + return str; +} + +var e = (typeof window !== 'undefined' ? window : exports); + +var sampleModels = {}; +var cookies = {}; +var models = {}; + +e.authorizations = new SwaggerAuthorizations(); +e.ApiKeyAuthorization = ApiKeyAuthorization; +e.PasswordAuthorization = PasswordAuthorization; +e.CookieAuthorization = CookieAuthorization; +e.SwaggerClient = SwaggerClient;/** + * SwaggerHttp is a wrapper for executing requests + */ +var SwaggerHttp = function() {}; + +SwaggerHttp.prototype.execute = function(obj) { + if(obj && (typeof obj.useJQuery === 'boolean')) + this.useJQuery = obj.useJQuery; + else + this.useJQuery = this.isIE8(); + + if(this.useJQuery) + return new JQueryHttpClient().execute(obj); + else + return new ShredHttpClient().execute(obj); +} + +SwaggerHttp.prototype.isIE8 = function() { + var detectedIE = false; + if (typeof navigator !== 'undefined' && navigator.userAgent) { + nav = navigator.userAgent.toLowerCase(); + if (nav.indexOf('msie') !== -1) { + var version = parseInt(nav.split('msie')[1]); + if (version <= 8) { + detectedIE = true; + } + } + } + return detectedIE; +}; + +/* + * JQueryHttpClient lets a browser take advantage of JQuery's cross-browser magic. + * NOTE: when jQuery is available it will export both '$' and 'jQuery' to the global space. + * Since we are using closures here we need to alias it for internal use. + */ +var JQueryHttpClient = function(options) { + "use strict"; + if(!jQuery){ + var jQuery = window.jQuery; + } +} + +JQueryHttpClient.prototype.execute = function(obj) { + var cb = obj.on; + var request = obj; + + obj.type = obj.method; + obj.cache = false; + + obj.beforeSend = function(xhr) { + var key, results; + if (obj.headers) { + results = []; + var key; + for (key in obj.headers) { + if (key.toLowerCase() === "content-type") { + results.push(obj.contentType = obj.headers[key]); + } else if (key.toLowerCase() === "accept") { + results.push(obj.accepts = obj.headers[key]); + } else { + results.push(xhr.setRequestHeader(key, obj.headers[key])); + } + } + return results; + } + }; + + obj.data = obj.body; + obj.complete = function(response, textStatus, opts) { + var headers = {}, + headerArray = response.getAllResponseHeaders().split("\n"); + + for(var i = 0; i < headerArray.length; i++) { + var toSplit = headerArray[i].trim(); + if(toSplit.length === 0) + continue; + var separator = toSplit.indexOf(":"); + if(separator === -1) { + // Name but no value in the header + headers[toSplit] = null; + continue; + } + var name = toSplit.substring(0, separator).trim(), + value = toSplit.substring(separator + 1).trim(); + headers[name] = value; + } + + var out = { + url: request.url, + method: request.method, + status: response.status, + data: response.responseText, + headers: headers + }; + + var contentType = (headers["content-type"]||headers["Content-Type"]||null) + + if(contentType != null) { + if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) { + if(response.responseText && response.responseText !== "") + out.obj = JSON.parse(response.responseText); + else + out.obj = {} + } + } + + if(response.status >= 200 && response.status < 300) + cb.response(out); + else if(response.status === 0 || (response.status >= 400 && response.status < 599)) + cb.error(out); + else + return cb.response(out); + }; + + jQuery.support.cors = true; + return jQuery.ajax(obj); +} + +/* + * ShredHttpClient is a light-weight, node or browser HTTP client + */ +var ShredHttpClient = function(options) { + this.options = (options||{}); + this.isInitialized = false; + + var identity, toString; + + if (typeof window !== 'undefined') { + this.Shred = require("./shred"); + this.content = require("./shred/content"); + } + else + this.Shred = require("shred"); + this.shred = new this.Shred(); +} + +ShredHttpClient.prototype.initShred = function () { + this.isInitialized = true; + this.registerProcessors(this.shred); +} + +ShredHttpClient.prototype.registerProcessors = function(shred) { + var identity = function(x) { + return x; + }; + var toString = function(x) { + return x.toString(); + }; + + if (typeof window !== 'undefined') { + this.content.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], { + parser: identity, + stringify: toString + }); + } else { + this.Shred.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], { + parser: identity, + stringify: toString + }); + } +} + +ShredHttpClient.prototype.execute = function(obj) { + if(!this.isInitialized) + this.initShred(); + + var cb = obj.on, res; + + var transform = function(response) { + var out = { + headers: response._headers, + url: response.request.url, + method: response.request.method, + status: response.status, + data: response.content.data + }; + + var contentType = (response._headers["content-type"]||response._headers["Content-Type"]||null) + + if(contentType != null) { + if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) { + if(response.content.data && response.content.data !== "") + out.obj = JSON.parse(response.content.data); + else + out.obj = {} + } + } + return out; + }; + + res = { + error: function(response) { + if (obj) + return cb.error(transform(response)); + }, + redirect: function(response) { + if (obj) + return cb.redirect(transform(response)); + }, + 307: function(response) { + if (obj) + return cb.redirect(transform(response)); + }, + response: function(response) { + if (obj) + return cb.response(transform(response)); + } + }; + if (obj) { + obj.on = res; + } + return this.shred.request(obj); +}; \ No newline at end of file diff --git a/dist/swagger-ui.js b/dist/swagger-ui.js index 2dff7b7e..3ce99c4f 100644 --- a/dist/swagger-ui.js +++ b/dist/swagger-ui.js @@ -93,7 +93,6 @@ var Docs = { switch (fragments.length) { case 1: // Expand all operations for the resource and scroll to it - log('shebang resource:' + fragments[0]); var dom_id = 'resource_' + fragments[0]; Docs.expandEndpointListForResource(fragments[0]); @@ -101,7 +100,6 @@ var Docs = { break; case 2: // Refer to the endpoint DOM element, e.g. #words_get_search - log('shebang endpoint: ' + fragments.join('_')); // Expand Resource Docs.expandEndpointListForResource(fragments[0]); @@ -111,8 +109,6 @@ var Docs = { var li_dom_id = fragments.join('_'); var li_content_dom_id = li_dom_id + "_content"; - log("li_dom_id " + li_dom_id); - log("li_content_dom_id " + li_content_dom_id); Docs.expandOperation($('#'+li_content_dom_id)); $('#'+li_dom_id).slideto({highlight: false}); @@ -1085,7 +1081,7 @@ function program1(depth0,data) { if (stack1 = helpers.id) { stack1 = stack1.call(depth0, {hash:{},data:data}); } else { stack1 = depth0.id; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } buffer += escapeExpression(stack1) - + "');\">"; + + "');\">/"; if (stack1 = helpers.name) { stack1 = stack1.call(depth0, {hash:{},data:data}); } else { stack1 = depth0.name; stack1 = typeof stack1 === functionType ? stack1.apply(depth0) : stack1; } buffer += escapeExpression(stack1) @@ -1288,9 +1284,15 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; } this.options.url = url; this.headerView.update(url); - this.api = new SwaggerApi(this.options); - this.api.build(); - return this.api; + if (url.indexOf('swagger.json') > 0) { + this.api = new SwaggerClient(this.options); + this.api.build(); + return this.api; + } else { + this.api = new SwaggerApi(this.options); + this.api.build(); + return this.api; + } }; SwaggerUi.prototype.render = function() { @@ -1458,13 +1460,15 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; if (opts.swaggerOptions.sorter) { sorterName = opts.swaggerOptions.sorter; sorter = sorters[sorterName]; - _ref3 = this.model.apisArray; - for (_i = 0, _len = _ref3.length; _i < _len; _i++) { - route = _ref3[_i]; - route.operationsArray.sort(sorter); - } - if (sorterName === "alpha") { - return this.model.apisArray.sort(sorter); + if (this.model.apisArray) { + _ref3 = this.model.apisArray; + for (_i = 0, _len = _ref3.length; _i < _len; _i++) { + route = _ref3[_i]; + route.operationsArray.sort(sorter); + } + if (sorterName === "alpha") { + return this.model.apisArray.sort(sorter); + } } } }; @@ -1517,7 +1521,11 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; return _ref3; } - ResourceView.prototype.initialize = function() {}; + ResourceView.prototype.initialize = function() { + if ("" === this.model.description) { + return this.model.description = null; + } + }; ResourceView.prototype.render = function() { var counter, id, methods, operation, _i, _len, _ref4; @@ -1613,7 +1621,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; }; OperationView.prototype.render = function() { - var contentTypeModel, isMethodSubmissionSupported, k, o, param, responseContentTypeView, responseSignatureView, signatureModel, statusCode, type, v, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref5, _ref6, _ref7, _ref8; + var contentTypeModel, isMethodSubmissionSupported, k, o, param, ref, responseContentTypeView, responseSignatureView, schema, signatureModel, statusCode, type, v, _i, _j, _k, _l, _len, _len1, _len2, _len3, _ref5, _ref6, _ref7, _ref8; isMethodSubmissionSupported = true; if (!isMethodSubmissionSupported) { this.model.isReadOnly = true; @@ -1650,6 +1658,7 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; }); $('.model-signature', $(this.el)).append(responseSignatureView.render().el); } else { + this.model.responseClassSignature = 'string'; $('.model-signature', $(this.el)).html(this.model.type); } contentTypeModel = { @@ -1661,12 +1670,23 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; for (_j = 0, _len1 = _ref6.length; _j < _len1; _j++) { param = _ref6[_j]; type = param.type || param.dataType; - if (type.toLowerCase() === 'file') { + if (typeof type === 'undefined') { + schema = param.schema; + if (schema['$ref']) { + ref = schema['$ref']; + if (ref.indexOf('#/definitions/') === 0) { + type = ref.substring('#/definitions/'.length); + } else { + type = ref; + } + } + } + if (type && type.toLowerCase() === 'file') { if (!contentTypeModel.consumes) { - log("set content type "); contentTypeModel.consumes = 'multipart/form-data'; } } + param.type = type; } responseContentTypeView = new ResponseContentTypeView({ model: contentTypeModel @@ -1677,6 +1697,9 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; param = _ref7[_k]; this.addParameter(param, contentTypeModel.consumes); } + if (typeof this.model.responseMessages === 'undefined') { + this.model.responseMessages = []; + } _ref8 = this.model.responseMessages; for (_l = 0, _len3 = _ref8.length; _l < _len3; _l++) { statusCode = _ref8[_l]; @@ -1800,7 +1823,6 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; headerParams[param.name] = map[param.name]; } } - log(headerParams); _ref8 = form.find('input[type~="file"]'); for (_l = 0, _len3 = _ref8.length; _l < _len3; _l++) { el = _ref8[_l]; @@ -2096,12 +2118,25 @@ helpers = this.merge(helpers, Handlebars.helpers); data = data || {}; }; ParameterView.prototype.render = function() { - var contentTypeModel, isParam, parameterContentTypeView, responseContentTypeView, signatureModel, signatureView, template, type; + var contentTypeModel, isParam, parameterContentTypeView, ref, responseContentTypeView, schema, signatureModel, signatureView, template, type; type = this.model.type || this.model.dataType; + if (typeof type === 'undefined') { + schema = this.model.schema; + if (schema['$ref']) { + ref = schema['$ref']; + if (ref.indexOf('#/definitions/') === 0) { + type = ref.substring('#/definitions/'.length); + } else { + type = ref; + } + } + } + this.model.type = type; + this.model.paramType = this.model["in"] || this.model.paramType; if (this.model.paramType === 'body') { this.model.isBody = true; } - if (type.toLowerCase() === 'file') { + if (type && type.toLowerCase() === 'file') { this.model.isFile = true; } template = this.template(); diff --git a/dist/swagger-ui.min.js b/dist/swagger-ui.min.js index 03734602..fcae2e09 100644 --- a/dist/swagger-ui.min.js +++ b/dist/swagger-ui.min.js @@ -1 +1 @@ -$(function(){$.fn.vAlign=function(){return this.each(function(c){var a=$(this).height();var d=$(this).parent().height();var b=(d-a)/2;$(this).css("margin-top",b)})};$.fn.stretchFormtasticInputWidthToParent=function(){return this.each(function(b){var d=$(this).closest("form").innerWidth();var c=parseInt($(this).closest("form").css("padding-left"),10)+parseInt($(this).closest("form").css("padding-right"),10);var a=parseInt($(this).css("padding-left"),10)+parseInt($(this).css("padding-right"),10);$(this).css("width",d-c-a)})};$("form.formtastic li.string input, form.formtastic textarea").stretchFormtasticInputWidthToParent();$("ul.downplayed li div.content p").vAlign();$("form.sandbox").submit(function(){var a=true;$(this).find("input.required").each(function(){$(this).removeClass("error");if($(this).val()==""){$(this).addClass("error");$(this).wiggle();a=false}});return a})});function clippyCopiedCallback(b){$("#api_key_copied").fadeIn().delay(1000).fadeOut()}log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){console.log(Array.prototype.slice.call(arguments)[0])}};if(Function.prototype.bind&&console&&typeof console.log=="object"){["log","info","warn","error","assert","dir","clear","profile","profileEnd"].forEach(function(a){console[a]=this.bind(console[a],console)},Function.prototype.call)}var Docs={shebang:function(){var b=$.param.fragment().split("/");b.shift();switch(b.length){case 1:log("shebang resource:"+b[0]);var d="resource_"+b[0];Docs.expandEndpointListForResource(b[0]);$("#"+d).slideto({highlight:false});break;case 2:log("shebang endpoint: "+b.join("_"));Docs.expandEndpointListForResource(b[0]);$("#"+d).slideto({highlight:false});var c=b.join("_");var a=c+"_content";log("li_dom_id "+c);log("li_content_dom_id "+a);Docs.expandOperation($("#"+a));$("#"+c).slideto({highlight:false});break}},toggleEndpointListForResource:function(b){var a=$("li#resource_"+Docs.escapeResourceName(b)+" ul.endpoints");if(a.is(":visible")){Docs.collapseEndpointListForResource(b)}else{Docs.expandEndpointListForResource(b)}},expandEndpointListForResource:function(b){var b=Docs.escapeResourceName(b);if(b==""){$(".resource ul.endpoints").slideDown();return}$("li#resource_"+b).addClass("active");var a=$("li#resource_"+b+" ul.endpoints");a.slideDown()},collapseEndpointListForResource:function(b){var b=Docs.escapeResourceName(b);$("li#resource_"+b).removeClass("active");var a=$("li#resource_"+b+" ul.endpoints");a.slideUp()},expandOperationsForResource:function(a){Docs.expandEndpointListForResource(a);if(a==""){$(".resource ul.endpoints li.operation div.content").slideDown();return}$("li#resource_"+Docs.escapeResourceName(a)+" li.operation div.content").each(function(){Docs.expandOperation($(this))})},collapseOperationsForResource:function(a){Docs.expandEndpointListForResource(a);$("li#resource_"+Docs.escapeResourceName(a)+" li.operation div.content").each(function(){Docs.collapseOperation($(this))})},escapeResourceName:function(a){return a.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g,"\\$&")},expandOperation:function(a){a.slideDown()},collapseOperation:function(a){a.slideUp()}};(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.content_type=b(function(g,l,f,k,j){this.compilerInfo=[4,">= 1.0.0"];f=this.merge(f,g.helpers);j=j||{};var i="",c,h="function",m=this;function e(r,q){var o="",p;o+="\n ";p=f.each.call(r,r.produces,{hash:{},inverse:m.noop,fn:m.program(2,d,q),data:q});if(p||p===0){o+=p}o+="\n";return o}function d(r,q){var o="",p;o+='\n \n ";return o}function n(p,o){return'\n \n'}i+='\n\n";return i})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.main=b(function(g,m,f,l,k){this.compilerInfo=[4,">= 1.0.0"];f=this.merge(f,g.helpers);k=k||{};var i="",c,h="function",j=this.escapeExpression,p=this;function e(v,u){var r="",t,s;r+='\n
'+j(((t=((t=v.info),t==null||t===false?t:t.title)),typeof t===h?t.apply(v):t))+'
\n
';s=((t=((t=v.info),t==null||t===false?t:t.description)),typeof t===h?t.apply(v):t);if(s||s===0){r+=s}r+="
\n ";s=f["if"].call(v,((t=v.info),t==null||t===false?t:t.termsOfServiceUrl),{hash:{},inverse:p.noop,fn:p.program(2,d,u),data:u});if(s||s===0){r+=s}r+="\n ";s=f["if"].call(v,((t=v.info),t==null||t===false?t:t.contact),{hash:{},inverse:p.noop,fn:p.program(4,q,u),data:u});if(s||s===0){r+=s}r+="\n ";s=f["if"].call(v,((t=v.info),t==null||t===false?t:t.license),{hash:{},inverse:p.noop,fn:p.program(6,o,u),data:u});if(s||s===0){r+=s}r+="\n ";return r}function d(u,t){var r="",s;r+='';return r}function q(u,t){var r="",s;r+="';return r}function o(u,t){var r="",s;r+="";return r}function n(u,t){var r="",s;r+='\n , api version: ';if(s=f.apiVersion){s=s.call(u,{hash:{},data:t})}else{s=u.apiVersion;s=typeof s===h?s.apply(u):s}r+=j(s)+"\n ";return r}i+="
\n ";c=f["if"].call(m,m.info,{hash:{},inverse:p.noop,fn:p.program(1,e,k),data:k});if(c||c===0){i+=c}i+="\n
\n
\n
    \n
\n\n
\n
\n
\n

[ base url: ";if(c=f.basePath){c=c.call(m,{hash:{},data:k})}else{c=m.basePath;c=typeof c===h?c.apply(m):c}i+=j(c)+"\n ";c=f["if"].call(m,m.apiVersion,{hash:{},inverse:p.noop,fn:p.program(8,n,k),data:k});if(c||c===0){i+=c}i+="]

\n
\n
\n";return i})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.operation=b(function(g,s,q,m,y){this.compilerInfo=[4,">= 1.0.0"];q=this.merge(q,g.helpers);y=y||{};var r="",i,f,e="function",d=this.escapeExpression,p=this,c=q.blockHelperMissing;function o(C,B){var z="",A;z+="\n

Implementation Notes

\n

";if(A=q.notes){A=A.call(C,{hash:{},data:B})}else{A=C.notes;A=typeof A===e?A.apply(C):A}if(A||A===0){z+=A}z+="

\n ";return z}function n(A,z){return'\n
\n '}function l(C,B){var z="",A;z+='\n \n ";return z}function k(D,C){var z="",B,A;z+="\n
"+d(((B=D.scope),typeof B===e?B.apply(D):B))+"
\n ";return z}function h(A,z){return"
"}function x(A,z){return'\n
\n \n
\n '}function w(A,z){return'\n

Response Class

\n

\n
\n
\n '}function v(A,z){return'\n

Parameters

\n \n \n \n \n \n \n \n \n \n \n \n\n \n
ParameterValueDescriptionParameter TypeData Type
\n '}function u(A,z){return"\n
\n

Response Messages

\n \n \n \n \n \n \n \n \n \n \n \n
HTTP Status CodeReasonResponse Model
\n "}function t(A,z){return"\n "}function j(A,z){return"\n
\n \n \n \n
\n "}r+="\n
    \n
  • \n \n \n
  • \n
\n";return r})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.param=b(function(f,q,o,j,t){this.compilerInfo=[4,">= 1.0.0"];o=this.merge(o,f.helpers);t=t||{};var p="",g,d="function",c=this.escapeExpression,n=this;function m(y,x){var v="",w;v+="\n ";w=o["if"].call(y,y.isFile,{hash:{},inverse:n.program(4,k,x),fn:n.program(2,l,x),data:x});if(w||w===0){v+=w}v+="\n ";return v}function l(y,x){var v="",w;v+='\n \n
\n ';return v}function k(y,x){var v="",w;v+="\n ";w=o["if"].call(y,y.defaultValue,{hash:{},inverse:n.program(7,h,x),fn:n.program(5,i,x),data:x});if(w||w===0){v+=w}v+="\n ";return v}function i(y,x){var v="",w;v+="\n \n ";return v}function h(y,x){var v="",w;v+="\n \n
\n
\n ';return v}function e(y,x){var v="",w;v+="\n ";w=o["if"].call(y,y.isFile,{hash:{},inverse:n.program(10,u,x),fn:n.program(2,l,x),data:x});if(w||w===0){v+=w}v+="\n ";return v}function u(y,x){var v="",w;v+="\n ";w=o["if"].call(y,y.defaultValue,{hash:{},inverse:n.program(13,r,x),fn:n.program(11,s,x),data:x});if(w||w===0){v+=w}v+="\n ";return v}function s(y,x){var v="",w;v+="\n \n ";return v}function r(y,x){var v="",w;v+="\n \n ";return v}p+="";if(g=o.name){g=g.call(q,{hash:{},data:t})}else{g=q.name;g=typeof g===d?g.apply(q):g}p+=c(g)+"\n\n\n ";g=o["if"].call(q,q.isBody,{hash:{},inverse:n.program(9,e,t),fn:n.program(1,m,t),data:t});if(g||g===0){p+=g}p+="\n\n\n";if(g=o.description){g=g.call(q,{hash:{},data:t})}else{g=q.description;g=typeof g===d?g.apply(q):g}if(g||g===0){p+=g}p+="\n";if(g=o.paramType){g=g.call(q,{hash:{},data:t})}else{g=q.paramType;g=typeof g===d?g.apply(q):g}if(g||g===0){p+=g}p+='\n\n \n\n';return p})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.param_list=b(function(h,t,r,m,y){this.compilerInfo=[4,">= 1.0.0"];r=this.merge(r,h.helpers);y=y||{};var s="",j,g,e,p=this,q=r.helperMissing,d="function",c=this.escapeExpression;function o(A,z){return" multiple='multiple'"}function n(A,z){return"\n "}function l(C,B){var z="",A;z+="\n ";A=r["if"].call(C,C.defaultValue,{hash:{},inverse:p.program(8,i,B),fn:p.program(6,k,B),data:B});if(A||A===0){z+=A}z+="\n ";return z}function k(A,z){return"\n "}function i(E,D){var z="",C,B,A;z+="\n ";A={hash:{},inverse:p.program(11,x,D),fn:p.program(9,f,D),data:D};B=((C=r.isArray||E.isArray),C?C.call(E,E,A):q.call(E,"isArray",E,A));if(B||B===0){z+=B}z+="\n ";return z}function f(A,z){return"\n "}function x(A,z){return"\n \n "}function w(C,B){var z="",A;z+="\n ";A=r["if"].call(C,C.isDefault,{hash:{},inverse:p.program(16,u,B),fn:p.program(14,v,B),data:B});if(A||A===0){z+=A}z+="\n ";return z}function v(C,B){var z="",A;z+='\n \n ";return z}function u(C,B){var z="",A;z+="\n \n ";return z}s+="";if(j=r.name){j=j.call(t,{hash:{},data:y})}else{j=t.name;j=typeof j===d?j.apply(t):j}s+=c(j)+"\n\n \n\n";if(g=r.description){g=g.call(t,{hash:{},data:y})}else{g=t.description;g=typeof g===d?g.apply(t):g}if(g||g===0){s+=g}s+="\n";if(g=r.paramType){g=g.call(t,{hash:{},data:y})}else{g=t.paramType;g=typeof g===d?g.apply(t):g}if(g||g===0){s+=g}s+='\n';return s})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.param_readonly=b(function(g,m,f,l,k){this.compilerInfo=[4,">= 1.0.0"];f=this.merge(f,g.helpers);k=k||{};var i="",d,h="function",j=this.escapeExpression,o=this;function e(t,s){var q="",r;q+="\n \n ";return q}function c(t,s){var q="",r;q+="\n ";r=f["if"].call(t,t.defaultValue,{hash:{},inverse:o.program(6,n,s),fn:o.program(4,p,s),data:s});if(r||r===0){q+=r}q+="\n ";return q}function p(t,s){var q="",r;q+="\n ";if(r=f.defaultValue){r=r.call(t,{hash:{},data:s})}else{r=t.defaultValue;r=typeof r===h?r.apply(t):r}q+=j(r)+"\n ";return q}function n(r,q){return"\n (empty)\n "}i+="";if(d=f.name){d=d.call(m,{hash:{},data:k})}else{d=m.name;d=typeof d===h?d.apply(m):d}i+=j(d)+"\n\n ";d=f["if"].call(m,m.isBody,{hash:{},inverse:o.program(3,c,k),fn:o.program(1,e,k),data:k});if(d||d===0){i+=d}i+="\n\n";if(d=f.description){d=d.call(m,{hash:{},data:k})}else{d=m.description;d=typeof d===h?d.apply(m):d}if(d||d===0){i+=d}i+="\n";if(d=f.paramType){d=d.call(m,{hash:{},data:k})}else{d=m.paramType;d=typeof d===h?d.apply(m):d}if(d||d===0){i+=d}i+='\n\n';return i})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.param_readonly_required=b(function(g,m,f,l,k){this.compilerInfo=[4,">= 1.0.0"];f=this.merge(f,g.helpers);k=k||{};var i="",d,h="function",j=this.escapeExpression,o=this;function e(t,s){var q="",r;q+="\n \n ";return q}function c(t,s){var q="",r;q+="\n ";r=f["if"].call(t,t.defaultValue,{hash:{},inverse:o.program(6,n,s),fn:o.program(4,p,s),data:s});if(r||r===0){q+=r}q+="\n ";return q}function p(t,s){var q="",r;q+="\n ";if(r=f.defaultValue){r=r.call(t,{hash:{},data:s})}else{r=t.defaultValue;r=typeof r===h?r.apply(t):r}q+=j(r)+"\n ";return q}function n(r,q){return"\n (empty)\n "}i+="";if(d=f.name){d=d.call(m,{hash:{},data:k})}else{d=m.name;d=typeof d===h?d.apply(m):d}i+=j(d)+"\n\n ";d=f["if"].call(m,m.isBody,{hash:{},inverse:o.program(3,c,k),fn:o.program(1,e,k),data:k});if(d||d===0){i+=d}i+="\n\n";if(d=f.description){d=d.call(m,{hash:{},data:k})}else{d=m.description;d=typeof d===h?d.apply(m):d}if(d||d===0){i+=d}i+="\n";if(d=f.paramType){d=d.call(m,{hash:{},data:k})}else{d=m.paramType;d=typeof d===h?d.apply(m):d}if(d||d===0){i+=d}i+='\n\n';return i})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.param_required=b(function(f,q,o,j,u){this.compilerInfo=[4,">= 1.0.0"];o=this.merge(o,f.helpers);u=u||{};var p="",g,d="function",c=this.escapeExpression,n=this;function m(z,y){var w="",x;w+="\n ";x=o["if"].call(z,z.isFile,{hash:{},inverse:n.program(4,k,y),fn:n.program(2,l,y),data:y});if(x||x===0){w+=x}w+="\n ";return w}function l(z,y){var w="",x;w+='\n \n ";return w}function k(z,y){var w="",x;w+="\n ";x=o["if"].call(z,z.defaultValue,{hash:{},inverse:n.program(7,h,y),fn:n.program(5,i,y),data:y});if(x||x===0){w+=x}w+="\n ";return w}function i(z,y){var w="",x;w+="\n \n ";return w}function h(z,y){var w="",x;w+="\n \n
\n
\n ';return w}function e(z,y){var w="",x;w+="\n ";x=o["if"].call(z,z.isFile,{hash:{},inverse:n.program(12,t,y),fn:n.program(10,v,y),data:y});if(x||x===0){w+=x}w+="\n ";return w}function v(z,y){var w="",x;w+="\n \n ";return w}function t(z,y){var w="",x;w+="\n ";x=o["if"].call(z,z.defaultValue,{hash:{},inverse:n.program(15,r,y),fn:n.program(13,s,y),data:y});if(x||x===0){w+=x}w+="\n ";return w}function s(z,y){var w="",x;w+="\n \n ";return w}function r(z,y){var w="",x;w+="\n \n ";return w}p+="";if(g=o.name){g=g.call(q,{hash:{},data:u})}else{g=q.name;g=typeof g===d?g.apply(q):g}p+=c(g)+"\n\n ";g=o["if"].call(q,q.isBody,{hash:{},inverse:n.program(9,e,u),fn:n.program(1,m,u),data:u});if(g||g===0){p+=g}p+="\n\n\n ";if(g=o.description){g=g.call(q,{hash:{},data:u})}else{g=q.description;g=typeof g===d?g.apply(q):g}if(g||g===0){p+=g}p+="\n\n";if(g=o.paramType){g=g.call(q,{hash:{},data:u})}else{g=q.paramType;g=typeof g===d?g.apply(q):g}if(g||g===0){p+=g}p+='\n\n';return p})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.parameter_content_type=b(function(g,l,f,k,j){this.compilerInfo=[4,">= 1.0.0"];f=this.merge(f,g.helpers);j=j||{};var i="",c,h="function",m=this;function e(r,q){var o="",p;o+="\n ";p=f.each.call(r,r.consumes,{hash:{},inverse:m.noop,fn:m.program(2,d,q),data:q});if(p||p===0){o+=p}o+="\n";return o}function d(r,q){var o="",p;o+='\n \n ";return o}function n(p,o){return'\n \n'}i+='\n\n";return i})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.resource=b(function(f,l,e,k,j){this.compilerInfo=[4,">= 1.0.0"];e=this.merge(e,f.helpers);j=j||{};var h="",c,o,g="function",i=this.escapeExpression,n=this,m=e.blockHelperMissing;function d(q,p){return" : "}h+="
\n

\n ";if(c=e.name){c=c.call(l,{hash:{},data:j})}else{c=l.name;c=typeof c===g?c.apply(l):c}h+=i(c)+" ";o={hash:{},inverse:n.noop,fn:n.program(1,d,j),data:j};if(c=e.description){c=c.call(l,o)}else{c=l.description;c=typeof c===g?c.apply(l):c}if(!e.description){c=m.call(l,c,o)}if(c||c===0){h+=c}if(c=e.description){c=c.call(l,{hash:{},data:j})}else{c=l.description;c=typeof c===g?c.apply(l):c}if(c||c===0){h+=c}h+="\n

\n \n
\n\n";return h})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.response_content_type=b(function(g,l,f,k,j){this.compilerInfo=[4,">= 1.0.0"];f=this.merge(f,g.helpers);j=j||{};var i="",c,h="function",m=this;function e(r,q){var o="",p;o+="\n ";p=f.each.call(r,r.produces,{hash:{},inverse:m.noop,fn:m.program(2,d,q),data:q});if(p||p===0){o+=p}o+="\n";return o}function d(r,q){var o="",p;o+='\n \n ";return o}function n(p,o){return'\n \n'}i+='\n\n";return i})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.signature=b(function(e,k,d,j,i){this.compilerInfo=[4,">= 1.0.0"];d=this.merge(d,e.helpers);i=i||{};var g="",c,f="function",h=this.escapeExpression;g+='
\n\n
\n\n
\n
\n ';if(c=d.signature){c=c.call(k,{hash:{},data:i})}else{c=k.signature;c=typeof c===f?c.apply(k):c}if(c||c===0){g+=c}g+='\n
\n\n
\n
';if(c=d.sampleJSON){c=c.call(k,{hash:{},data:i})}else{c=k.sampleJSON;c=typeof c===f?c.apply(k):c}g+=h(c)+'
\n \n
\n
\n\n';return g})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.status_code=b(function(e,k,d,j,i){this.compilerInfo=[4,">= 1.0.0"];d=this.merge(d,e.helpers);i=i||{};var g="",c,f="function",h=this.escapeExpression;g+="";if(c=d.code){c=c.call(k,{hash:{},data:i})}else{c=k.code;c=typeof c===f?c.apply(k):c}g+=h(c)+"\n";if(c=d.message){c=c.call(k,{hash:{},data:i})}else{c=k.message;c=typeof c===f?c.apply(k):c}if(c||c===0){g+=c}g+="\n";return g})})();(function(){var j,r,u,o,l,k,n,m,i,p,s,q,h,c,g,f,e,d,b,a,x,w,t={}.hasOwnProperty,v=function(B,z){for(var y in z){if(t.call(z,y)){B[y]=z[y]}}function A(){this.constructor=B}A.prototype=z.prototype;B.prototype=new A();B.__super__=z.prototype;return B};s=(function(z){v(y,z);function y(){q=y.__super__.constructor.apply(this,arguments);return q}y.prototype.dom_id="swagger_ui";y.prototype.options=null;y.prototype.api=null;y.prototype.headerView=null;y.prototype.mainView=null;y.prototype.initialize=function(A){var B=this;if(A==null){A={}}if(A.dom_id!=null){this.dom_id=A.dom_id;delete A.dom_id}if($("#"+this.dom_id)==null){$("body").append('
')}this.options=A;this.options.success=function(){return B.render()};this.options.progress=function(C){return B.showMessage(C)};this.options.failure=function(C){return B.onLoadFailure(C)};this.headerView=new r({el:$("#header")});return this.headerView.on("update-swagger-ui",function(C){return B.updateSwaggerUi(C)})};y.prototype.updateSwaggerUi=function(A){this.options.url=A.url;return this.load()};y.prototype.load=function(){var B,A;if((A=this.mainView)!=null){A.clear()}B=this.options.url;if(B.indexOf("http")!==0){B=this.buildUrl(window.location.href.toString(),B)}this.options.url=B;this.headerView.update(B);this.api=new SwaggerApi(this.options);this.api.build();return this.api};y.prototype.render=function(){var A=this;this.showMessage("Finished Loading Resource Information. Rendering Swagger UI...");this.mainView=new u({model:this.api,el:$("#"+this.dom_id),swaggerOptions:this.options}).render();this.showMessage();switch(this.options.docExpansion){case"full":Docs.expandOperationsForResource("");break;case"list":Docs.collapseOperationsForResource("")}if(this.options.onComplete){this.options.onComplete(this.api,this)}return setTimeout(function(){return Docs.shebang()},400)};y.prototype.buildUrl=function(C,A){var B,D;log("base is "+C);if(A.indexOf("/")===0){D=C.split("/");C=D[0]+"//"+D[2];return C+A}else{B=C.length;if(C.indexOf("?")>-1){B=Math.min(B,C.indexOf("?"))}if(C.indexOf("#")>-1){B=Math.min(B,C.indexOf("#"))}C=C.substring(0,B);if(C.indexOf("/",C.length-1)!==-1){return C+A}return C+"/"+A}};y.prototype.showMessage=function(A){if(A==null){A=""}$("#message-bar").removeClass("message-fail");$("#message-bar").addClass("message-success");return $("#message-bar").html(A)};y.prototype.onLoadFailure=function(A){var B;if(A==null){A=""}$("#message-bar").removeClass("message-success");$("#message-bar").addClass("message-fail");B=$("#message-bar").html(A);if(this.options.onFailure!=null){this.options.onFailure(A)}return B};return y})(Backbone.Router);window.SwaggerUi=s;r=(function(z){v(y,z);function y(){h=y.__super__.constructor.apply(this,arguments);return h}y.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"};y.prototype.initialize=function(){};y.prototype.showPetStore=function(A){return this.trigger("update-swagger-ui",{url:"http://petstore.swagger.wordnik.com/api/api-docs"})};y.prototype.showWordnikDev=function(A){return this.trigger("update-swagger-ui",{url:"http://api.wordnik.com/v4/resources.json"})};y.prototype.showCustomOnKeyup=function(A){if(A.keyCode===13){return this.showCustom()}};y.prototype.showCustom=function(A){if(A!=null){A.preventDefault()}return this.trigger("update-swagger-ui",{url:$("#input_baseUrl").val(),apiKey:$("#input_apiKey").val()})};y.prototype.update=function(B,C,A){if(A==null){A=false}$("#input_baseUrl").val(B);if(A){return this.trigger("update-swagger-ui",{url:B})}};return y})(Backbone.View);u=(function(y){var z;v(A,y);function A(){g=A.__super__.constructor.apply(this,arguments);return g}z={alpha:function(C,B){return C.path.localeCompare(B.path)},method:function(C,B){return C.method.localeCompare(B.method)}};A.prototype.initialize=function(D){var C,H,F,E,B,G;if(D==null){D={}}if(D.swaggerOptions.sorter){F=D.swaggerOptions.sorter;H=z[F];G=this.model.apisArray;for(E=0,B=G.length;EB){K=B-C}if(KA){H=A-E}if(H0){D[I.name]=I.value}if(I.type==="file"){N=true}}E=G.find("textarea");for(L=0,F=E.length;L0){D.body=I.value}}B=G.find("select");for(K=0,C=B.length;K0){D[I.name]=J}}A.responseContentType=$("div select[name=responseContentType]",$(this.el)).val();A.requestContentType=$("div select[name=parameterContentType]",$(this.el)).val();$(".response_throbber",$(this.el)).show();if(N){return this.handleFileUpload(D,G)}else{return this.model["do"](D,A,this.showCompleteStatus,this.showErrorStatus,this)}}};y.prototype.success=function(A,B){return B.showCompleteStatus(A)};y.prototype.handleFileUpload=function(R,I){var M,H,C,N,L,K,P,J,G,F,D,Q,U,T,S,E,B,A,V,O=this;E=I.serializeArray();for(J=0,Q=E.length;J0){R[N.name]=N.value}}M=new FormData();P=0;B=this.model.parameters;for(G=0,U=B.length;G");$(".request_url pre",$(this.el)).text(this.invocationUrl);L={type:this.model.method,url:this.invocationUrl,headers:C,data:M,dataType:"json",contentType:false,processData:false,error:function(X,Y,W){return O.showErrorStatus(O.wrap(X),O)},success:function(W){return O.showResponse(W,O)},complete:function(W){return O.showCompleteStatus(O.wrap(W),O)}};if(window.authorizations){window.authorizations.apply(L)}if(P===0){L.data.append("fake","true")}jQuery.ajax(L);return false};y.prototype.wrap=function(E){var C,F,H,B,G,D,A;H={};F=E.getAllResponseHeaders().split("\r");for(D=0,A=F.length;D0){return C.join(",")}else{return null}}};y.prototype.hideResponse=function(A){if(A!=null){A.preventDefault()}$(".response",$(this.el)).slideUp();return $(".response_hider",$(this.el)).fadeOut()};y.prototype.showResponse=function(A){var B;B=JSON.stringify(A,null,"\t").replace(/\n/g,"
");return $(".response_body",$(this.el)).html(escape(B))};y.prototype.showErrorStatus=function(B,A){return A.showStatus(B)};y.prototype.showCompleteStatus=function(B,A){return A.showStatus(B)};y.prototype.formatXml=function(H){var D,G,B,I,N,J,C,A,L,M,F,E,K;A=/(>)(<)(\/*)/g;M=/[ ]*(.*)[ ]+\n/g;D=/(<.+>)(.+\n)/g;H=H.replace(A,"$1\n$2$3").replace(M,"$1\n").replace(D,"$1\n$2");C=0;G="";N=H.split("\n");B=0;I="other";L={"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};F=function(T){var P,O,R,V,S,Q,U;Q={single:Boolean(T.match(/<.+\/>/)),closing:Boolean(T.match(/<\/.+>/)),opening:Boolean(T.match(/<[^!?].*>/))};S=((function(){var W;W=[];for(R in Q){U=Q[R];if(U){W.push(R)}}return W})())[0];S=S===void 0?"other":S;P=I+"->"+S;I=S;V="";B+=L[P];V=((function(){var X,Y,W;W=[];for(O=X=0,Y=B;0<=Y?XY;O=0<=Y?++X:--X){W.push(" ")}return W})()).join("");if(P==="opening->closing"){return G=G.substr(0,G.length-1)+T+"\n"}else{return G+=V+T+"\n"}};for(E=0,K=N.length;E").text("no content");E=$('
').append(C)}else{if(J==="application/json"||/\+json$/.test(J)){C=$("").text(JSON.stringify(JSON.parse(H),null,"  "));E=$('
').append(C)}else{if(J==="application/xml"||/\+xml$/.test(J)){C=$("").text(this.formatXml(H));E=$('
').append(C)}else{if(J==="text/html"){C=$("").html(H);E=$('
').append(C)}else{if(/^image\//.test(J)){E=$("").attr("src",B)}else{C=$("").text(H);E=$('
').append(C)}}}}}I=E;$(".request_url",$(this.el)).html("
");$(".request_url pre",$(this.el)).text(B);$(".response_code",$(this.el)).html("
"+F.status+"
");$(".response_body",$(this.el)).html(I);$(".response_headers",$(this.el)).html("
"+_.escape(JSON.stringify(F.headers,null,"  ")).replace(/\n/g,"
")+"
");$(".response",$(this.el)).slideDown();$(".response_hider",$(this.el)).show();$(".response_throbber",$(this.el)).hide();G=$(".response_body",$(this.el))[0];A=this.options.swaggerOptions;if(A.highlightSizeThreshold&&F.data.length>A.highlightSizeThreshold){return G}else{return hljs.highlightBlock(G)}};y.prototype.toggleOperationContent=function(){var A;A=$("#"+Docs.escapeResourceName(this.model.parentId)+"_"+this.model.nickname+"_content");if(A.is(":visible")){return Docs.collapseOperation(A)}else{return Docs.expandOperation(A)}};return y})(Backbone.View);p=(function(z){v(y,z);function y(){d=y.__super__.constructor.apply(this,arguments);return d}y.prototype.initialize=function(){};y.prototype.render=function(){var B,A,C;C=this.template();$(this.el).html(C(this.model));if(swaggerUi.api.models.hasOwnProperty(this.model.responseModel)){B={sampleJSON:JSON.stringify(swaggerUi.api.models[this.model.responseModel].createJSONSample(),null,2),isParam:false,signature:swaggerUi.api.models[this.model.responseModel].getMockSignature()};A=new i({model:B,tagName:"div"});$(".model-signature",this.$el).append(A.render().el)}else{$(".model-signature",this.$el).html("")}return this};y.prototype.template=function(){return Handlebars.templates.status_code};return y})(Backbone.View);k=(function(z){v(y,z);function y(){b=y.__super__.constructor.apply(this,arguments);return b}y.prototype.initialize=function(){return Handlebars.registerHelper("isArray",function(B,A){if(B.type.toLowerCase()==="array"||B.allowMultiple){return A.fn(this)}else{return A.inverse(this)}})};y.prototype.render=function(){var G,A,C,F,B,H,E,D;D=this.model.type||this.model.dataType;if(this.model.paramType==="body"){this.model.isBody=true}if(D.toLowerCase()==="file"){this.model.isFile=true}E=this.template();$(this.el).html(E(this.model));B={sampleJSON:this.model.sampleJSON,isParam:true,signature:this.model.signature};if(this.model.sampleJSON){H=new i({model:B,tagName:"div"});$(".model-signature",$(this.el)).append(H.render().el)}else{$(".model-signature",$(this.el)).html(this.model.signature)}A=false;if(this.model.isBody){A=true}G={isParam:A};G.consumes=this.model.consumes;if(A){C=new l({model:G});$(".parameter-content-type",$(this.el)).append(C.render().el)}else{F=new m({model:G});$(".response-content-type",$(this.el)).append(F.render().el)}return this};y.prototype.template=function(){if(this.model.isList){return Handlebars.templates.param_list}else{if(this.options.readOnly){if(this.model.required){return Handlebars.templates.param_readonly_required}else{return Handlebars.templates.param_readonly}}else{if(this.model.required){return Handlebars.templates.param_required}else{return Handlebars.templates.param}}}};return y})(Backbone.View);i=(function(z){v(y,z);function y(){a=y.__super__.constructor.apply(this,arguments);return a}y.prototype.events={"click a.description-link":"switchToDescription","click a.snippet-link":"switchToSnippet","mousedown .snippet":"snippetToTextArea"};y.prototype.initialize=function(){};y.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));this.switchToSnippet();this.isParam=this.model.isParam;if(this.isParam){$(".notice",$(this.el)).text("Click to set as parameter value")}return this};y.prototype.template=function(){return Handlebars.templates.signature};y.prototype.switchToDescription=function(A){if(A!=null){A.preventDefault()}$(".snippet",$(this.el)).hide();$(".description",$(this.el)).show();$(".description-link",$(this.el)).addClass("selected");return $(".snippet-link",$(this.el)).removeClass("selected")};y.prototype.switchToSnippet=function(A){if(A!=null){A.preventDefault()}$(".description",$(this.el)).hide();$(".snippet",$(this.el)).show();$(".snippet-link",$(this.el)).addClass("selected");return $(".description-link",$(this.el)).removeClass("selected")};y.prototype.snippetToTextArea=function(A){var B;if(this.isParam){if(A!=null){A.preventDefault()}B=$("textarea",$(this.el.parentNode.parentNode.parentNode));if($.trim(B.val())===""){return B.val(this.model.sampleJSON)}}};return y})(Backbone.View);j=(function(y){v(z,y);function z(){x=z.__super__.constructor.apply(this,arguments);return x}z.prototype.initialize=function(){};z.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));$("label[for=contentType]",$(this.el)).text("Response Content Type");return this};z.prototype.template=function(){return Handlebars.templates.content_type};return z})(Backbone.View);m=(function(y){v(z,y);function z(){w=z.__super__.constructor.apply(this,arguments);return w}z.prototype.initialize=function(){};z.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));$("label[for=responseContentType]",$(this.el)).text("Response Content Type");return this};z.prototype.template=function(){return Handlebars.templates.response_content_type};return z})(Backbone.View);l=(function(z){v(y,z);function y(){c=y.__super__.constructor.apply(this,arguments);return c}y.prototype.initialize=function(){};y.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));$("label[for=parameterContentType]",$(this.el)).text("Parameter content type:");return this};y.prototype.template=function(){return Handlebars.templates.parameter_content_type};return y})(Backbone.View)}).call(this); \ No newline at end of file +$(function(){$.fn.vAlign=function(){return this.each(function(c){var a=$(this).height();var d=$(this).parent().height();var b=(d-a)/2;$(this).css("margin-top",b)})};$.fn.stretchFormtasticInputWidthToParent=function(){return this.each(function(b){var d=$(this).closest("form").innerWidth();var c=parseInt($(this).closest("form").css("padding-left"),10)+parseInt($(this).closest("form").css("padding-right"),10);var a=parseInt($(this).css("padding-left"),10)+parseInt($(this).css("padding-right"),10);$(this).css("width",d-c-a)})};$("form.formtastic li.string input, form.formtastic textarea").stretchFormtasticInputWidthToParent();$("ul.downplayed li div.content p").vAlign();$("form.sandbox").submit(function(){var a=true;$(this).find("input.required").each(function(){$(this).removeClass("error");if($(this).val()==""){$(this).addClass("error");$(this).wiggle();a=false}});return a})});function clippyCopiedCallback(b){$("#api_key_copied").fadeIn().delay(1000).fadeOut()}log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){console.log(Array.prototype.slice.call(arguments)[0])}};if(Function.prototype.bind&&console&&typeof console.log=="object"){["log","info","warn","error","assert","dir","clear","profile","profileEnd"].forEach(function(a){console[a]=this.bind(console[a],console)},Function.prototype.call)}var Docs={shebang:function(){var b=$.param.fragment().split("/");b.shift();switch(b.length){case 1:var d="resource_"+b[0];Docs.expandEndpointListForResource(b[0]);$("#"+d).slideto({highlight:false});break;case 2:Docs.expandEndpointListForResource(b[0]);$("#"+d).slideto({highlight:false});var c=b.join("_");var a=c+"_content";Docs.expandOperation($("#"+a));$("#"+c).slideto({highlight:false});break}},toggleEndpointListForResource:function(b){var a=$("li#resource_"+Docs.escapeResourceName(b)+" ul.endpoints");if(a.is(":visible")){Docs.collapseEndpointListForResource(b)}else{Docs.expandEndpointListForResource(b)}},expandEndpointListForResource:function(b){var b=Docs.escapeResourceName(b);if(b==""){$(".resource ul.endpoints").slideDown();return}$("li#resource_"+b).addClass("active");var a=$("li#resource_"+b+" ul.endpoints");a.slideDown()},collapseEndpointListForResource:function(b){var b=Docs.escapeResourceName(b);$("li#resource_"+b).removeClass("active");var a=$("li#resource_"+b+" ul.endpoints");a.slideUp()},expandOperationsForResource:function(a){Docs.expandEndpointListForResource(a);if(a==""){$(".resource ul.endpoints li.operation div.content").slideDown();return}$("li#resource_"+Docs.escapeResourceName(a)+" li.operation div.content").each(function(){Docs.expandOperation($(this))})},collapseOperationsForResource:function(a){Docs.expandEndpointListForResource(a);$("li#resource_"+Docs.escapeResourceName(a)+" li.operation div.content").each(function(){Docs.collapseOperation($(this))})},escapeResourceName:function(a){return a.replace(/[!"#$%&'()*+,.\/:;<=>?@\[\\\]\^`{|}~]/g,"\\$&")},expandOperation:function(a){a.slideDown()},collapseOperation:function(a){a.slideUp()}};(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.content_type=b(function(g,l,f,k,j){this.compilerInfo=[4,">= 1.0.0"];f=this.merge(f,g.helpers);j=j||{};var i="",c,h="function",m=this;function e(r,q){var o="",p;o+="\n ";p=f.each.call(r,r.produces,{hash:{},inverse:m.noop,fn:m.program(2,d,q),data:q});if(p||p===0){o+=p}o+="\n";return o}function d(r,q){var o="",p;o+='\n \n ";return o}function n(p,o){return'\n \n'}i+='\n\n";return i})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.main=b(function(g,m,f,l,k){this.compilerInfo=[4,">= 1.0.0"];f=this.merge(f,g.helpers);k=k||{};var i="",c,h="function",j=this.escapeExpression,p=this;function e(v,u){var r="",t,s;r+='\n
'+j(((t=((t=v.info),t==null||t===false?t:t.title)),typeof t===h?t.apply(v):t))+'
\n
';s=((t=((t=v.info),t==null||t===false?t:t.description)),typeof t===h?t.apply(v):t);if(s||s===0){r+=s}r+="
\n ";s=f["if"].call(v,((t=v.info),t==null||t===false?t:t.termsOfServiceUrl),{hash:{},inverse:p.noop,fn:p.program(2,d,u),data:u});if(s||s===0){r+=s}r+="\n ";s=f["if"].call(v,((t=v.info),t==null||t===false?t:t.contact),{hash:{},inverse:p.noop,fn:p.program(4,q,u),data:u});if(s||s===0){r+=s}r+="\n ";s=f["if"].call(v,((t=v.info),t==null||t===false?t:t.license),{hash:{},inverse:p.noop,fn:p.program(6,o,u),data:u});if(s||s===0){r+=s}r+="\n ";return r}function d(u,t){var r="",s;r+='';return r}function q(u,t){var r="",s;r+="';return r}function o(u,t){var r="",s;r+="";return r}function n(u,t){var r="",s;r+='\n , api version: ';if(s=f.apiVersion){s=s.call(u,{hash:{},data:t})}else{s=u.apiVersion;s=typeof s===h?s.apply(u):s}r+=j(s)+"\n ";return r}i+="
\n ";c=f["if"].call(m,m.info,{hash:{},inverse:p.noop,fn:p.program(1,e,k),data:k});if(c||c===0){i+=c}i+="\n
\n
\n
    \n
\n\n
\n
\n
\n

[ base url: ";if(c=f.basePath){c=c.call(m,{hash:{},data:k})}else{c=m.basePath;c=typeof c===h?c.apply(m):c}i+=j(c)+"\n ";c=f["if"].call(m,m.apiVersion,{hash:{},inverse:p.noop,fn:p.program(8,n,k),data:k});if(c||c===0){i+=c}i+="]

\n
\n
\n";return i})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.operation=b(function(g,s,q,m,y){this.compilerInfo=[4,">= 1.0.0"];q=this.merge(q,g.helpers);y=y||{};var r="",i,f,e="function",d=this.escapeExpression,p=this,c=q.blockHelperMissing;function o(C,B){var z="",A;z+="\n

Implementation Notes

\n

";if(A=q.notes){A=A.call(C,{hash:{},data:B})}else{A=C.notes;A=typeof A===e?A.apply(C):A}if(A||A===0){z+=A}z+="

\n ";return z}function n(A,z){return'\n
\n '}function l(C,B){var z="",A;z+='\n \n ";return z}function k(D,C){var z="",B,A;z+="\n
"+d(((B=D.scope),typeof B===e?B.apply(D):B))+"
\n ";return z}function h(A,z){return"
"}function x(A,z){return'\n
\n \n
\n '}function w(A,z){return'\n

Response Class

\n

\n
\n
\n '}function v(A,z){return'\n

Parameters

\n \n \n \n \n \n \n \n \n \n \n \n\n \n
ParameterValueDescriptionParameter TypeData Type
\n '}function u(A,z){return"\n
\n

Response Messages

\n \n \n \n \n \n \n \n \n \n \n \n
HTTP Status CodeReasonResponse Model
\n "}function t(A,z){return"\n "}function j(A,z){return"\n
\n \n \n \n
\n "}r+="\n
    \n
  • \n \n \n
  • \n
\n";return r})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.param=b(function(f,q,o,j,t){this.compilerInfo=[4,">= 1.0.0"];o=this.merge(o,f.helpers);t=t||{};var p="",g,d="function",c=this.escapeExpression,n=this;function m(y,x){var v="",w;v+="\n ";w=o["if"].call(y,y.isFile,{hash:{},inverse:n.program(4,k,x),fn:n.program(2,l,x),data:x});if(w||w===0){v+=w}v+="\n ";return v}function l(y,x){var v="",w;v+='\n \n
\n ';return v}function k(y,x){var v="",w;v+="\n ";w=o["if"].call(y,y.defaultValue,{hash:{},inverse:n.program(7,h,x),fn:n.program(5,i,x),data:x});if(w||w===0){v+=w}v+="\n ";return v}function i(y,x){var v="",w;v+="\n \n ";return v}function h(y,x){var v="",w;v+="\n \n
\n
\n ';return v}function e(y,x){var v="",w;v+="\n ";w=o["if"].call(y,y.isFile,{hash:{},inverse:n.program(10,u,x),fn:n.program(2,l,x),data:x});if(w||w===0){v+=w}v+="\n ";return v}function u(y,x){var v="",w;v+="\n ";w=o["if"].call(y,y.defaultValue,{hash:{},inverse:n.program(13,r,x),fn:n.program(11,s,x),data:x});if(w||w===0){v+=w}v+="\n ";return v}function s(y,x){var v="",w;v+="\n \n ";return v}function r(y,x){var v="",w;v+="\n \n ";return v}p+="";if(g=o.name){g=g.call(q,{hash:{},data:t})}else{g=q.name;g=typeof g===d?g.apply(q):g}p+=c(g)+"\n\n\n ";g=o["if"].call(q,q.isBody,{hash:{},inverse:n.program(9,e,t),fn:n.program(1,m,t),data:t});if(g||g===0){p+=g}p+="\n\n\n";if(g=o.description){g=g.call(q,{hash:{},data:t})}else{g=q.description;g=typeof g===d?g.apply(q):g}if(g||g===0){p+=g}p+="\n";if(g=o.paramType){g=g.call(q,{hash:{},data:t})}else{g=q.paramType;g=typeof g===d?g.apply(q):g}if(g||g===0){p+=g}p+='\n\n \n\n';return p})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.param_list=b(function(h,t,r,m,y){this.compilerInfo=[4,">= 1.0.0"];r=this.merge(r,h.helpers);y=y||{};var s="",j,g,e,p=this,q=r.helperMissing,d="function",c=this.escapeExpression;function o(A,z){return" multiple='multiple'"}function n(A,z){return"\n "}function l(C,B){var z="",A;z+="\n ";A=r["if"].call(C,C.defaultValue,{hash:{},inverse:p.program(8,i,B),fn:p.program(6,k,B),data:B});if(A||A===0){z+=A}z+="\n ";return z}function k(A,z){return"\n "}function i(E,D){var z="",C,B,A;z+="\n ";A={hash:{},inverse:p.program(11,x,D),fn:p.program(9,f,D),data:D};B=((C=r.isArray||E.isArray),C?C.call(E,E,A):q.call(E,"isArray",E,A));if(B||B===0){z+=B}z+="\n ";return z}function f(A,z){return"\n "}function x(A,z){return"\n \n "}function w(C,B){var z="",A;z+="\n ";A=r["if"].call(C,C.isDefault,{hash:{},inverse:p.program(16,u,B),fn:p.program(14,v,B),data:B});if(A||A===0){z+=A}z+="\n ";return z}function v(C,B){var z="",A;z+='\n \n ";return z}function u(C,B){var z="",A;z+="\n \n ";return z}s+="";if(j=r.name){j=j.call(t,{hash:{},data:y})}else{j=t.name;j=typeof j===d?j.apply(t):j}s+=c(j)+"\n\n \n\n";if(g=r.description){g=g.call(t,{hash:{},data:y})}else{g=t.description;g=typeof g===d?g.apply(t):g}if(g||g===0){s+=g}s+="\n";if(g=r.paramType){g=g.call(t,{hash:{},data:y})}else{g=t.paramType;g=typeof g===d?g.apply(t):g}if(g||g===0){s+=g}s+='\n';return s})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.param_readonly=b(function(g,m,f,l,k){this.compilerInfo=[4,">= 1.0.0"];f=this.merge(f,g.helpers);k=k||{};var i="",d,h="function",j=this.escapeExpression,o=this;function e(t,s){var q="",r;q+="\n \n ";return q}function c(t,s){var q="",r;q+="\n ";r=f["if"].call(t,t.defaultValue,{hash:{},inverse:o.program(6,n,s),fn:o.program(4,p,s),data:s});if(r||r===0){q+=r}q+="\n ";return q}function p(t,s){var q="",r;q+="\n ";if(r=f.defaultValue){r=r.call(t,{hash:{},data:s})}else{r=t.defaultValue;r=typeof r===h?r.apply(t):r}q+=j(r)+"\n ";return q}function n(r,q){return"\n (empty)\n "}i+="";if(d=f.name){d=d.call(m,{hash:{},data:k})}else{d=m.name;d=typeof d===h?d.apply(m):d}i+=j(d)+"\n\n ";d=f["if"].call(m,m.isBody,{hash:{},inverse:o.program(3,c,k),fn:o.program(1,e,k),data:k});if(d||d===0){i+=d}i+="\n\n";if(d=f.description){d=d.call(m,{hash:{},data:k})}else{d=m.description;d=typeof d===h?d.apply(m):d}if(d||d===0){i+=d}i+="\n";if(d=f.paramType){d=d.call(m,{hash:{},data:k})}else{d=m.paramType;d=typeof d===h?d.apply(m):d}if(d||d===0){i+=d}i+='\n\n';return i})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.param_readonly_required=b(function(g,m,f,l,k){this.compilerInfo=[4,">= 1.0.0"];f=this.merge(f,g.helpers);k=k||{};var i="",d,h="function",j=this.escapeExpression,o=this;function e(t,s){var q="",r;q+="\n \n ";return q}function c(t,s){var q="",r;q+="\n ";r=f["if"].call(t,t.defaultValue,{hash:{},inverse:o.program(6,n,s),fn:o.program(4,p,s),data:s});if(r||r===0){q+=r}q+="\n ";return q}function p(t,s){var q="",r;q+="\n ";if(r=f.defaultValue){r=r.call(t,{hash:{},data:s})}else{r=t.defaultValue;r=typeof r===h?r.apply(t):r}q+=j(r)+"\n ";return q}function n(r,q){return"\n (empty)\n "}i+="";if(d=f.name){d=d.call(m,{hash:{},data:k})}else{d=m.name;d=typeof d===h?d.apply(m):d}i+=j(d)+"\n\n ";d=f["if"].call(m,m.isBody,{hash:{},inverse:o.program(3,c,k),fn:o.program(1,e,k),data:k});if(d||d===0){i+=d}i+="\n\n";if(d=f.description){d=d.call(m,{hash:{},data:k})}else{d=m.description;d=typeof d===h?d.apply(m):d}if(d||d===0){i+=d}i+="\n";if(d=f.paramType){d=d.call(m,{hash:{},data:k})}else{d=m.paramType;d=typeof d===h?d.apply(m):d}if(d||d===0){i+=d}i+='\n\n';return i})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.param_required=b(function(f,q,o,j,u){this.compilerInfo=[4,">= 1.0.0"];o=this.merge(o,f.helpers);u=u||{};var p="",g,d="function",c=this.escapeExpression,n=this;function m(z,y){var w="",x;w+="\n ";x=o["if"].call(z,z.isFile,{hash:{},inverse:n.program(4,k,y),fn:n.program(2,l,y),data:y});if(x||x===0){w+=x}w+="\n ";return w}function l(z,y){var w="",x;w+='\n \n ";return w}function k(z,y){var w="",x;w+="\n ";x=o["if"].call(z,z.defaultValue,{hash:{},inverse:n.program(7,h,y),fn:n.program(5,i,y),data:y});if(x||x===0){w+=x}w+="\n ";return w}function i(z,y){var w="",x;w+="\n \n ";return w}function h(z,y){var w="",x;w+="\n \n
\n
\n ';return w}function e(z,y){var w="",x;w+="\n ";x=o["if"].call(z,z.isFile,{hash:{},inverse:n.program(12,t,y),fn:n.program(10,v,y),data:y});if(x||x===0){w+=x}w+="\n ";return w}function v(z,y){var w="",x;w+="\n \n ";return w}function t(z,y){var w="",x;w+="\n ";x=o["if"].call(z,z.defaultValue,{hash:{},inverse:n.program(15,r,y),fn:n.program(13,s,y),data:y});if(x||x===0){w+=x}w+="\n ";return w}function s(z,y){var w="",x;w+="\n \n ";return w}function r(z,y){var w="",x;w+="\n \n ";return w}p+="";if(g=o.name){g=g.call(q,{hash:{},data:u})}else{g=q.name;g=typeof g===d?g.apply(q):g}p+=c(g)+"\n\n ";g=o["if"].call(q,q.isBody,{hash:{},inverse:n.program(9,e,u),fn:n.program(1,m,u),data:u});if(g||g===0){p+=g}p+="\n\n\n ";if(g=o.description){g=g.call(q,{hash:{},data:u})}else{g=q.description;g=typeof g===d?g.apply(q):g}if(g||g===0){p+=g}p+="\n\n";if(g=o.paramType){g=g.call(q,{hash:{},data:u})}else{g=q.paramType;g=typeof g===d?g.apply(q):g}if(g||g===0){p+=g}p+='\n\n';return p})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.parameter_content_type=b(function(g,l,f,k,j){this.compilerInfo=[4,">= 1.0.0"];f=this.merge(f,g.helpers);j=j||{};var i="",c,h="function",m=this;function e(r,q){var o="",p;o+="\n ";p=f.each.call(r,r.consumes,{hash:{},inverse:m.noop,fn:m.program(2,d,q),data:q});if(p||p===0){o+=p}o+="\n";return o}function d(r,q){var o="",p;o+='\n \n ";return o}function n(p,o){return'\n \n'}i+='\n\n";return i})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.resource=b(function(f,l,e,k,j){this.compilerInfo=[4,">= 1.0.0"];e=this.merge(e,f.helpers);j=j||{};var h="",c,o,g="function",i=this.escapeExpression,n=this,m=e.blockHelperMissing;function d(q,p){return" : "}h+="
\n

\n /";if(c=e.name){c=c.call(l,{hash:{},data:j})}else{c=l.name;c=typeof c===g?c.apply(l):c}h+=i(c)+" ";o={hash:{},inverse:n.noop,fn:n.program(1,d,j),data:j};if(c=e.description){c=c.call(l,o)}else{c=l.description;c=typeof c===g?c.apply(l):c}if(!e.description){c=m.call(l,c,o)}if(c||c===0){h+=c}if(c=e.description){c=c.call(l,{hash:{},data:j})}else{c=l.description;c=typeof c===g?c.apply(l):c}if(c||c===0){h+=c}h+="\n

\n \n
\n\n";return h})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.response_content_type=b(function(g,l,f,k,j){this.compilerInfo=[4,">= 1.0.0"];f=this.merge(f,g.helpers);j=j||{};var i="",c,h="function",m=this;function e(r,q){var o="",p;o+="\n ";p=f.each.call(r,r.produces,{hash:{},inverse:m.noop,fn:m.program(2,d,q),data:q});if(p||p===0){o+=p}o+="\n";return o}function d(r,q){var o="",p;o+='\n \n ";return o}function n(p,o){return'\n \n'}i+='\n\n";return i})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.signature=b(function(e,k,d,j,i){this.compilerInfo=[4,">= 1.0.0"];d=this.merge(d,e.helpers);i=i||{};var g="",c,f="function",h=this.escapeExpression;g+='
\n\n
\n\n
\n
\n ';if(c=d.signature){c=c.call(k,{hash:{},data:i})}else{c=k.signature;c=typeof c===f?c.apply(k):c}if(c||c===0){g+=c}g+='\n
\n\n
\n
';if(c=d.sampleJSON){c=c.call(k,{hash:{},data:i})}else{c=k.sampleJSON;c=typeof c===f?c.apply(k):c}g+=h(c)+'
\n \n
\n
\n\n';return g})})();(function(){var b=Handlebars.template,a=Handlebars.templates=Handlebars.templates||{};a.status_code=b(function(e,k,d,j,i){this.compilerInfo=[4,">= 1.0.0"];d=this.merge(d,e.helpers);i=i||{};var g="",c,f="function",h=this.escapeExpression;g+="";if(c=d.code){c=c.call(k,{hash:{},data:i})}else{c=k.code;c=typeof c===f?c.apply(k):c}g+=h(c)+"\n";if(c=d.message){c=c.call(k,{hash:{},data:i})}else{c=k.message;c=typeof c===f?c.apply(k):c}if(c||c===0){g+=c}g+="\n";return g})})();(function(){var j,r,u,o,l,k,n,m,i,p,s,q,h,c,g,f,e,d,b,a,x,w,t={}.hasOwnProperty,v=function(B,z){for(var y in z){if(t.call(z,y)){B[y]=z[y]}}function A(){this.constructor=B}A.prototype=z.prototype;B.prototype=new A();B.__super__=z.prototype;return B};s=(function(z){v(y,z);function y(){q=y.__super__.constructor.apply(this,arguments);return q}y.prototype.dom_id="swagger_ui";y.prototype.options=null;y.prototype.api=null;y.prototype.headerView=null;y.prototype.mainView=null;y.prototype.initialize=function(A){var B=this;if(A==null){A={}}if(A.dom_id!=null){this.dom_id=A.dom_id;delete A.dom_id}if($("#"+this.dom_id)==null){$("body").append('
')}this.options=A;this.options.success=function(){return B.render()};this.options.progress=function(C){return B.showMessage(C)};this.options.failure=function(C){return B.onLoadFailure(C)};this.headerView=new r({el:$("#header")});return this.headerView.on("update-swagger-ui",function(C){return B.updateSwaggerUi(C)})};y.prototype.updateSwaggerUi=function(A){this.options.url=A.url;return this.load()};y.prototype.load=function(){var B,A;if((A=this.mainView)!=null){A.clear()}B=this.options.url;if(B.indexOf("http")!==0){B=this.buildUrl(window.location.href.toString(),B)}this.options.url=B;this.headerView.update(B);if(B.indexOf("swagger.json")>0){this.api=new SwaggerClient(this.options);this.api.build();return this.api}else{this.api=new SwaggerApi(this.options);this.api.build();return this.api}};y.prototype.render=function(){var A=this;this.showMessage("Finished Loading Resource Information. Rendering Swagger UI...");this.mainView=new u({model:this.api,el:$("#"+this.dom_id),swaggerOptions:this.options}).render();this.showMessage();switch(this.options.docExpansion){case"full":Docs.expandOperationsForResource("");break;case"list":Docs.collapseOperationsForResource("")}if(this.options.onComplete){this.options.onComplete(this.api,this)}return setTimeout(function(){return Docs.shebang()},400)};y.prototype.buildUrl=function(C,A){var B,D;log("base is "+C);if(A.indexOf("/")===0){D=C.split("/");C=D[0]+"//"+D[2];return C+A}else{B=C.length;if(C.indexOf("?")>-1){B=Math.min(B,C.indexOf("?"))}if(C.indexOf("#")>-1){B=Math.min(B,C.indexOf("#"))}C=C.substring(0,B);if(C.indexOf("/",C.length-1)!==-1){return C+A}return C+"/"+A}};y.prototype.showMessage=function(A){if(A==null){A=""}$("#message-bar").removeClass("message-fail");$("#message-bar").addClass("message-success");return $("#message-bar").html(A)};y.prototype.onLoadFailure=function(A){var B;if(A==null){A=""}$("#message-bar").removeClass("message-success");$("#message-bar").addClass("message-fail");B=$("#message-bar").html(A);if(this.options.onFailure!=null){this.options.onFailure(A)}return B};return y})(Backbone.Router);window.SwaggerUi=s;r=(function(z){v(y,z);function y(){h=y.__super__.constructor.apply(this,arguments);return h}y.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"};y.prototype.initialize=function(){};y.prototype.showPetStore=function(A){return this.trigger("update-swagger-ui",{url:"http://petstore.swagger.wordnik.com/api/api-docs"})};y.prototype.showWordnikDev=function(A){return this.trigger("update-swagger-ui",{url:"http://api.wordnik.com/v4/resources.json"})};y.prototype.showCustomOnKeyup=function(A){if(A.keyCode===13){return this.showCustom()}};y.prototype.showCustom=function(A){if(A!=null){A.preventDefault()}return this.trigger("update-swagger-ui",{url:$("#input_baseUrl").val(),apiKey:$("#input_apiKey").val()})};y.prototype.update=function(B,C,A){if(A==null){A=false}$("#input_baseUrl").val(B);if(A){return this.trigger("update-swagger-ui",{url:B})}};return y})(Backbone.View);u=(function(y){var z;v(A,y);function A(){g=A.__super__.constructor.apply(this,arguments);return g}z={alpha:function(C,B){return C.path.localeCompare(B.path)},method:function(C,B){return C.method.localeCompare(B.method)}};A.prototype.initialize=function(D){var C,H,F,E,B,G;if(D==null){D={}}if(D.swaggerOptions.sorter){F=D.swaggerOptions.sorter;H=z[F];if(this.model.apisArray){G=this.model.apisArray;for(E=0,B=G.length;EB){K=B-C}if(KA){H=A-E}if(H0){D[I.name]=I.value}if(I.type==="file"){N=true}}E=G.find("textarea");for(L=0,F=E.length;L0){D.body=I.value}}B=G.find("select");for(K=0,C=B.length;K0){D[I.name]=J}}A.responseContentType=$("div select[name=responseContentType]",$(this.el)).val();A.requestContentType=$("div select[name=parameterContentType]",$(this.el)).val();$(".response_throbber",$(this.el)).show();if(N){return this.handleFileUpload(D,G)}else{return this.model["do"](D,A,this.showCompleteStatus,this.showErrorStatus,this)}}};y.prototype.success=function(A,B){return B.showCompleteStatus(A)};y.prototype.handleFileUpload=function(R,I){var M,H,C,N,L,K,P,J,G,F,D,Q,U,T,S,E,B,A,V,O=this;E=I.serializeArray();for(J=0,Q=E.length;J0){R[N.name]=N.value}}M=new FormData();P=0;B=this.model.parameters;for(G=0,U=B.length;G
");$(".request_url pre",$(this.el)).text(this.invocationUrl);L={type:this.model.method,url:this.invocationUrl,headers:C,data:M,dataType:"json",contentType:false,processData:false,error:function(X,Y,W){return O.showErrorStatus(O.wrap(X),O)},success:function(W){return O.showResponse(W,O)},complete:function(W){return O.showCompleteStatus(O.wrap(W),O)}};if(window.authorizations){window.authorizations.apply(L)}if(P===0){L.data.append("fake","true")}jQuery.ajax(L);return false};y.prototype.wrap=function(E){var C,F,H,B,G,D,A;H={};F=E.getAllResponseHeaders().split("\r");for(D=0,A=F.length;D0){return C.join(",")}else{return null}}};y.prototype.hideResponse=function(A){if(A!=null){A.preventDefault()}$(".response",$(this.el)).slideUp();return $(".response_hider",$(this.el)).fadeOut()};y.prototype.showResponse=function(A){var B;B=JSON.stringify(A,null,"\t").replace(/\n/g,"
");return $(".response_body",$(this.el)).html(escape(B))};y.prototype.showErrorStatus=function(B,A){return A.showStatus(B)};y.prototype.showCompleteStatus=function(B,A){return A.showStatus(B)};y.prototype.formatXml=function(H){var D,G,B,I,N,J,C,A,L,M,F,E,K;A=/(>)(<)(\/*)/g;M=/[ ]*(.*)[ ]+\n/g;D=/(<.+>)(.+\n)/g;H=H.replace(A,"$1\n$2$3").replace(M,"$1\n").replace(D,"$1\n$2");C=0;G="";N=H.split("\n");B=0;I="other";L={"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};F=function(T){var P,O,R,V,S,Q,U;Q={single:Boolean(T.match(/<.+\/>/)),closing:Boolean(T.match(/<\/.+>/)),opening:Boolean(T.match(/<[^!?].*>/))};S=((function(){var W;W=[];for(R in Q){U=Q[R];if(U){W.push(R)}}return W})())[0];S=S===void 0?"other":S;P=I+"->"+S;I=S;V="";B+=L[P];V=((function(){var X,Y,W;W=[];for(O=X=0,Y=B;0<=Y?XY;O=0<=Y?++X:--X){W.push(" ")}return W})()).join("");if(P==="opening->closing"){return G=G.substr(0,G.length-1)+T+"\n"}else{return G+=V+T+"\n"}};for(E=0,K=N.length;E").text("no content");E=$('
').append(C)}else{if(J==="application/json"||/\+json$/.test(J)){C=$("").text(JSON.stringify(JSON.parse(H),null,"  "));E=$('
').append(C)}else{if(J==="application/xml"||/\+xml$/.test(J)){C=$("").text(this.formatXml(H));E=$('
').append(C)}else{if(J==="text/html"){C=$("").html(H);E=$('
').append(C)}else{if(/^image\//.test(J)){E=$("").attr("src",B)}else{C=$("").text(H);E=$('
').append(C)}}}}}I=E;$(".request_url",$(this.el)).html("
");$(".request_url pre",$(this.el)).text(B);$(".response_code",$(this.el)).html("
"+F.status+"
");$(".response_body",$(this.el)).html(I);$(".response_headers",$(this.el)).html("
"+_.escape(JSON.stringify(F.headers,null,"  ")).replace(/\n/g,"
")+"
");$(".response",$(this.el)).slideDown();$(".response_hider",$(this.el)).show();$(".response_throbber",$(this.el)).hide();G=$(".response_body",$(this.el))[0];A=this.options.swaggerOptions;if(A.highlightSizeThreshold&&F.data.length>A.highlightSizeThreshold){return G}else{return hljs.highlightBlock(G)}};y.prototype.toggleOperationContent=function(){var A;A=$("#"+Docs.escapeResourceName(this.model.parentId)+"_"+this.model.nickname+"_content");if(A.is(":visible")){return Docs.collapseOperation(A)}else{return Docs.expandOperation(A)}};return y})(Backbone.View);p=(function(z){v(y,z);function y(){d=y.__super__.constructor.apply(this,arguments);return d}y.prototype.initialize=function(){};y.prototype.render=function(){var B,A,C;C=this.template();$(this.el).html(C(this.model));if(swaggerUi.api.models.hasOwnProperty(this.model.responseModel)){B={sampleJSON:JSON.stringify(swaggerUi.api.models[this.model.responseModel].createJSONSample(),null,2),isParam:false,signature:swaggerUi.api.models[this.model.responseModel].getMockSignature()};A=new i({model:B,tagName:"div"});$(".model-signature",this.$el).append(A.render().el)}else{$(".model-signature",this.$el).html("")}return this};y.prototype.template=function(){return Handlebars.templates.status_code};return y})(Backbone.View);k=(function(z){v(y,z);function y(){b=y.__super__.constructor.apply(this,arguments);return b}y.prototype.initialize=function(){return Handlebars.registerHelper("isArray",function(B,A){if(B.type.toLowerCase()==="array"||B.allowMultiple){return A.fn(this)}else{return A.inverse(this)}})};y.prototype.render=function(){var A,B,E,C,F,D,I,J,H,G;G=this.model.type||this.model.dataType;if(typeof G==="undefined"){D=this.model.schema;if(D["$ref"]){C=D["$ref"];if(C.indexOf("#/definitions/")===0){G=C.substring("#/definitions/".length)}else{G=C}}}this.model.type=G;this.model.paramType=this.model["in"]||this.model.paramType;if(this.model.paramType==="body"){this.model.isBody=true}if(G&&G.toLowerCase()==="file"){this.model.isFile=true}H=this.template();$(this.el).html(H(this.model));I={sampleJSON:this.model.sampleJSON,isParam:true,signature:this.model.signature};if(this.model.sampleJSON){J=new i({model:I,tagName:"div"});$(".model-signature",$(this.el)).append(J.render().el)}else{$(".model-signature",$(this.el)).html(this.model.signature)}B=false;if(this.model.isBody){B=true}A={isParam:B};A.consumes=this.model.consumes;if(B){E=new l({model:A});$(".parameter-content-type",$(this.el)).append(E.render().el)}else{F=new m({model:A});$(".response-content-type",$(this.el)).append(F.render().el)}return this};y.prototype.template=function(){if(this.model.isList){return Handlebars.templates.param_list}else{if(this.options.readOnly){if(this.model.required){return Handlebars.templates.param_readonly_required}else{return Handlebars.templates.param_readonly}}else{if(this.model.required){return Handlebars.templates.param_required}else{return Handlebars.templates.param}}}};return y})(Backbone.View);i=(function(z){v(y,z);function y(){a=y.__super__.constructor.apply(this,arguments);return a}y.prototype.events={"click a.description-link":"switchToDescription","click a.snippet-link":"switchToSnippet","mousedown .snippet":"snippetToTextArea"};y.prototype.initialize=function(){};y.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));this.switchToSnippet();this.isParam=this.model.isParam;if(this.isParam){$(".notice",$(this.el)).text("Click to set as parameter value")}return this};y.prototype.template=function(){return Handlebars.templates.signature};y.prototype.switchToDescription=function(A){if(A!=null){A.preventDefault()}$(".snippet",$(this.el)).hide();$(".description",$(this.el)).show();$(".description-link",$(this.el)).addClass("selected");return $(".snippet-link",$(this.el)).removeClass("selected")};y.prototype.switchToSnippet=function(A){if(A!=null){A.preventDefault()}$(".description",$(this.el)).hide();$(".snippet",$(this.el)).show();$(".snippet-link",$(this.el)).addClass("selected");return $(".description-link",$(this.el)).removeClass("selected")};y.prototype.snippetToTextArea=function(A){var B;if(this.isParam){if(A!=null){A.preventDefault()}B=$("textarea",$(this.el.parentNode.parentNode.parentNode));if($.trim(B.val())===""){return B.val(this.model.sampleJSON)}}};return y})(Backbone.View);j=(function(y){v(z,y);function z(){x=z.__super__.constructor.apply(this,arguments);return x}z.prototype.initialize=function(){};z.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));$("label[for=contentType]",$(this.el)).text("Response Content Type");return this};z.prototype.template=function(){return Handlebars.templates.content_type};return z})(Backbone.View);m=(function(y){v(z,y);function z(){w=z.__super__.constructor.apply(this,arguments);return w}z.prototype.initialize=function(){};z.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));$("label[for=responseContentType]",$(this.el)).text("Response Content Type");return this};z.prototype.template=function(){return Handlebars.templates.response_content_type};return z})(Backbone.View);l=(function(z){v(y,z);function y(){c=y.__super__.constructor.apply(this,arguments);return c}y.prototype.initialize=function(){};y.prototype.render=function(){var A;A=this.template();$(this.el).html(A(this.model));$("label[for=parameterContentType]",$(this.el)).text("Parameter content type:");return this};y.prototype.template=function(){return Handlebars.templates.parameter_content_type};return y})(Backbone.View)}).call(this); \ No newline at end of file diff --git a/lib/swagger-client.js b/lib/swagger-client.js new file mode 100644 index 00000000..0f87c1de --- /dev/null +++ b/lib/swagger-client.js @@ -0,0 +1,1321 @@ +// swagger-client.js +// version 2.1.0 + +/** + * SwaggerAuthorizations applys the correct authorization to an operation being executed + */ +var SwaggerAuthorizations = function() { + this.authz = {}; +}; + +SwaggerAuthorizations.prototype.add = function(name, auth) { + this.authz[name] = auth; + return auth; +}; + +SwaggerAuthorizations.prototype.remove = function(name) { + return delete this.authz[name]; +}; + +SwaggerAuthorizations.prototype.apply = function(obj, authorizations) { + var status = null; + var key; + + // if the "authorizations" key is undefined, or has an empty array, add all keys + if(typeof authorizations === 'undefined' || Object.keys(authorizations).length == 0) { + for (key in this.authz) { + value = this.authz[key]; + result = value.apply(obj, authorizations); + if (result === true) + status = true; + } + } + else { + for(name in authorizations) { + for (key in this.authz) { + if(key == name) { + value = this.authz[key]; + result = value.apply(obj, authorizations); + if (result === true) + status = true; + } + } + } + } + + return status; +}; + +/** + * ApiKeyAuthorization allows a query param or header to be injected + */ +var ApiKeyAuthorization = function(name, value, type) { + this.name = name; + this.value = value; + this.type = type; +}; + +ApiKeyAuthorization.prototype.apply = function(obj, authorizations) { + if (this.type === "query") { + if (obj.url.indexOf('?') > 0) + obj.url = obj.url + "&" + this.name + "=" + this.value; + else + obj.url = obj.url + "?" + this.name + "=" + this.value; + return true; + } else if (this.type === "header") { + obj.headers[this.name] = this.value; + return true; + } +}; + +var CookieAuthorization = function(cookie) { + this.cookie = cookie; +} + +CookieAuthorization.prototype.apply = function(obj, authorizations) { + obj.cookieJar = obj.cookieJar || CookieJar(); + obj.cookieJar.setCookie(this.cookie); + return true; +} + +/** + * Password Authorization is a basic auth implementation + */ +var PasswordAuthorization = function(name, username, password) { + this.name = name; + this.username = username; + this.password = password; + this._btoa = null; + if (typeof window !== 'undefined') + this._btoa = btoa; + else + this._btoa = require("btoa"); +}; + +PasswordAuthorization.prototype.apply = function(obj, authorizations) { + var base64encoder = this._btoa; + obj.headers["Authorization"] = "Basic " + base64encoder(this.username + ":" + this.password); + return true; +};var __bind = function(fn, me){ + return function(){ + return fn.apply(me, arguments); + }; +}; + +fail = function(message) { + log(message); +} + +log = function(){ + log.history = log.history || []; + log.history.push(arguments); + if(this.console){ + console.log( Array.prototype.slice.call(arguments)[0] ); + } +}; + +if (!Array.prototype.indexOf) { + Array.prototype.indexOf = function(obj, start) { + for (var i = (start || 0), j = this.length; i < j; i++) { + if (this[i] === obj) { return i; } + } + return -1; + } +} + +if (!('filter' in Array.prototype)) { + Array.prototype.filter= function(filter, that /*opt*/) { + var other= [], v; + for (var i=0, n= this.length; i 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.label = tag; + operationGroup.apis = []; + this[tag].help = this.help.bind(operationGroup); + this.apisArray.push(new OperationGroup(tag, operation)); + } + operationGroup[operationId] = operation.execute.bind(operation); + operationGroup[operationId].help = operation.help.bind(operation); + operationGroup.apis.push(operation); + + // legacy UI feature + var j; + var api = null; + for(j = 0; j < this.apisArray.length; j++) { + if(this.apisArray[j].tag === tag) { + api = this.apisArray[j]; + } + } + if(api) { + api.operationsArray.push(operation); + } + } + } + else { + log('no group to bind to'); + } + } + } + this.isBuilt = true; + if (this.success) + this.success(); + return this; +} + +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) { + if(typeof op.operationId !== 'undefined') { + return (op.operationId); + } + else { + return path.substring(1).replace(/\//g, "_").replace(/\{/g, "").replace(/\}/g, "") + "_" + httpMethod; + } +} + +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 = []; + this.operation = args; + this.consumes = args.consumes; + this.produces = args.produces; + this.parent = parent; + this.host = parent.host; + this.schemes = parent.schemes; + 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 ' + nickname + ' is missing path.')); + this.parameters = args != null ? (args.parameters||[]) : {}; + this.summary = args.summary || ''; + this.responses = (args.responses||{}); + this.type = null; + + // this.authorizations = authorizations; + + var i; + for(i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + type = this.getType(param); + + param.signature = this.getSignature(type, models); + param.sampleJSON = this.getSampleJSON(type, models); + param.responseClassSignature = param.signature; + } + + var response; + var model; + var responses = this.responses; + + if(responses['200']) + response = responses['200']; + else if(responses['default']) + response = responses['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(); + } + else { + this.type = response.schema.type; + } + } + // else + // this.responseClassSignature = ''; + + if (errors.length > 0) + 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 === '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 === '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; + // return new PrimitiveModel(schema); + // else + + // var ref = schema.items['$ref']; + // if(ref.indexOf('#/definitions/') === 0) + // ref = ref.substring('#/definitions/'.length); + // return new Model('name', models[ref]); + // } + // else + // return new Model('name', schema); +} + +Operation.prototype.help = function() { + log(this.nickname + ': ' + this.operation.summary); + for(var i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + log(' * ' + param.name + ': ' + param.description); + } +} + +Operation.prototype.getSignature = function(type, models) { + var isPrimitive, listType; + + if(type instanceof Array) { + listType = true; + type = type[0]; + } + + // listType = this.isListType(type); + if(type === 'string') + isPrimitive = true + else + isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true; + if (isPrimitive) { + return type; + } else { + if (listType != null) { + return models[type].getMockSignature(); + } else { + return models[type].getMockSignature(); + } + } +}; + +Operation.prototype.getSampleJSON = function(type, models) { + var isPrimitive, listType, sampleJson; + + listType = (type instanceof Array); + isPrimitive = (models[type] != null) ? 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 support +Operation.prototype["do"] = function(args, opts, callback, error, parent) { + return this.execute(args, opts, callback, error, parent); +} + +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; + } + + var formParams = {}; + var headers = {}; + var requestUrl = this.path; + + success = (success||log) + error = (error||log) + + var requiredParams = []; + var missingParams = []; + // check required params + for(var i = 0; i < this.parameters.length; i++) { + var param = this.parameters[i]; + if(param.required === true) { + requiredParams.push(param.name); + if(typeof args[param.name] === 'undefined') + missingParams = param.name; + } + } + + if(missingParams.length > 0) { + var message = 'missing required params: ' + missingParams; + fail(message); + return; + } + + // set content type negotiation + var consumes = this.consumes || this.parent.consumes || [ 'application/json' ]; + var produces = this.produces || this.parent.produces || [ 'application/json' ]; + + headers = this.setContentTypes(args, opts); + + // 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'); + requestUrl = requestUrl.replace(reg, this.encodePathParam(args[param.name])); + } + else if (param.in === 'query') { + if(querystring === '') + querystring += '?'; + if(typeof param.collectionFormat !== 'undefined') { + var qp = args[param.name]; + if(Array.isArray(qp)) + querystring += this.encodeCollection(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 === 'header') + headers[param.name] = args[param.name]; + else if (param.in === 'form') + formParams[param.name] = args[param.name]; + } + } + var scheme = this.schemes[0]; + var url = scheme + '://' + this.host + this.basePath + requestUrl + querystring; + + var obj = { + url: url, + method: args.method, + useJQuery: this.useJQuery, + headers: headers, + on: { + response: function(response) { + return success(response, parent); + }, + error: function(response) { + return error(response, parent); + } + } + }; + new SwaggerHttp().execute(obj); +} + +Operation.prototype.setContentTypes = function(args, opts) { + // default type + var accepts = 'application/json'; + var consumes = 'application/json'; + + var allDefinedParams = this.parameters; + var definedFormParams = []; + var definedFileParams = []; + var body = args.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 === 'form') + definedFormParams.push(param); + else if(param.in === 'file') + definedFileParams.push(param); + else if(param.in === 'header' && this.params.headers) { + var key = param.name; + var headerValue = this.params.headers[param.name]; + if(typeof this.params.headers[param.name] !== 'undefined') + headers[key] = headerValue; + } + } + + // if there's a body, need to set the accepts header via requestContentType + if (body && (this.type === 'post' || this.type === 'put' || this.type === 'patch' || this.type === 'delete')) { + if (opts.requestContentType) + consumes = opts.requestContentType; + } else { + // if any form params, content type must be set + if(definedFormParams.length > 0) { + if(definedFileParams.length > 0) + consumes = 'multipart/form-data'; + else + consumes = 'application/x-www-form-urlencoded'; + } + else if (this.type == 'DELETE') + body = '{}'; + else if (this.type != 'DELETE') + accepts = null; + } + + if (consumes && this.consumes) { + if (this.consumes.indexOf(consumes) === -1) { + log('server doesn\'t consume ' + consumes + ', try ' + JSON.stringify(this.consumes)); + consumes = this.operation.consumes[0]; + } + } + + 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); + accepts = this.produces[0]; + } + } + + if ((consumes && body !== '') || (consumes === 'application/x-www-form-urlencoded')) + headers['Content-Type'] = consumes; + if (accepts) + headers['Accept'] = accepts; + return headers; +} + +Operation.prototype.encodeCollection = function(type, name, value) { + var encoded = ''; + var i; + if(type === 'jaxrs') { + for(i = 0; i < value.length; i++) { + if(i > 0) encoded += '&' + encoded += this.encodeQueryParam(name) + '=' + this.encodeQueryParam(value[i]); + } + } + return encoded; +} + +Operation.prototype.encodeQueryParam = function(arg) { + return escape(arg); +} + +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++) { + part = parts[_i]; + encParts.push(encodeURIComponent(part)); + } + return encParts.join('/'); + } +}; + +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++) { + part = parts[_i]; + encParts.push(encodeURIComponent(part)); + } + return encParts.join('/'); + } +}; + +var ArrayModel = function(definition) { + this.name = "name"; + this.definition = definition || {}; + this.properties = []; + this.type; + this.ref; + + var requiredFields = definition.enum || []; + var items = definition.items; + if(items) { + var type = items.type; + if(items.type) { + this.type = typeFromJsonSchema(type.type, type.format); + } + else { + this.ref = items['$ref']; + } + } +} + +ArrayModel.prototype.createJSONSample = function(modelsToIgnore) { + var result; + var modelsToIgnore = (modelsToIgnore||[]) + if(this.type) { + result = type; + } + else if (this.ref) { + var name = simpleRef(this.ref); + result = models[name].createJSONSample(); + } + return [ result ]; +}; + +ArrayModel.prototype.getSampleValue = function() { + var result; + var modelsToIgnore = (modelsToIgnore||[]) + if(this.type) { + result = type; + } + else if (this.ref) { + var name = simpleRef(this.ref); + result = models[name].getSampleValue(); + } + return [ result ]; +} + +ArrayModel.prototype.getMockSignature = function(modelsToIgnore) { + var propertiesStr = []; + + if(this.ref) { + return models[simpleRef(this.ref)].getMockSignature(); + } +}; + + +var PrimitiveModel = function(definition) { + this.name = "name"; + this.definition = definition || {}; + this.properties = []; + this.type; + + var requiredFields = definition.enum || []; + this.type = typeFromJsonSchema(definition.type, definition.format); +} + +PrimitiveModel.prototype.createJSONSample = function(modelsToIgnore) { + var result = this.type; + return result; +}; + +PrimitiveModel.prototype.getSampleValue = function() { + var result = this.type; + return null; +} + +PrimitiveModel.prototype.getMockSignature = function(modelsToIgnore) { + var propertiesStr = []; + var i; + for (i = 0; i < this.properties.length; i++) { + var 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.push(this.name); + var i; + for (i = 0; i < this.properties.length; i++) { + var prop = this.properties[i]; + var ref = prop['$ref']; + var model = models[ref]; + if (model && modelsToIgnore.indexOf(ref) === -1) { + returnVal = returnVal + ('
' + model.getMockSignature(modelsToIgnore)); + } + } + return returnVal; +}; + +var Model = function(name, definition) { + this.name = name; + this.definition = definition || {}; + this.properties = []; + var requiredFields = definition.enum || []; + + 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 = {}; + var modelsToIgnore = (modelsToIgnore||[]) + modelsToIgnore.push(this.name); + for (var i = 0; i < this.properties.length; i++) { + prop = this.properties[i]; + result[prop.name] = prop.getSampleValue(modelsToIgnore); + } + modelsToIgnore.pop(this.name); + return result; +}; + +Model.prototype.getSampleValue = function() { + var i; + var obj = {}; + for(i = 0; i < this.properties.length; i++ ) { + var property = this.properties[i]; + obj[property.name] = property.sampleValue(); + } + return obj; +} + +Model.prototype.getMockSignature = function(modelsToIgnore) { + var propertiesStr = []; + var i; + for (i = 0; i < this.properties.length; i++) { + var 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.push(this.name); + var i; + for (i = 0; i < this.properties.length; i++) { + var prop = this.properties[i]; + var ref = prop['$ref']; + var model = models[ref]; + if (model && modelsToIgnore.indexOf(ref) === -1) { + returnVal = returnVal + ('
' + model.getMockSignature(modelsToIgnore)); + } + } + return returnVal; +}; + +var Property = function(name, obj, required) { + this.schema = obj; + this.required = required; + if(obj['$ref']) { + var refType = obj['$ref']; + refType = refType.indexOf('#/definitions') === -1 ? refType : refType.substring('#/definitions').length; + this['$ref'] = refType; + } + else if (obj.type === 'array') { + if(obj.items['$ref']) + this['$ref'] = obj.items['$ref']; + else + obj = obj.items; + } + this.name = name; + this.obj = obj; + this.optional = true; + this.example = obj.example || null; +} + +Property.prototype.getSampleValue = function () { + return this.sampleValue(false); +} + +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 refModel = models[this['$ref']]; + if(refModel && typeof ignoredModels[refModel] === 'undefined') { + output = refModel.getSampleValue(ignoredModels); + } + else + type = refModel; + } + else if(this.example) + output = this.example; + 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 = {}; + if(isArray) return [output]; + else return output; +} + +getStringSignature = function(obj) { + var str = ''; + if(obj.type === 'array') { + obj = (obj.items || obj['$ref'] || {}); + str += 'Array['; + } + if(obj.type === 'integer' && obj.format === 'int32') + str += 'integer'; + else if(obj.type === 'integer' && obj.format === 'int64') + 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 === 'number' && obj.format === 'float') + str += 'float'; + else if(obj.type === 'number' && obj.format === 'double') + str += 'double'; + else if(obj.type === 'boolean') + str += 'boolean'; + else + str += obj.type || obj['$ref']; + if(obj.type === 'array') + str += ']'; + return str; +} + +simpleRef = function(name) { + 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; + else + str = this.name + ' : ' + JSON.stringify(this.obj); + if(!this.required) + str += ' (optional)'; + return str; +} + +typeFromJsonSchema = function(type, format) { + var str; + if(type === 'integer' && format === 'int32') + str = 'integer'; + else if(type === 'integer' && format === 'int64') + 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 === 'boolean') + str = 'boolean'; + else if(type === 'string') + str = 'string'; + + return str; +} + +var e = (typeof window !== 'undefined' ? window : exports); + +var sampleModels = {}; +var cookies = {}; +var models = {}; + +e.authorizations = new SwaggerAuthorizations(); +e.ApiKeyAuthorization = ApiKeyAuthorization; +e.PasswordAuthorization = PasswordAuthorization; +e.CookieAuthorization = CookieAuthorization; +e.SwaggerClient = SwaggerClient;/** + * SwaggerHttp is a wrapper for executing requests + */ +var SwaggerHttp = function() {}; + +SwaggerHttp.prototype.execute = function(obj) { + if(obj && (typeof obj.useJQuery === 'boolean')) + this.useJQuery = obj.useJQuery; + else + this.useJQuery = this.isIE8(); + + if(this.useJQuery) + return new JQueryHttpClient().execute(obj); + else + return new ShredHttpClient().execute(obj); +} + +SwaggerHttp.prototype.isIE8 = function() { + var detectedIE = false; + if (typeof navigator !== 'undefined' && navigator.userAgent) { + nav = navigator.userAgent.toLowerCase(); + if (nav.indexOf('msie') !== -1) { + var version = parseInt(nav.split('msie')[1]); + if (version <= 8) { + detectedIE = true; + } + } + } + return detectedIE; +}; + +/* + * JQueryHttpClient lets a browser take advantage of JQuery's cross-browser magic. + * NOTE: when jQuery is available it will export both '$' and 'jQuery' to the global space. + * Since we are using closures here we need to alias it for internal use. + */ +var JQueryHttpClient = function(options) { + "use strict"; + if(!jQuery){ + var jQuery = window.jQuery; + } +} + +JQueryHttpClient.prototype.execute = function(obj) { + var cb = obj.on; + var request = obj; + + obj.type = obj.method; + obj.cache = false; + + obj.beforeSend = function(xhr) { + var key, results; + if (obj.headers) { + results = []; + var key; + for (key in obj.headers) { + if (key.toLowerCase() === "content-type") { + results.push(obj.contentType = obj.headers[key]); + } else if (key.toLowerCase() === "accept") { + results.push(obj.accepts = obj.headers[key]); + } else { + results.push(xhr.setRequestHeader(key, obj.headers[key])); + } + } + return results; + } + }; + + obj.data = obj.body; + obj.complete = function(response, textStatus, opts) { + var headers = {}, + headerArray = response.getAllResponseHeaders().split("\n"); + + for(var i = 0; i < headerArray.length; i++) { + var toSplit = headerArray[i].trim(); + if(toSplit.length === 0) + continue; + var separator = toSplit.indexOf(":"); + if(separator === -1) { + // Name but no value in the header + headers[toSplit] = null; + continue; + } + var name = toSplit.substring(0, separator).trim(), + value = toSplit.substring(separator + 1).trim(); + headers[name] = value; + } + + var out = { + url: request.url, + method: request.method, + status: response.status, + data: response.responseText, + headers: headers + }; + + var contentType = (headers["content-type"]||headers["Content-Type"]||null) + + if(contentType != null) { + if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) { + if(response.responseText && response.responseText !== "") + out.obj = JSON.parse(response.responseText); + else + out.obj = {} + } + } + + if(response.status >= 200 && response.status < 300) + cb.response(out); + else if(response.status === 0 || (response.status >= 400 && response.status < 599)) + cb.error(out); + else + return cb.response(out); + }; + + jQuery.support.cors = true; + return jQuery.ajax(obj); +} + +/* + * ShredHttpClient is a light-weight, node or browser HTTP client + */ +var ShredHttpClient = function(options) { + this.options = (options||{}); + this.isInitialized = false; + + var identity, toString; + + if (typeof window !== 'undefined') { + this.Shred = require("./shred"); + this.content = require("./shred/content"); + } + else + this.Shred = require("shred"); + this.shred = new this.Shred(); +} + +ShredHttpClient.prototype.initShred = function () { + this.isInitialized = true; + this.registerProcessors(this.shred); +} + +ShredHttpClient.prototype.registerProcessors = function(shred) { + var identity = function(x) { + return x; + }; + var toString = function(x) { + return x.toString(); + }; + + if (typeof window !== 'undefined') { + this.content.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], { + parser: identity, + stringify: toString + }); + } else { + this.Shred.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], { + parser: identity, + stringify: toString + }); + } +} + +ShredHttpClient.prototype.execute = function(obj) { + if(!this.isInitialized) + this.initShred(); + + var cb = obj.on, res; + + var transform = function(response) { + var out = { + headers: response._headers, + url: response.request.url, + method: response.request.method, + status: response.status, + data: response.content.data + }; + + var contentType = (response._headers["content-type"]||response._headers["Content-Type"]||null) + + if(contentType != null) { + if(contentType.indexOf("application/json") == 0 || contentType.indexOf("+json") > 0) { + if(response.content.data && response.content.data !== "") + out.obj = JSON.parse(response.content.data); + else + out.obj = {} + } + } + return out; + }; + + res = { + error: function(response) { + if (obj) + return cb.error(transform(response)); + }, + redirect: function(response) { + if (obj) + return cb.redirect(transform(response)); + }, + 307: function(response) { + if (obj) + return cb.redirect(transform(response)); + }, + response: function(response) { + if (obj) + return cb.response(transform(response)); + } + }; + if (obj) { + obj.on = res; + } + return this.shred.request(obj); +}; \ No newline at end of file diff --git a/src/main/coffeescript/SwaggerUi.coffee b/src/main/coffeescript/SwaggerUi.coffee index 909cd6d7..f327941b 100644 --- a/src/main/coffeescript/SwaggerUi.coffee +++ b/src/main/coffeescript/SwaggerUi.coffee @@ -47,9 +47,16 @@ class SwaggerUi extends Backbone.Router @options.url = url @headerView.update(url) - @api = new SwaggerApi(@options) - @api.build() - @api + + if url.indexOf('swagger.json') > 0 + @api = new SwaggerClient(@options) + @api.build() + @api + else + @api = new SwaggerApi(@options) + @api.build() + @api + # This is bound to success handler for SwaggerApi # so it gets called when SwaggerApi completes loading diff --git a/src/main/coffeescript/view/MainView.coffee b/src/main/coffeescript/view/MainView.coffee index 8bab9683..2a0a33bd 100644 --- a/src/main/coffeescript/view/MainView.coffee +++ b/src/main/coffeescript/view/MainView.coffee @@ -8,10 +8,11 @@ class MainView extends Backbone.View if opts.swaggerOptions.sorter sorterName = opts.swaggerOptions.sorter sorter = sorters[sorterName] - for route in @model.apisArray - route.operationsArray.sort sorter - if (sorterName == "alpha") # sort top level paths if alpha - @model.apisArray.sort sorter + if @model.apisArray + for route in @model.apisArray + route.operationsArray.sort sorter + if (sorterName == "alpha") # sort top level paths if alpha + @model.apisArray.sort sorter render: -> # Render the outer container for resources diff --git a/src/main/coffeescript/view/OperationView.coffee b/src/main/coffeescript/view/OperationView.coffee index 631b62e7..a12df679 100644 --- a/src/main/coffeescript/view/OperationView.coffee +++ b/src/main/coffeescript/view/OperationView.coffee @@ -44,6 +44,9 @@ class OperationView extends Backbone.View isMethodSubmissionSupported = true #jQuery.inArray(@model.method, @model.supportedSubmitMethods) >= 0 @model.isReadOnly = true unless isMethodSubmissionSupported + #@model.responseClassSignature = "hello" + #@model.responseSampleJSON = @model.createJSONSample + @model.oauth = null if @model.authorizations for k, v of @model.authorizations @@ -66,6 +69,7 @@ class OperationView extends Backbone.View responseSignatureView = new SignatureView({model: signatureModel, tagName: 'div'}) $('.model-signature', $(@el)).append responseSignatureView.render().el else + @model.responseClassSignature = 'string' $('.model-signature', $(@el)).html(@model.type) contentTypeModel = @@ -76,10 +80,18 @@ class OperationView extends Backbone.View for param in @model.parameters type = param.type || param.dataType - if type.toLowerCase() == 'file' + if typeof type is 'undefined' + schema = param.schema + if schema['$ref'] + ref = schema['$ref'] + if ref.indexOf('#/definitions/') is 0 + type = ref.substring('#/definitions/'.length) + else + type = ref + if type and type.toLowerCase() == 'file' if !contentTypeModel.consumes - log "set content type " contentTypeModel.consumes = 'multipart/form-data' + param.type = type responseContentTypeView = new ResponseContentTypeView({model: contentTypeModel}) $('.response-content-type', $(@el)).append responseContentTypeView.render().el @@ -88,6 +100,8 @@ class OperationView extends Backbone.View @addParameter param, contentTypeModel.consumes for param in @model.parameters # Render each response code + if typeof @model.responseMessages is 'undefined' + @model.responseMessages = [] @addStatusCode statusCode for statusCode in @model.responseMessages @ @@ -171,8 +185,6 @@ class OperationView extends Backbone.View if param.paramType is 'header' headerParams[param.name] = map[param.name] - log headerParams - # add files for el in form.find('input[type~="file"]') if typeof el.files[0] isnt 'undefined' diff --git a/src/main/coffeescript/view/ParameterView.coffee b/src/main/coffeescript/view/ParameterView.coffee index 281f0877..957d4f36 100644 --- a/src/main/coffeescript/view/ParameterView.coffee +++ b/src/main/coffeescript/view/ParameterView.coffee @@ -9,8 +9,21 @@ class ParameterView extends Backbone.View render: -> type = @model.type || @model.dataType + + if typeof type is 'undefined' + schema = @model.schema + if schema['$ref'] + ref = schema['$ref'] + if ref.indexOf('#/definitions/') is 0 + type = ref.substring('#/definitions/'.length) + else + type = ref + + @model.type = type + @model.paramType = @model.in || @model.paramType @model.isBody = true if @model.paramType == 'body' - @model.isFile = true if type.toLowerCase() == 'file' + @model.isFile = true if type and type.toLowerCase() == 'file' + #@model.signature = type template = @template() $(@el).html(template(@model)) diff --git a/src/main/coffeescript/view/ResourceView.coffee b/src/main/coffeescript/view/ResourceView.coffee index 5145362a..56d6e68f 100644 --- a/src/main/coffeescript/view/ResourceView.coffee +++ b/src/main/coffeescript/view/ResourceView.coffee @@ -1,5 +1,7 @@ class ResourceView extends Backbone.View initialize: -> + if "" is @model.description + @model.description = null render: -> $(@el).html(Handlebars.templates.resource(@model)) diff --git a/src/main/javascript/doc.js b/src/main/javascript/doc.js index 71fa60a3..0746d7b9 100644 --- a/src/main/javascript/doc.js +++ b/src/main/javascript/doc.js @@ -91,7 +91,6 @@ var Docs = { switch (fragments.length) { case 1: // Expand all operations for the resource and scroll to it - log('shebang resource:' + fragments[0]); var dom_id = 'resource_' + fragments[0]; Docs.expandEndpointListForResource(fragments[0]); @@ -99,7 +98,6 @@ var Docs = { break; case 2: // Refer to the endpoint DOM element, e.g. #words_get_search - log('shebang endpoint: ' + fragments.join('_')); // Expand Resource Docs.expandEndpointListForResource(fragments[0]); @@ -109,8 +107,6 @@ var Docs = { var li_dom_id = fragments.join('_'); var li_content_dom_id = li_dom_id + "_content"; - log("li_dom_id " + li_dom_id); - log("li_content_dom_id " + li_content_dom_id); Docs.expandOperation($('#'+li_content_dom_id)); $('#'+li_dom_id).slideto({highlight: false}); diff --git a/src/main/template/resource.handlebars b/src/main/template/resource.handlebars index f763af42..e02db471 100644 --- a/src/main/template/resource.handlebars +++ b/src/main/template/resource.handlebars @@ -1,6 +1,6 @@

- {{name}} {{#description}} : {{/description}}{{{description}}} + /{{name}} {{#description}} : {{/description}}{{{description}}}