diff --git a/lib/swagger.js b/lib/swagger.js new file mode 100644 index 00000000..177a109d --- /dev/null +++ b/lib/swagger.js @@ -0,0 +1,1006 @@ +// Generated by CoffeeScript 1.4.0 +(function() { + var ApiKeyAuthorization, SwaggerApi, SwaggerAuthorizations, SwaggerHttp, SwaggerModel, SwaggerModelProperty, SwaggerOperation, SwaggerRequest, SwaggerResource, + __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; }; + + SwaggerApi = (function() { + + SwaggerApi.prototype.discoveryUrl = "http://api.wordnik.com/v4/resources.json"; + + SwaggerApi.prototype.debug = false; + + SwaggerApi.prototype.basePath = null; + + SwaggerApi.prototype.authorizations = null; + + SwaggerApi.prototype.authorizationScheme = null; + + function SwaggerApi(options) { + if (options == null) { + options = {}; + } + if (options.discoveryUrl != null) { + this.discoveryUrl = options.discoveryUrl; + } + this.supportedSubmitMethods = options.supportedSubmitMethods != null ? options.supportedSubmitMethods : ['get']; + if (options.success != null) { + this.success = options.success; + } + this.failure = options.failure != null ? options.failure : function() {}; + this.progress = options.progress != null ? options.progress : function() {}; + this.defaultHeaders = options.headers != null ? options.headers : {}; + if (options.success != null) { + this.build(); + } + } + + SwaggerApi.prototype.build = function() { + var obj, + _this = this; + this.progress('fetching resource list: ' + this.discoveryUrl); + obj = { + url: this.discoveryUrl, + method: "get", + on: { + error: function(response) { + if (_this.discoveryUrl.substring(0, 4) !== 'http') { + return _this.fail('Please specify the protocol for ' + _this.discoveryUrl); + } else if (error.status === 0) { + return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.'); + } else if (error.status === 404) { + return _this.fail('Can\'t read swagger JSON from ' + _this.discoveryUrl); + } else { + return _this.fail(error.status + ' : ' + error.statusText + ' ' + _this.discoveryUrl); + } + }, + response: function(rawResponse) { + var res, resource, response, _i, _len, _ref; + response = JSON.parse(rawResponse.content.data); + if (response.apiVersion != null) { + _this.apiVersion = response.apiVersion; + } + _this.apis = {}; + _this.apisArray = []; + if (response.basePath) { + _this.basePath = response.basePath; + } else if (_this.discoveryUrl.indexOf('?') > 0) { + _this.basePath = _this.discoveryUrl.substring(0, _this.discoveryUrl.lastIndexOf('?')); + } else { + _this.basePath = _this.discoveryUrl; + } + _ref = response.apis; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + resource = _ref[_i]; + res = new SwaggerResource(resource, _this); + _this.apis[res.name] = res; + _this.apisArray.push(res); + } + return _this; + } + } + }; + return new SwaggerHttp().execute(obj); + }; + + SwaggerApi.prototype.selfReflect = function() { + var resource, resource_name, _ref; + if (this.apis == null) { + return false; + } + _ref = this.apis; + for (resource_name in _ref) { + resource = _ref[resource_name]; + if (resource.ready == null) { + return false; + } + } + this.setConsolidatedModels(); + this.ready = true; + if (this.success != null) { + return this.success(); + } + }; + + SwaggerApi.prototype.fail = function(message) { + this.failure(message); + throw message; + }; + + SwaggerApi.prototype.setConsolidatedModels = function() { + var model, modelName, resource, resource_name, _i, _len, _ref, _ref1, _results; + this.modelsArray = []; + this.models = {}; + _ref = this.apis; + for (resource_name in _ref) { + resource = _ref[resource_name]; + for (modelName in resource.models) { + if (!(this.models[modelName] != null)) { + this.models[modelName] = resource.models[modelName]; + this.modelsArray.push(resource.models[modelName]); + } + } + } + _ref1 = this.modelsArray; + _results = []; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + model = _ref1[_i]; + _results.push(model.setReferencedModels(this.models)); + } + return _results; + }; + + SwaggerApi.prototype.help = function() { + var operation, operation_name, parameter, resource, resource_name, _i, _len, _ref, _ref1, _ref2; + _ref = this.apis; + for (resource_name in _ref) { + resource = _ref[resource_name]; + console.log(resource_name); + _ref1 = resource.operations; + for (operation_name in _ref1) { + operation = _ref1[operation_name]; + console.log(" " + operation.nickname); + _ref2 = operation.parameters; + for (_i = 0, _len = _ref2.length; _i < _len; _i++) { + parameter = _ref2[_i]; + console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description); + } + } + } + return this; + }; + + return SwaggerApi; + + })(); + + SwaggerResource = (function() { + + SwaggerResource.prototype.api = null; + + SwaggerResource.prototype.produces = null; + + SwaggerResource.prototype.consumes = null; + + function SwaggerResource(resourceObj, api) { + var consumes, obj, parts, produces, + _this = this; + this.api = api; + this.api = this.api; + produces = []; + consumes = []; + this.path = this.api.resourcePath != null ? this.api.resourcePath : resourceObj.path; + this.description = resourceObj.description; + parts = this.path.split("/"); + this.name = parts[parts.length - 1].replace('.{format}', ''); + this.basePath = this.api.basePath; + this.operations = {}; + this.operationsArray = []; + this.modelsArray = []; + this.models = {}; + if ((resourceObj.operations != null) && (this.api.resourcePath != null)) { + this.api.progress('reading resource ' + this.name + ' models and operations'); + this.addModels(resourceObj.models); + this.addOperations(resourceObj.path, resourceObj.operations); + this.api[this.name] = this; + } else { + if (this.path == null) { + this.api.fail("SwaggerResources must have a path."); + } + this.url = this.api.basePath + this.path.replace('{format}', 'json'); + this.api.progress('fetching resource ' + this.name + ': ' + this.url); + obj = { + url: this.url, + method: "get", + on: { + error: function(response) { + return _this.api.fail("Unable to read api '" + _this.name + "' from path " + _this.url + " (server returned " + error.statusText + ")"); + }, + response: function(rawResponse) { + var endpoint, response, _i, _len, _ref; + response = JSON.parse(rawResponse.content._body); + if (response.produces != null) { + _this.produces = response.produces; + } + if (response.consumes != null) { + _this.consumes = response.consumes; + } + if ((response.basePath != null) && response.basePath.replace(/\s/g, '').length > 0) { + _this.basePath = response.basePath; + } + _this.addModels(response.models); + if (response.apis) { + _ref = response.apis; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + endpoint = _ref[_i]; + _this.addOperations(endpoint.path, endpoint.operations); + } + } + _this.api[_this.name] = _this; + _this.ready = true; + return _this.api.selfReflect(); + } + } + }; + new SwaggerHttp().execute(obj); + } + } + + SwaggerResource.prototype.addModels = function(models) { + var model, modelName, swaggerModel, _i, _len, _ref, _results; + if (models != null) { + for (modelName in models) { + if (!(this.models[modelName] != null)) { + swaggerModel = new SwaggerModel(modelName, models[modelName]); + this.modelsArray.push(swaggerModel); + this.models[modelName] = swaggerModel; + } + } + _ref = this.modelsArray; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + model = _ref[_i]; + _results.push(model.setReferencedModels(this.models)); + } + return _results; + } + }; + + SwaggerResource.prototype.addOperations = function(resource_path, ops) { + var consumes, method, o, op, produces, responseMessages, _i, _len, _results; + if (ops) { + _results = []; + for (_i = 0, _len = ops.length; _i < _len; _i++) { + o = ops[_i]; + consumes = null; + produces = null; + if (o.consumes != null) { + consumes = o.consumes; + } else { + consumes = this.consumes; + } + if (o.produces != null) { + produces = o.produces; + } else { + produces = this.produces; + } + responseMessages = o.responseMessages; + method = o.method; + if (o.httpMethod) { + method = o.httpMethod; + } + if (o.supportedContentTypes) { + consumes = o.supportedContentTypes; + } + if (o.errorResponses) { + responseMessages = o.errorResponses; + } + op = new SwaggerOperation(o.nickname, resource_path, method, o.parameters, o.summary, o.notes, o.responseClass, responseMessages, this, consumes, produces); + this.operations[op.nickname] = op; + _results.push(this.operationsArray.push(op)); + } + return _results; + } + }; + + SwaggerResource.prototype.help = function() { + var msg, operation, operation_name, parameter, _i, _len, _ref, _ref1, _results; + _ref = this.operations; + _results = []; + for (operation_name in _ref) { + operation = _ref[operation_name]; + msg = " " + operation.nickname; + _ref1 = operation.parameters; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + parameter = _ref1[_i]; + msg.concat(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description); + } + _results.push(msg); + } + return _results; + }; + + return SwaggerResource; + + })(); + + SwaggerModel = (function() { + + function SwaggerModel(modelName, obj) { + var propertyName; + this.name = obj.id != null ? obj.id : modelName; + this.properties = []; + for (propertyName in obj.properties) { + this.properties.push(new SwaggerModelProperty(propertyName, obj.properties[propertyName])); + } + } + + SwaggerModel.prototype.setReferencedModels = function(allModels) { + var prop, _i, _len, _ref, _results; + _ref = this.properties; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + prop = _ref[_i]; + if (allModels[prop.dataType] != null) { + _results.push(prop.refModel = allModels[prop.dataType]); + } else if ((prop.refDataType != null) && (allModels[prop.refDataType] != null)) { + _results.push(prop.refModel = allModels[prop.refDataType]); + } else { + _results.push(void 0); + } + } + return _results; + }; + + SwaggerModel.prototype.getMockSignature = function(modelsToIgnore) { + var classClose, classOpen, prop, propertiesStr, returnVal, strong, strongClose, stronger, _i, _j, _len, _len1, _ref, _ref1; + propertiesStr = []; + _ref = this.properties; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + prop = _ref[_i]; + propertiesStr.push(prop.toString()); + } + strong = ''; + stronger = ''; + strongClose = ''; + classOpen = strong + this.name + ' {' + strongClose; + classClose = strong + '}' + strongClose; + returnVal = classOpen + '
' + propertiesStr.join(',
') + '
' + classClose; + if (!modelsToIgnore) { + modelsToIgnore = []; + } + modelsToIgnore.push(this); + _ref1 = this.properties; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + prop = _ref1[_j]; + if ((prop.refModel != null) && (modelsToIgnore.indexOf(prop.refModel)) === -1) { + returnVal = returnVal + ('
' + prop.refModel.getMockSignature(modelsToIgnore)); + } + } + return returnVal; + }; + + SwaggerModel.prototype.createJSONSample = function(modelsToIgnore) { + var prop, result, _i, _len, _ref; + result = {}; + modelsToIgnore = modelsToIgnore || []; + modelsToIgnore.push(this.name); + _ref = this.properties; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + prop = _ref[_i]; + result[prop.name] = prop.getSampleValue(modelsToIgnore); + } + return result; + }; + + return SwaggerModel; + + })(); + + SwaggerModelProperty = (function() { + + function SwaggerModelProperty(name, obj) { + this.name = name; + this.dataType = obj.type; + this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set'); + this.descr = obj.description; + this.required = obj.required; + if (obj.items != null) { + if (obj.items.type != null) { + this.refDataType = obj.items.type; + } + if (obj.items.$ref != null) { + this.refDataType = obj.items.$ref; + } + } + this.dataTypeWithRef = this.refDataType != null ? this.dataType + '[' + this.refDataType + ']' : this.dataType; + if (obj.allowableValues != null) { + this.valueType = obj.allowableValues.valueType; + this.values = obj.allowableValues.values; + if (this.values != null) { + this.valuesString = "'" + this.values.join("' or '") + "'"; + } + } + } + + SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) { + var result; + if ((this.refModel != null) && (modelsToIgnore.indexOf(this.refModel.name) === -1)) { + result = this.refModel.createJSONSample(modelsToIgnore); + } else { + if (this.isCollection) { + result = this.refDataType; + } else { + result = this.dataType; + } + } + if (this.isCollection) { + return [result]; + } else { + return result; + } + }; + + SwaggerModelProperty.prototype.toString = function() { + var req, str; + req = this.required ? 'propReq' : 'propOpt'; + str = '' + this.name + ' (' + this.dataTypeWithRef + ''; + if (!this.required) { + str += ', optional'; + } + str += ')'; + if (this.values != null) { + str += " = ['" + this.values.join("' or '") + "']"; + } + if (this.descr != null) { + str += ': ' + this.descr + ''; + } + return str; + }; + + return SwaggerModelProperty; + + })(); + + SwaggerOperation = (function() { + + function SwaggerOperation(nickname, path, method, parameters, summary, notes, responseClass, responseMessages, resource, consumes, produces) { + var parameter, v, _i, _j, _len, _len1, _ref, _ref1, _ref2, + _this = this; + this.nickname = nickname; + this.path = path; + this.method = method; + this.parameters = parameters != null ? parameters : []; + this.summary = summary; + this.notes = notes; + this.responseClass = responseClass; + this.responseMessages = responseMessages; + this.resource = resource; + this.consumes = consumes; + this.produces = produces; + this["do"] = __bind(this["do"], this); + + if (this.nickname == null) { + this.resource.api.fail("SwaggerOperations must have a nickname."); + } + if (this.path == null) { + this.resource.api.fail("SwaggerOperation " + nickname + " is missing path."); + } + if (this.method == null) { + this.resource.api.fail("SwaggerOperation " + nickname + " is missing method."); + } + this.path = this.path.replace('{format}', 'json'); + this.method = this.method.toLowerCase(); + this.isGetMethod = this.method === "get"; + this.resourceName = this.resource.name; + if (((_ref = this.responseClass) != null ? _ref.toLowerCase() : void 0) === 'void') { + this.responseClass = void 0; + } + if (this.responseClass != null) { + this.responseClassSignature = this.getSignature(this.responseClass, this.resource.models); + this.responseSampleJSON = this.getSampleJSON(this.responseClass, this.resource.models); + } + this.responseMessages = this.responseMessages || []; + _ref1 = this.parameters; + for (_i = 0, _len = _ref1.length; _i < _len; _i++) { + parameter = _ref1[_i]; + parameter.name = parameter.name || parameter.dataType; + if (parameter.dataType.toLowerCase() === 'boolean') { + parameter.allowableValues = {}; + parameter.allowableValues.values = this.resource.api.booleanValues; + } + parameter.signature = this.getSignature(parameter.dataType, this.resource.models); + parameter.sampleJSON = this.getSampleJSON(parameter.dataType, this.resource.models); + if (parameter.allowableValues != null) { + if (parameter.allowableValues.valueType === "RANGE") { + parameter.isRange = true; + } else { + parameter.isList = true; + } + if (parameter.allowableValues.values != null) { + parameter.allowableValues.descriptiveValues = []; + _ref2 = parameter.allowableValues.values; + for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) { + v = _ref2[_j]; + if ((parameter.defaultValue != null) && parameter.defaultValue === v) { + parameter.allowableValues.descriptiveValues.push({ + value: v, + isDefault: true + }); + } else { + parameter.allowableValues.descriptiveValues.push({ + value: v, + isDefault: false + }); + } + } + } + } + } + this.resource[this.nickname] = function(args, callback, error) { + return _this["do"](args, callback, error); + }; + } + + SwaggerOperation.prototype.isListType = function(dataType) { + if (dataType.indexOf('[') >= 0) { + return dataType.substring(dataType.indexOf('[') + 1, dataType.indexOf(']')); + } else { + return void 0; + } + }; + + SwaggerOperation.prototype.getSignature = function(dataType, models) { + var isPrimitive, listType; + listType = this.isListType(dataType); + isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true; + if (isPrimitive) { + return dataType; + } else { + if (listType != null) { + return models[listType].getMockSignature(); + } else { + return models[dataType].getMockSignature(); + } + } + }; + + SwaggerOperation.prototype.getSampleJSON = function(dataType, models) { + var isPrimitive, listType, val; + listType = this.isListType(dataType); + isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true; + val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[dataType].createJSONSample()); + if (val) { + val = listType ? [val] : val; + return JSON.stringify(val, null, 2); + } + }; + + SwaggerOperation.prototype["do"] = function(args, callback, error) { + var key, param, params, possibleParams, requestContentType, responseContentType, value; + if (args == null) { + args = {}; + } + requestContentType = null; + responseContentType = null; + if ((typeof args) === "function") { + error = callback; + callback = args; + args = {}; + } + if (error == null) { + error = function(xhr, textStatus, error) { + return console.log(xhr, textStatus, error); + }; + } + if (callback == null) { + callback = function(data) { + return console.log("default callback: " + data); + }; + } + params = {}; + if (args.requestContentType) { + requestContentType = args.requestContentType; + } + if (args.responseContentType) { + responseContentType = args.responseContentType; + } + if (args.headers != null) { + params.headers = args.headers; + delete args.headers; + } + if (args.body != null) { + params.body = args.body; + delete args.body; + } + possibleParams = (function() { + var _i, _len, _ref, _results; + _ref = this.parameters; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + param = _ref[_i]; + if (param.paramType === "form") { + _results.push(param); + } + } + return _results; + }).call(this); + if (possibleParams) { + for (key in possibleParams) { + value = possibleParams[key]; + if (args[value.name]) { + params[value.name] = args[value.name]; + } + } + } + if (args.mock != null) { + params.mock = args["mock"]; + } + params["parent"] = args["parent"]; + return new SwaggerRequest(this.method, this.urlify(args), params, requestContentType, responseContentType, callback, error, this); + }; + + SwaggerOperation.prototype.pathJson = function() { + return this.path.replace("{format}", "json"); + }; + + SwaggerOperation.prototype.pathXml = function() { + return this.path.replace("{format}", "xml"); + }; + + SwaggerOperation.prototype.urlify = function(args) { + var param, queryParams, reg, url, _i, _j, _len, _len1, _ref, _ref1; + url = this.resource.basePath + this.pathJson(); + _ref = this.parameters; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + param = _ref[_i]; + if (param.paramType === 'path') { + if (args[param.name]) { + reg = new RegExp('\{' + param.name + '[^\}]*\}', 'gi'); + url = url.replace(reg, encodeURIComponent(args[param.name])); + delete args[param.name]; + } else { + throw "" + param.name + " is a required path param."; + } + } + } + queryParams = ""; + _ref1 = this.parameters; + for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) { + param = _ref1[_j]; + if (param.paramType === 'query') { + if (args[param.name]) { + if (queryParams !== "") { + queryParams += "&"; + } + queryParams += encodeURIComponent(param.name) + '=' + encodeURIComponent(args[param.name]); + } + } + } + if ((queryParams != null) && queryParams.length > 0) { + url += "?" + queryParams; + } + return url; + }; + + SwaggerOperation.prototype.supportHeaderParams = function() { + return this.resource.api.supportHeaderParams; + }; + + SwaggerOperation.prototype.supportedSubmitMethods = function() { + return this.resource.api.supportedSubmitMethods; + }; + + SwaggerOperation.prototype.getQueryParams = function(args) { + return this.getMatchingParams(['query'], args); + }; + + SwaggerOperation.prototype.getHeaderParams = function(args) { + return this.getMatchingParams(['header'], args); + }; + + SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args) { + var matchingParams, name, param, value, _i, _len, _ref, _ref1; + matchingParams = {}; + _ref = this.parameters; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + param = _ref[_i]; + if (args && args[param.name]) { + matchingParams[param.name] = args[param.name]; + } + } + _ref1 = this.resource.api.headers; + for (name in _ref1) { + value = _ref1[name]; + matchingParams[name] = value; + } + return matchingParams; + }; + + SwaggerOperation.prototype.help = function() { + var msg, parameter, _i, _len, _ref; + msg = ""; + _ref = this.parameters; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + parameter = _ref[_i]; + if (msg !== "") { + msg += "\n"; + } + msg += "* " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description; + } + return msg; + }; + + return SwaggerOperation; + + })(); + + SwaggerRequest = (function() { + + function SwaggerRequest(type, url, params, requestContentType, responseContentType, successCallback, errorCallback, operation, execution) { + var body, e, fields, headers, key, myHeaders, obj, param, parent, possibleParams, urlEncoded, value, values, + _this = this; + this.type = type; + this.url = url; + this.params = params; + this.requestContentType = requestContentType; + this.responseContentType = responseContentType; + this.successCallback = successCallback; + this.errorCallback = errorCallback; + this.operation = operation; + this.execution = execution; + if (this.type == null) { + throw "SwaggerRequest type is required (get/post/put/delete)."; + } + if (this.url == null) { + throw "SwaggerRequest url is required."; + } + if (this.successCallback == null) { + throw "SwaggerRequest successCallback is required."; + } + if (this.errorCallback == null) { + throw "SwaggerRequest error callback is required."; + } + if (this.operation == null) { + throw "SwaggerRequest operation is required."; + } + this.type = this.type.toUpperCase(); + headers = params.headers; + myHeaders = {}; + body = params.body; + parent = params["parent"]; + requestContentType = "application/json"; + if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH")) { + if (this.requestContentType) { + requestContentType = this.requestContentType; + } + } else { + if (((function() { + var _i, _len, _ref, _results; + _ref = this.operation.parameters; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + param = _ref[_i]; + if (param.paramType === "form") { + _results.push(param); + } + } + return _results; + }).call(this)).length > 0) { + requestContentType = "application/x-www-form-urlencoded"; + } else if (this.type !== "DELETE") { + requestContentType = null; + } + } + if (requestContentType && this.operation.consumes) { + if (this.operation.consumes.indexOf(requestContentType) === -1) { + console.log("server doesn't consume " + requestContentType + ", try " + JSON.stringify(this.operation.consumes)); + if (this.requestContentType === null) { + requestContentType = this.operation.consumes[0]; + } + } else { + console.log("it's ok to send " + requestContentType); + } + } + responseContentType = null; + if (this.type === "POST" || this.type === "GET") { + if (this.responseContentType) { + responseContentType = this.responseContentType; + } else { + responseContentType = "application/json"; + } + } else { + responseContentType = null; + } + if (responseContentType && this.operation.produces) { + if (this.operation.produces.indexOf(responseContentType) === -1) { + console.log("server can't produce " + responseContentType); + } else { + console.log("get ready for " + responseContentType); + } + } + if (requestContentType && requestContentType.indexOf("application/x-www-form-urlencoded") === 0) { + console.log("pulling fields"); + fields = {}; + possibleParams = (function() { + var _i, _len, _ref, _results; + _ref = this.operation.parameters; + _results = []; + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + param = _ref[_i]; + if (param.paramType === "form") { + _results.push(param); + } + } + return _results; + }).call(this); + console.log(possibleParams); + values = {}; + for (key in possibleParams) { + value = possibleParams[key]; + if (this.params[value.name]) { + values[value.name] = this.params[value.name]; + } + } + urlEncoded = ""; + for (key in values) { + value = values[key]; + if (urlEncoded !== "") { + urlEncoded += "&"; + } + urlEncoded += encodeURIComponent(key) + '=' + encodeURIComponent(value); + } + body = urlEncoded; + } + if (requestContentType) { + myHeaders["Content-Type"] = requestContentType; + } + if (responseContentType) { + myHeaders["Accept"] = responseContentType; + } + if (!((headers != null) && (headers.mock != null))) { + obj = { + url: this.url, + method: this.type, + headers: myHeaders, + body: body, + on: { + error: function(response) { + return _this.errorCallback(response, _this.params["parent"]); + }, + redirect: function(response) { + return _this.successCallback(response, _this.params["parent"]); + }, + 307: function(response) { + return _this.successCallback(response, _this.params["parent"]); + }, + response: function(response) { + return _this.successCallback(response, _this.params["parent"]); + } + } + }; + e = {}; + if (typeof window !== 'undefined') { + e = window; + } else { + e = exports; + } + e.authorizations.apply(obj); + if (params.mock == null) { + new SwaggerHttp().execute(obj); + } else { + return obj; + } + } + } + + SwaggerRequest.prototype.asCurl = function() { + var header_args, k, v; + header_args = (function() { + var _ref, _results; + _ref = this.headers; + _results = []; + for (k in _ref) { + v = _ref[k]; + _results.push("--header \"" + k + ": " + v + "\""); + } + return _results; + }).call(this); + return "curl " + (header_args.join(" ")) + " " + this.url; + }; + + return SwaggerRequest; + + })(); + + SwaggerHttp = (function() { + + SwaggerHttp.prototype.shred = null; + + function SwaggerHttp() { + var Shred; + Shred = null; + if (typeof window !== 'undefined') { + Shred = require("./shred"); + } else { + Shred = require("shred"); + } + this.shred = new Shred(); + } + + SwaggerHttp.prototype.execute = function(obj) { + var Content, identity, toString, + _this = this; + Content = require("./shred/content"); + identity = function(x) { + return x; + }; + toString = function(x) { + return x.toString; + }; + Content.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], { + parser: identity, + stringify: toString + }); + return this.shred.request(obj); + }; + + return SwaggerHttp; + + })(); + + SwaggerAuthorizations = (function() { + + SwaggerAuthorizations.prototype.authz = null; + + function SwaggerAuthorizations() { + this.authz = {}; + } + + SwaggerAuthorizations.prototype.add = function(name, auth) { + this.authz[name] = auth; + return auth; + }; + + SwaggerAuthorizations.prototype.apply = function(obj) { + var key, value, _ref, _results; + _ref = this.authz; + _results = []; + for (key in _ref) { + value = _ref[key]; + _results.push(value.apply(obj)); + } + return _results; + }; + + return SwaggerAuthorizations; + + })(); + + ApiKeyAuthorization = (function() { + + ApiKeyAuthorization.prototype.type = null; + + ApiKeyAuthorization.prototype.name = null; + + ApiKeyAuthorization.prototype.value = null; + + function ApiKeyAuthorization(name, value, type) { + this.name = name; + this.value = value; + this.type = type; + } + + ApiKeyAuthorization.prototype.apply = function(obj) { + 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") { + return obj.headers[this.name] = this.value; + } + }; + + return ApiKeyAuthorization; + + })(); + + this.SwaggerApi = SwaggerApi; + + this.SwaggerResource = SwaggerResource; + + this.SwaggerOperation = SwaggerOperation; + + this.SwaggerRequest = SwaggerRequest; + + this.SwaggerModelProperty = SwaggerModelProperty; + + this.SwaggerAuthorizations = new SwaggerAuthorizations(); + + this.ApiKeyAuthorization = ApiKeyAuthorization; + + this.authorizations = new SwaggerAuthorizations(); + +}).call(this);