1 // Generated by CoffeeScript 1.6.3
3 var ApiKeyAuthorization, PasswordAuthorization, SwaggerApi, SwaggerAuthorizations, SwaggerHttp, SwaggerModel, SwaggerModelProperty, SwaggerOperation, SwaggerRequest, SwaggerResource,
4 __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
6 SwaggerApi = (function() {
7 SwaggerApi.prototype.url = "http://api.wordnik.com/v4/resources.json";
9 SwaggerApi.prototype.debug = false;
11 SwaggerApi.prototype.basePath = null;
13 SwaggerApi.prototype.authorizations = null;
15 SwaggerApi.prototype.authorizationScheme = null;
17 SwaggerApi.prototype.info = null;
19 function SwaggerApi(url, options) {
20 if (options == null) {
32 if (options.url != null) {
33 this.url = options.url;
35 if (options.success != null) {
36 this.success = options.success;
38 this.failure = options.failure != null ? options.failure : function() {};
39 this.progress = options.progress != null ? options.progress : function() {};
40 if (options.success != null) {
45 SwaggerApi.prototype.build = function() {
48 this.progress('fetching resource list: ' + this.url);
50 response = JSON.parse(getSpec());
52 _this.swaggerVersion = response.swaggerVersion;
53 if (_this.swaggerVersion === "1.2") {
54 setTimeout(function(){return _this.buildFromSpec(response);}, 500);
56 return setTimeout(function(){return _this.buildFrom1_1Spec(response);}, 500);
61 SwaggerApi.prototype.buildFromSpec = function(response) {
62 var api, isApi, newName, operation, res, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
63 if (response.apiVersion != null) {
64 this.apiVersion = response.apiVersion;
68 this.produces = response.produces;
69 this.authSchemes = response.authorizations;
70 if (response.info != null) {
71 this.info = response.info;
75 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
78 _ref1 = api.operations;
79 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
80 operation = _ref1[_j];
85 if (response.basePath) {
86 this.basePath = response.basePath;
87 } else if (this.url.indexOf('?') > 0) {
88 this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
90 this.basePath = this.url;
93 newName = response.resourcePath.replace(/\//g, '');
94 this.resourcePath = response.resourcePath;
95 res = new SwaggerResource(response, this);
96 this.apis[newName] = res;
97 this.apisArray.push(res);
99 _ref2 = response.apis;
100 for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
101 resource = _ref2[_k];
102 res = new SwaggerResource(resource, this);
103 this.apis[res.name] = res;
104 this.apisArray.push(res);
113 SwaggerApi.prototype.buildFrom1_1Spec = function(response) {
114 var api, isApi, newName, operation, res, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
115 console.log("This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info");
116 if (response.apiVersion != null) {
117 this.apiVersion = response.apiVersion;
121 this.produces = response.produces;
122 if (response.info != null) {
123 this.info = response.info;
126 _ref = response.apis;
127 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
129 if (api.operations) {
130 _ref1 = api.operations;
131 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
132 operation = _ref1[_j];
137 if (response.basePath) {
138 this.basePath = response.basePath;
139 } else if (this.url.indexOf('?') > 0) {
140 this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
142 this.basePath = this.url;
145 newName = response.resourcePath.replace(/\//g, '');
146 this.resourcePath = response.resourcePath;
147 res = new SwaggerResource(response, this);
148 this.apis[newName] = res;
149 this.apisArray.push(res);
151 _ref2 = response.apis;
152 for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
153 resource = _ref2[_k];
154 res = new SwaggerResource(resource, this);
155 this.apis[res.name] = res;
156 this.apisArray.push(res);
165 SwaggerApi.prototype.selfReflect = function() {
166 var resource, resource_name, _ref;
167 if (this.apis == null) {
171 for (resource_name in _ref) {
172 resource = _ref[resource_name];
173 if (resource.ready == null) {
177 this.setConsolidatedModels();
179 if (this.success != null) {
180 return this.success();
184 SwaggerApi.prototype.fail = function(message) {
185 this.failure(message);
189 SwaggerApi.prototype.setConsolidatedModels = function() {
190 var model, modelName, resource, resource_name, _i, _len, _ref, _ref1, _results;
191 this.modelsArray = [];
194 for (resource_name in _ref) {
195 resource = _ref[resource_name];
196 for (modelName in resource.models) {
197 if (this.models[modelName] == null) {
198 this.models[modelName] = resource.models[modelName];
199 this.modelsArray.push(resource.models[modelName]);
203 _ref1 = this.modelsArray;
205 for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
207 _results.push(model.setReferencedModels(this.models));
212 SwaggerApi.prototype.help = function() {
213 var operation, operation_name, parameter, resource, resource_name, _i, _len, _ref, _ref1, _ref2;
215 for (resource_name in _ref) {
216 resource = _ref[resource_name];
217 console.log(resource_name);
218 _ref1 = resource.operations;
219 for (operation_name in _ref1) {
220 operation = _ref1[operation_name];
221 console.log(" " + operation.nickname);
222 _ref2 = operation.parameters;
223 for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
224 parameter = _ref2[_i];
225 console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
236 SwaggerResource = (function() {
237 SwaggerResource.prototype.api = null;
239 SwaggerResource.prototype.produces = null;
241 SwaggerResource.prototype.consumes = null;
243 function SwaggerResource(resourceObj, api) {
244 var consumes, e, obj, parts, produces,
250 this.path = this.api.resourcePath != null ? this.api.resourcePath : resourceObj.path;
251 this.description = resourceObj.description;
252 parts = this.path.split("/");
253 this.name = parts[parts.length - 1].replace('.{format}', '');
254 this.basePath = this.api.basePath;
255 this.operations = {};
256 this.operationsArray = [];
257 this.modelsArray = [];
259 if ((resourceObj.apis != null) && (this.api.resourcePath != null)) {
260 this.addApiDeclaration(resourceObj);
262 if (this.path == null) {
263 this.api.fail("SwaggerResources must have a path.");
265 if (this.path.substring(0, 4) === 'http') {
266 this.url = this.path.replace('{format}', 'json');
268 this.url = this.api.basePath + this.path.replace('{format}', 'json');
270 this.api.progress('fetching resource ' + this.name + ': ' + this.url);
272 var split = resourceObj.path.split("/");
273 var resource = split[split.length-1];
274 response = JSON.parse(jsonFor(resource));
275 setTimeout(function(){return _this.addApiDeclaration(response);}, 500);
279 SwaggerResource.prototype.addApiDeclaration = function(response) {
280 var endpoint, _i, _len, _ref;
281 if (response.produces != null) {
282 this.produces = response.produces;
284 if (response.consumes != null) {
285 this.consumes = response.consumes;
287 if ((response.basePath != null) && response.basePath.replace(/\s/g, '').length > 0) {
288 this.basePath = response.basePath;
290 this.addModels(response.models);
292 _ref = response.apis;
293 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
295 this.addOperations(endpoint.path, endpoint.operations, response.consumes, response.produces);
298 this.api[this.name] = this;
300 return this.api.selfReflect();
303 SwaggerResource.prototype.addModels = function(models) {
304 var model, modelName, swaggerModel, _i, _len, _ref, _results;
305 if (models != null) {
306 for (modelName in models) {
307 if (this.models[modelName] == null) {
308 swaggerModel = new SwaggerModel(modelName, models[modelName]);
309 this.modelsArray.push(swaggerModel);
310 this.models[modelName] = swaggerModel;
313 _ref = this.modelsArray;
315 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
317 _results.push(model.setReferencedModels(this.models));
323 SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes, produces) {
324 var method, o, op, r, ref, responseMessages, type, _i, _j, _len, _len1, _results;
327 for (_i = 0, _len = ops.length; _i < _len; _i++) {
329 consumes = this.consumes;
330 produces = this.produces;
331 if (o.consumes != null) {
332 consumes = o.consumes;
334 consumes = this.consumes;
336 if (o.produces != null) {
337 produces = o.produces;
339 produces = this.produces;
341 type = o.type || o.responseClass;
342 if (type === "array") {
345 ref = o.items["type"] || o.items["$ref"];
347 type = "array[" + ref + "]";
349 responseMessages = o.responseMessages;
352 method = o.httpMethod;
354 if (o.supportedContentTypes) {
355 consumes = o.supportedContentTypes;
357 if (o.errorResponses) {
358 responseMessages = o.errorResponses;
359 for (_j = 0, _len1 = responseMessages.length; _j < _len1; _j++) {
360 r = responseMessages[_j];
361 r.message = r.reason;
365 o.nickname = this.sanitize(o.nickname);
366 op = new SwaggerOperation(o.nickname, resource_path, method, o.parameters, o.summary, o.notes, type, responseMessages, this, consumes, produces);
367 this.operations[op.nickname] = op;
368 _results.push(this.operationsArray.push(op));
374 SwaggerResource.prototype.sanitize = function(nickname) {
376 op = nickname.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|./?,\\'""-]/g, '_');
377 op = op.replace(/((_){2,})/g, '_');
378 op = op.replace(/^(_)*/g, '');
379 op = op.replace(/([_])*$/g, '');
383 SwaggerResource.prototype.help = function() {
384 var msg, operation, operation_name, parameter, _i, _len, _ref, _ref1, _results;
385 _ref = this.operations;
387 for (operation_name in _ref) {
388 operation = _ref[operation_name];
389 msg = " " + operation.nickname;
390 _ref1 = operation.parameters;
391 for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
392 parameter = _ref1[_i];
393 msg.concat(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
400 return SwaggerResource;
404 SwaggerModel = (function() {
405 function SwaggerModel(modelName, obj) {
406 var prop, propertyName, value;
407 this.name = obj.id != null ? obj.id : modelName;
408 this.properties = [];
409 for (propertyName in obj.properties) {
410 if (obj.required != null) {
411 for (value in obj.required) {
412 if (propertyName === obj.required[value]) {
413 obj.properties[propertyName].required = true;
417 prop = new SwaggerModelProperty(propertyName, obj.properties[propertyName]);
418 this.properties.push(prop);
422 SwaggerModel.prototype.setReferencedModels = function(allModels) {
423 var prop, type, _i, _len, _ref, _results;
424 _ref = this.properties;
426 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
428 type = prop.type || prop.dataType;
429 if (allModels[type] != null) {
430 _results.push(prop.refModel = allModels[type]);
431 } else if ((prop.refDataType != null) && (allModels[prop.refDataType] != null)) {
432 _results.push(prop.refModel = allModels[prop.refDataType]);
434 _results.push(void 0);
440 SwaggerModel.prototype.getMockSignature = function(modelsToIgnore) {
441 var classClose, classOpen, prop, propertiesStr, returnVal, strong, strongClose, stronger, _i, _j, _len, _len1, _ref, _ref1;
443 _ref = this.properties;
444 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
446 propertiesStr.push(prop.toString());
448 strong = '<span class="strong">';
449 stronger = '<span class="stronger">';
450 strongClose = '</span>';
451 classOpen = strong + this.name + ' {' + strongClose;
452 classClose = strong + '}' + strongClose;
453 returnVal = classOpen + '<div>' + propertiesStr.join(',</div><div>') + '</div>' + classClose;
454 if (!modelsToIgnore) {
457 modelsToIgnore.push(this);
458 _ref1 = this.properties;
459 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
461 if ((prop.refModel != null) && (modelsToIgnore.indexOf(prop.refModel)) === -1) {
462 returnVal = returnVal + ('<br>' + prop.refModel.getMockSignature(modelsToIgnore));
468 SwaggerModel.prototype.createJSONSample = function(modelsToIgnore) {
469 var prop, result, _i, _len, _ref;
471 modelsToIgnore = modelsToIgnore || [];
472 modelsToIgnore.push(this.name);
473 _ref = this.properties;
474 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
476 result[prop.name] = prop.getSampleValue(modelsToIgnore);
478 modelsToIgnore.pop(this.name);
486 SwaggerModelProperty = (function() {
487 function SwaggerModelProperty(name, obj) {
489 this.dataType = obj.type || obj.dataType || obj["$ref"];
490 this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set');
491 this.descr = obj.description;
492 this.required = obj.required;
493 if (obj.items != null) {
494 if (obj.items.type != null) {
495 this.refDataType = obj.items.type;
497 if (obj.items.$ref != null) {
498 this.refDataType = obj.items.$ref;
501 this.dataTypeWithRef = this.refDataType != null ? this.dataType + '[' + this.refDataType + ']' : this.dataType;
502 if (obj.allowableValues != null) {
503 this.valueType = obj.allowableValues.valueType;
504 this.values = obj.allowableValues.values;
505 if (this.values != null) {
506 this.valuesString = "'" + this.values.join("' or '") + "'";
509 if (obj["enum"] != null) {
510 this.valueType = "string";
511 this.values = obj["enum"];
512 if (this.values != null) {
513 this.valueString = "'" + this.values.join("' or '") + "'";
518 SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
520 if ((this.refModel != null) && (modelsToIgnore.indexOf(this.refModel.name) === -1)) {
521 result = this.refModel.createJSONSample(modelsToIgnore);
523 if (this.isCollection) {
524 result = this.refDataType;
526 result = this.dataType;
529 if (this.isCollection) {
536 SwaggerModelProperty.prototype.toString = function() {
538 req = this.required ? 'propReq' : 'propOpt';
539 str = '<span class="propName ' + req + '">' + this.name + '</span> (<span class="propType">' + this.dataTypeWithRef + '</span>';
540 if (!this.required) {
541 str += ', <span class="propOptKey">optional</span>';
544 if (this.values != null) {
545 str += " = <span class='propVals'>['" + this.values.join("' or '") + "']</span>";
547 if (this.descr != null) {
548 str += ': <span class="propDesc">' + this.descr + '</span>';
553 return SwaggerModelProperty;
557 SwaggerOperation = (function() {
558 function SwaggerOperation(nickname, path, method, parameters, summary, notes, type, responseMessages, resource, consumes, produces) {
559 var parameter, v, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3,
561 this.nickname = nickname;
563 this.method = method;
564 this.parameters = parameters != null ? parameters : [];
565 this.summary = summary;
568 this.responseMessages = responseMessages;
569 this.resource = resource;
570 this.consumes = consumes;
571 this.produces = produces;
572 this["do"] = __bind(this["do"], this);
573 if (this.nickname == null) {
574 this.resource.api.fail("SwaggerOperations must have a nickname.");
576 if (this.path == null) {
577 this.resource.api.fail("SwaggerOperation " + nickname + " is missing path.");
579 if (this.method == null) {
580 this.resource.api.fail("SwaggerOperation " + nickname + " is missing method.");
582 this.path = this.path.replace('{format}', 'json');
583 this.method = this.method.toLowerCase();
584 this.isGetMethod = this.method === "get";
585 this.resourceName = this.resource.name;
586 if (((_ref = this.type) != null ? _ref.toLowerCase() : void 0) === 'void') {
589 if (this.type != null) {
590 this.responseClassSignature = this.getSignature(this.type, this.resource.models);
591 this.responseSampleJSON = this.getSampleJSON(this.type, this.resource.models);
593 this.responseMessages = this.responseMessages || [];
594 _ref1 = this.parameters;
595 for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
596 parameter = _ref1[_i];
597 parameter.name = parameter.name || parameter.type || parameter.dataType;
598 type = parameter.type || parameter.dataType;
599 if (type.toLowerCase() === 'boolean') {
600 parameter.allowableValues = {};
601 parameter.allowableValues.values = ["true", "false"];
603 parameter.signature = this.getSignature(type, this.resource.models);
604 parameter.sampleJSON = this.getSampleJSON(type, this.resource.models);
605 if (parameter["enum"] != null) {
606 parameter.isList = true;
607 parameter.allowableValues = {};
608 parameter.allowableValues.descriptiveValues = [];
609 _ref2 = parameter["enum"];
610 for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
612 if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
613 parameter.allowableValues.descriptiveValues.push({
618 parameter.allowableValues.descriptiveValues.push({
625 if (parameter.allowableValues != null) {
626 if (parameter.allowableValues.valueType === "RANGE") {
627 parameter.isRange = true;
629 parameter.isList = true;
631 if (parameter.allowableValues.values != null) {
632 parameter.allowableValues.descriptiveValues = [];
633 _ref3 = parameter.allowableValues.values;
634 for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
636 if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
637 parameter.allowableValues.descriptiveValues.push({
642 parameter.allowableValues.descriptiveValues.push({
651 this.resource[this.nickname] = function(args, callback, error) {
652 return _this["do"](args, callback, error);
654 this.resource[this.nickname].help = function() {
659 SwaggerOperation.prototype.isListType = function(type) {
660 if (type.indexOf('[') >= 0) {
661 return type.substring(type.indexOf('[') + 1, type.indexOf(']'));
667 SwaggerOperation.prototype.getSignature = function(type, models) {
668 var isPrimitive, listType;
669 listType = this.isListType(type);
670 isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
674 if (listType != null) {
675 return models[listType].getMockSignature();
677 return models[type].getMockSignature();
682 SwaggerOperation.prototype.getSampleJSON = function(type, models) {
683 var isPrimitive, listType, val;
684 listType = this.isListType(type);
685 isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
686 val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[type].createJSONSample());
688 val = listType ? [val] : val;
689 return JSON.stringify(val, null, 2);
693 SwaggerOperation.prototype["do"] = function(args, opts, callback, error) {
694 var key, param, params, possibleParams, req, requestContentType, responseContentType, value, _i, _len, _ref;
701 requestContentType = null;
702 responseContentType = null;
703 if ((typeof args) === "function") {
708 if ((typeof opts) === "function") {
713 error = function(xhr, textStatus, error) {
714 return console.log(xhr, textStatus, error);
717 if (callback == null) {
718 callback = function(data) {
721 if (data.content != null) {
722 content = data.content.data;
726 return console.log("default callback: " + content);
731 if (args.headers != null) {
732 params.headers = args.headers;
735 _ref = this.parameters;
736 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
738 if (param.paramType === "header") {
739 if (args[param.name]) {
740 params.headers[param.name] = args[param.name];
744 if (args.body != null) {
745 params.body = args.body;
748 possibleParams = (function() {
749 var _j, _len1, _ref1, _results;
750 _ref1 = this.parameters;
752 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
754 if (param.paramType === "form" || param.paramType.toLowerCase() === "file") {
755 _results.push(param);
760 if (possibleParams) {
761 for (key in possibleParams) {
762 value = possibleParams[key];
763 if (args[value.name]) {
764 params[value.name] = args[value.name];
768 req = new SwaggerRequest(this.method, this.urlify(args), params, opts, callback, error, this);
769 if (opts.mock != null) {
776 SwaggerOperation.prototype.pathJson = function() {
777 return this.path.replace("{format}", "json");
780 SwaggerOperation.prototype.pathXml = function() {
781 return this.path.replace("{format}", "xml");
784 SwaggerOperation.prototype.urlify = function(args) {
785 var param, queryParams, reg, url, _i, _j, _len, _len1, _ref, _ref1;
786 url = this.resource.basePath + this.pathJson();
787 _ref = this.parameters;
788 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
790 if (param.paramType === 'path') {
791 if (args[param.name]) {
792 reg = new RegExp('\{' + param.name + '[^\}]*\}', 'gi');
793 url = url.replace(reg, encodeURIComponent(args[param.name]));
794 delete args[param.name];
796 throw "" + param.name + " is a required path param.";
801 _ref1 = this.parameters;
802 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
804 if (param.paramType === 'query') {
805 if (args[param.name]) {
806 if (queryParams !== "") {
809 queryParams += encodeURIComponent(param.name) + '=' + encodeURIComponent(args[param.name]);
813 if ((queryParams != null) && queryParams.length > 0) {
814 url += "?" + queryParams;
819 SwaggerOperation.prototype.supportHeaderParams = function() {
820 return this.resource.api.supportHeaderParams;
823 SwaggerOperation.prototype.supportedSubmitMethods = function() {
824 return this.resource.api.supportedSubmitMethods;
827 SwaggerOperation.prototype.getQueryParams = function(args) {
828 return this.getMatchingParams(['query'], args);
831 SwaggerOperation.prototype.getHeaderParams = function(args) {
832 return this.getMatchingParams(['header'], args);
835 SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args) {
836 var matchingParams, name, param, value, _i, _len, _ref, _ref1;
838 _ref = this.parameters;
839 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
841 if (args && args[param.name]) {
842 matchingParams[param.name] = args[param.name];
845 _ref1 = this.resource.api.headers;
846 for (name in _ref1) {
848 matchingParams[name] = value;
850 return matchingParams;
853 SwaggerOperation.prototype.help = function() {
854 var msg, parameter, _i, _len, _ref;
856 _ref = this.parameters;
857 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
858 parameter = _ref[_i];
862 msg += "* " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description;
867 return SwaggerOperation;
871 SwaggerRequest = (function() {
872 function SwaggerRequest(type, url, params, opts, successCallback, errorCallback, operation, execution) {
873 var body, e, fields, headers, key, myHeaders, name, obj, param, parent, possibleParams, requestContentType, responseContentType, urlEncoded, value, values,
877 this.params = params;
879 this.successCallback = successCallback;
880 this.errorCallback = errorCallback;
881 this.operation = operation;
882 this.execution = execution;
883 if (this.type == null) {
884 throw "SwaggerRequest type is required (get/post/put/delete).";
886 if (this.url == null) {
887 throw "SwaggerRequest url is required.";
889 if (this.successCallback == null) {
890 throw "SwaggerRequest successCallback is required.";
892 if (this.errorCallback == null) {
893 throw "SwaggerRequest error callback is required.";
895 if (this.operation == null) {
896 throw "SwaggerRequest operation is required.";
898 this.type = this.type.toUpperCase();
899 headers = params.headers;
902 parent = params["parent"];
903 requestContentType = "application/json";
904 if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH")) {
905 if (this.opts.requestContentType) {
906 requestContentType = this.opts.requestContentType;
910 var _i, _len, _ref, _results;
911 _ref = this.operation.parameters;
913 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
915 if (param.paramType === "form") {
916 _results.push(param);
920 }).call(this)).length > 0) {
921 type = param.type || param.dataType;
923 var _i, _len, _ref, _results;
924 _ref = this.operation.parameters;
926 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
928 if (type.toLowerCase() === "file") {
929 _results.push(param);
933 }).call(this)).length > 0) {
934 requestContentType = "multipart/form-data";
936 requestContentType = "application/x-www-form-urlencoded";
938 } else if (this.type !== "DELETE") {
939 requestContentType = null;
942 if (requestContentType && this.operation.consumes) {
943 if (this.operation.consumes.indexOf(requestContentType) === -1) {
944 console.log("server doesn't consume " + requestContentType + ", try " + JSON.stringify(this.operation.consumes));
945 if (this.requestContentType === null) {
946 requestContentType = this.operation.consumes[0];
950 responseContentType = null;
951 if (this.type === "POST" || this.type === "GET" || this.type === "PATCH") {
952 if (this.opts.responseContentType) {
953 responseContentType = this.opts.responseContentType;
955 responseContentType = "application/json";
958 responseContentType = null;
960 if (responseContentType && this.operation.produces) {
961 if (this.operation.produces.indexOf(responseContentType) === -1) {
962 console.log("server can't produce " + responseContentType);
965 if (requestContentType && requestContentType.indexOf("application/x-www-form-urlencoded") === 0) {
967 possibleParams = (function() {
968 var _i, _len, _ref, _results;
969 _ref = this.operation.parameters;
971 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
973 if (param.paramType === "form") {
974 _results.push(param);
980 for (key in possibleParams) {
981 value = possibleParams[key];
982 if (this.params[value.name]) {
983 values[value.name] = this.params[value.name];
987 for (key in values) {
989 if (urlEncoded !== "") {
992 urlEncoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
996 for (name in headers) {
997 myHeaders[name] = headers[name];
999 if (requestContentType) {
1000 myHeaders["Content-Type"] = requestContentType;
1002 if (responseContentType) {
1003 myHeaders["Accept"] = responseContentType;
1005 if (!((headers != null) && (headers.mock != null))) {
1012 error: function(response) {
1013 return _this.errorCallback(response, _this.opts.parent);
1015 redirect: function(response) {
1016 return _this.successCallback(response, _this.opts.parent);
1018 307: function(response) {
1019 return _this.successCallback(response, _this.opts.parent);
1021 response: function(response) {
1022 return _this.successCallback(response, _this.opts.parent);
1027 if (typeof window !== 'undefined') {
1032 e.authorizations.apply(obj);
1033 if (opts.mock == null) {
1034 new SwaggerHttp().execute(obj);
1042 SwaggerRequest.prototype.asCurl = function() {
1043 var header_args, k, v;
1044 header_args = (function() {
1046 _ref = this.headers;
1050 _results.push("--header \"" + k + ": " + v + "\"");
1054 return "curl " + (header_args.join(" ")) + " " + this.url;
1057 return SwaggerRequest;
1061 SwaggerHttp = (function() {
1062 SwaggerHttp.prototype.Shred = null;
1064 SwaggerHttp.prototype.shred = null;
1066 SwaggerHttp.prototype.content = null;
1068 function SwaggerHttp() {
1069 var identity, toString,
1071 if (typeof window !== 'undefined') {
1072 this.Shred = require("./shred");
1074 this.Shred = require("shred");
1076 this.shred = new this.Shred();
1077 identity = function(x) {
1080 toString = function(x) {
1081 return x.toString();
1083 if (typeof window !== 'undefined') {
1084 this.content = require("./shred/content");
1085 this.content.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
1090 this.Shred.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
1097 SwaggerHttp.prototype.execute = function(obj) {
1098 return this.shred.request(obj);
1105 SwaggerAuthorizations = (function() {
1106 SwaggerAuthorizations.prototype.authz = null;
1108 function SwaggerAuthorizations() {
1112 SwaggerAuthorizations.prototype.add = function(name, auth) {
1113 this.authz[name] = auth;
1117 SwaggerAuthorizations.prototype.apply = function(obj) {
1118 var key, value, _ref, _results;
1123 _results.push(value.apply(obj));
1128 return SwaggerAuthorizations;
1132 ApiKeyAuthorization = (function() {
1133 ApiKeyAuthorization.prototype.type = null;
1135 ApiKeyAuthorization.prototype.name = null;
1137 ApiKeyAuthorization.prototype.value = null;
1139 function ApiKeyAuthorization(name, value, type) {
1145 ApiKeyAuthorization.prototype.apply = function(obj) {
1146 if (this.type === "query") {
1147 if (obj.url.indexOf('?') > 0) {
1148 obj.url = obj.url + "&" + this.name + "=" + this.value;
1150 obj.url = obj.url + "?" + this.name + "=" + this.value;
1153 } else if (this.type === "header") {
1154 return obj.headers[this.name] = this.value;
1158 return ApiKeyAuthorization;
1162 PasswordAuthorization = (function() {
1163 PasswordAuthorization.prototype.name = null;
1165 PasswordAuthorization.prototype.username = null;
1167 PasswordAuthorization.prototype.password = null;
1169 function PasswordAuthorization(name, username, password) {
1171 this.username = username;
1172 this.password = password;
1175 PasswordAuthorization.prototype.apply = function(obj) {
1176 return obj.headers["Authorization"] = "Basic " + btoa(this.username + ":" + this.password);
1179 return PasswordAuthorization;
1183 this.SwaggerApi = SwaggerApi;
1185 this.SwaggerResource = SwaggerResource;
1187 this.SwaggerOperation = SwaggerOperation;
1189 this.SwaggerRequest = SwaggerRequest;
1191 this.SwaggerModelProperty = SwaggerModelProperty;
1193 this.ApiKeyAuthorization = ApiKeyAuthorization;
1195 this.PasswordAuthorization = PasswordAuthorization;
1197 this.authorizations = new SwaggerAuthorizations();