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);
54 error: function(response) {
55 if (_this.url.substring(0, 4) !== 'http') {
56 return _this.fail('Please specify the protocol for ' + _this.url);
57 } else if (response.status === 0) {
58 return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
59 } else if (response.status === 404) {
60 return _this.fail('Can\'t read swagger JSON from ' + _this.url);
62 return _this.fail(response.status + ' : ' + response.statusText + ' ' + _this.url);
65 response: function(rawResponse) {
67 response = JSON.parse(rawResponse.content.data);
68 _this.swaggerVersion = response.swaggerVersion;
69 if (_this.swaggerVersion === "1.2") {
70 return _this.buildFromSpec(response);
72 return _this.buildFrom1_1Spec(response);
78 if (typeof window !== 'undefined') {
83 e.authorizations.apply(obj);
84 new SwaggerHttp().execute(obj);
88 SwaggerApi.prototype.buildFromSpec = function(response) {
89 var api, isApi, newName, operation, res, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
90 if (response.apiVersion != null) {
91 this.apiVersion = response.apiVersion;
95 this.produces = response.produces;
96 this.authSchemes = response.authorizations;
97 if (response.info != null) {
98 this.info = response.info;
101 _ref = response.apis;
102 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
104 if (api.operations) {
105 _ref1 = api.operations;
106 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
107 operation = _ref1[_j];
112 if (response.basePath) {
113 this.basePath = response.basePath;
114 } else if (this.url.indexOf('?') > 0) {
115 this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
117 this.basePath = this.url;
120 newName = response.resourcePath.replace(/\//g, '');
121 this.resourcePath = response.resourcePath;
122 res = new SwaggerResource(response, this);
123 this.apis[newName] = res;
124 this.apisArray.push(res);
126 _ref2 = response.apis;
127 for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
128 resource = _ref2[_k];
129 res = new SwaggerResource(resource, this);
130 this.apis[res.name] = res;
131 this.apisArray.push(res);
140 SwaggerApi.prototype.buildFrom1_1Spec = function(response) {
141 var api, isApi, newName, operation, res, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
142 console.log("This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info");
143 if (response.apiVersion != null) {
144 this.apiVersion = response.apiVersion;
148 this.produces = response.produces;
149 if (response.info != null) {
150 this.info = response.info;
153 _ref = response.apis;
154 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
156 if (api.operations) {
157 _ref1 = api.operations;
158 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
159 operation = _ref1[_j];
164 if (response.basePath) {
165 this.basePath = response.basePath;
166 } else if (this.url.indexOf('?') > 0) {
167 this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
169 this.basePath = this.url;
172 newName = response.resourcePath.replace(/\//g, '');
173 this.resourcePath = response.resourcePath;
174 res = new SwaggerResource(response, this);
175 this.apis[newName] = res;
176 this.apisArray.push(res);
178 _ref2 = response.apis;
179 for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
180 resource = _ref2[_k];
181 res = new SwaggerResource(resource, this);
182 this.apis[res.name] = res;
183 this.apisArray.push(res);
192 SwaggerApi.prototype.selfReflect = function() {
193 var resource, resource_name, _ref;
194 if (this.apis == null) {
198 for (resource_name in _ref) {
199 resource = _ref[resource_name];
200 if (resource.ready == null) {
204 this.setConsolidatedModels();
206 if (this.success != null) {
207 return this.success();
211 SwaggerApi.prototype.fail = function(message) {
212 this.failure(message);
216 SwaggerApi.prototype.setConsolidatedModels = function() {
217 var model, modelName, resource, resource_name, _i, _len, _ref, _ref1, _results;
218 this.modelsArray = [];
221 for (resource_name in _ref) {
222 resource = _ref[resource_name];
223 for (modelName in resource.models) {
224 if (this.models[modelName] == null) {
225 this.models[modelName] = resource.models[modelName];
226 this.modelsArray.push(resource.models[modelName]);
230 _ref1 = this.modelsArray;
232 for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
234 _results.push(model.setReferencedModels(this.models));
239 SwaggerApi.prototype.help = function() {
240 var operation, operation_name, parameter, resource, resource_name, _i, _len, _ref, _ref1, _ref2;
242 for (resource_name in _ref) {
243 resource = _ref[resource_name];
244 console.log(resource_name);
245 _ref1 = resource.operations;
246 for (operation_name in _ref1) {
247 operation = _ref1[operation_name];
248 console.log(" " + operation.nickname);
249 _ref2 = operation.parameters;
250 for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
251 parameter = _ref2[_i];
252 console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
263 SwaggerResource = (function() {
264 SwaggerResource.prototype.api = null;
266 SwaggerResource.prototype.produces = null;
268 SwaggerResource.prototype.consumes = null;
270 function SwaggerResource(resourceObj, api) {
271 var consumes, e, obj, parts, produces,
277 this.path = this.api.resourcePath != null ? this.api.resourcePath : resourceObj.path;
278 this.description = resourceObj.description;
279 parts = this.path.split("/");
280 this.name = parts[parts.length - 1].replace('.{format}', '');
281 this.basePath = this.api.basePath;
282 this.operations = {};
283 this.operationsArray = [];
284 this.modelsArray = [];
286 if ((resourceObj.apis != null) && (this.api.resourcePath != null)) {
287 this.addApiDeclaration(resourceObj);
289 if (this.path == null) {
290 this.api.fail("SwaggerResources must have a path.");
292 if (this.path.substring(0, 4) === 'http') {
293 this.url = this.path.replace('{format}', 'json');
295 this.url = this.api.basePath + this.path.replace('{format}', 'json');
297 this.api.progress('fetching resource ' + this.name + ': ' + this.url);
303 error: function(response) {
304 return _this.api.fail("Unable to read api '" + _this.name + "' from path " + _this.url + " (server returned " + response.statusText + ")");
306 response: function(rawResponse) {
308 response = JSON.parse(rawResponse.content.data);
309 return _this.addApiDeclaration(response);
314 if (typeof window !== 'undefined') {
319 e.authorizations.apply(obj);
320 new SwaggerHttp().execute(obj);
324 SwaggerResource.prototype.addApiDeclaration = function(response) {
325 var endpoint, _i, _len, _ref;
326 if (response.produces != null) {
327 this.produces = response.produces;
329 if (response.consumes != null) {
330 this.consumes = response.consumes;
332 if ((response.basePath != null) && response.basePath.replace(/\s/g, '').length > 0) {
333 this.basePath = response.basePath;
335 this.addModels(response.models);
337 _ref = response.apis;
338 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
340 this.addOperations(endpoint.path, endpoint.operations, response.consumes, response.produces);
343 this.api[this.name] = this;
345 return this.api.selfReflect();
348 SwaggerResource.prototype.addModels = function(models) {
349 var model, modelName, swaggerModel, _i, _len, _ref, _results;
350 if (models != null) {
351 for (modelName in models) {
352 if (this.models[modelName] == null) {
353 swaggerModel = new SwaggerModel(modelName, models[modelName]);
354 this.modelsArray.push(swaggerModel);
355 this.models[modelName] = swaggerModel;
358 _ref = this.modelsArray;
360 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
362 _results.push(model.setReferencedModels(this.models));
368 SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes, produces) {
369 var method, o, op, r, ref, responseMessages, type, _i, _j, _len, _len1, _results;
372 for (_i = 0, _len = ops.length; _i < _len; _i++) {
374 consumes = this.consumes;
375 produces = this.produces;
376 if (o.consumes != null) {
377 consumes = o.consumes;
379 consumes = this.consumes;
381 if (o.produces != null) {
382 produces = o.produces;
384 produces = this.produces;
386 type = o.type || o.responseClass;
387 if (type === "array") {
390 ref = o.items["type"] || o.items["$ref"];
392 type = "array[" + ref + "]";
394 responseMessages = o.responseMessages;
397 method = o.httpMethod;
399 if (o.supportedContentTypes) {
400 consumes = o.supportedContentTypes;
402 if (o.errorResponses) {
403 responseMessages = o.errorResponses;
404 for (_j = 0, _len1 = responseMessages.length; _j < _len1; _j++) {
405 r = responseMessages[_j];
406 r.message = r.reason;
410 o.nickname = this.sanitize(o.nickname);
411 op = new SwaggerOperation(o.nickname, resource_path, method, o.parameters, o.summary, o.notes, type, responseMessages, this, consumes, produces);
412 this.operations[op.nickname] = op;
413 _results.push(this.operationsArray.push(op));
419 SwaggerResource.prototype.sanitize = function(nickname) {
421 op = nickname.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|./?,\\'""-]/g, '_');
422 op = op.replace(/((_){2,})/g, '_');
423 op = op.replace(/^(_)*/g, '');
424 op = op.replace(/([_])*$/g, '');
428 SwaggerResource.prototype.help = function() {
429 var msg, operation, operation_name, parameter, _i, _len, _ref, _ref1, _results;
430 _ref = this.operations;
432 for (operation_name in _ref) {
433 operation = _ref[operation_name];
434 msg = " " + operation.nickname;
435 _ref1 = operation.parameters;
436 for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
437 parameter = _ref1[_i];
438 msg.concat(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
445 return SwaggerResource;
449 SwaggerModel = (function() {
450 function SwaggerModel(modelName, obj) {
451 var prop, propertyName, value;
452 this.name = obj.id != null ? obj.id : modelName;
453 this.properties = [];
454 for (propertyName in obj.properties) {
455 if (obj.required != null) {
456 for (value in obj.required) {
457 if (propertyName === obj.required[value]) {
458 obj.properties[propertyName].required = true;
462 prop = new SwaggerModelProperty(propertyName, obj.properties[propertyName]);
463 this.properties.push(prop);
467 SwaggerModel.prototype.setReferencedModels = function(allModels) {
468 var prop, type, _i, _len, _ref, _results;
469 _ref = this.properties;
471 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
473 type = prop.type || prop.dataType;
474 if (allModels[type] != null) {
475 _results.push(prop.refModel = allModels[type]);
476 } else if ((prop.refDataType != null) && (allModels[prop.refDataType] != null)) {
477 _results.push(prop.refModel = allModels[prop.refDataType]);
479 _results.push(void 0);
485 SwaggerModel.prototype.getMockSignature = function(modelsToIgnore) {
486 var classClose, classOpen, prop, propertiesStr, returnVal, strong, strongClose, stronger, _i, _j, _len, _len1, _ref, _ref1;
488 _ref = this.properties;
489 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
491 propertiesStr.push(prop.toString());
493 strong = '<span class="strong">';
494 stronger = '<span class="stronger">';
495 strongClose = '</span>';
496 classOpen = strong + this.name + ' {' + strongClose;
497 classClose = strong + '}' + strongClose;
498 returnVal = classOpen + '<div>' + propertiesStr.join(',</div><div>') + '</div>' + classClose;
499 if (!modelsToIgnore) {
502 modelsToIgnore.push(this);
503 _ref1 = this.properties;
504 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
506 if ((prop.refModel != null) && (modelsToIgnore.indexOf(prop.refModel)) === -1) {
507 returnVal = returnVal + ('<br>' + prop.refModel.getMockSignature(modelsToIgnore));
513 SwaggerModel.prototype.createJSONSample = function(modelsToIgnore) {
514 var prop, result, _i, _len, _ref;
516 modelsToIgnore = modelsToIgnore || [];
517 modelsToIgnore.push(this.name);
518 _ref = this.properties;
519 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
521 result[prop.name] = prop.getSampleValue(modelsToIgnore);
523 modelsToIgnore.pop(this.name);
531 SwaggerModelProperty = (function() {
532 function SwaggerModelProperty(name, obj) {
534 this.dataType = obj.type || obj.dataType || obj["$ref"];
535 this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set');
536 this.descr = obj.description;
537 this.required = obj.required;
538 if (obj.items != null) {
539 if (obj.items.type != null) {
540 this.refDataType = obj.items.type;
542 if (obj.items.$ref != null) {
543 this.refDataType = obj.items.$ref;
546 this.dataTypeWithRef = this.refDataType != null ? this.dataType + '[' + this.refDataType + ']' : this.dataType;
547 if (obj.allowableValues != null) {
548 this.valueType = obj.allowableValues.valueType;
549 this.values = obj.allowableValues.values;
550 if (this.values != null) {
551 this.valuesString = "'" + this.values.join("' or '") + "'";
554 if (obj["enum"] != null) {
555 this.valueType = "string";
556 this.values = obj["enum"];
557 if (this.values != null) {
558 this.valueString = "'" + this.values.join("' or '") + "'";
563 SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
565 if ((this.refModel != null) && (modelsToIgnore.indexOf(this.refModel.name) === -1)) {
566 result = this.refModel.createJSONSample(modelsToIgnore);
568 if (this.isCollection) {
569 result = this.refDataType;
571 result = this.dataType;
574 if (this.isCollection) {
581 SwaggerModelProperty.prototype.toString = function() {
583 req = this.required ? 'propReq' : 'propOpt';
584 str = '<span class="propName ' + req + '">' + this.name + '</span> (<span class="propType">' + this.dataTypeWithRef + '</span>';
585 if (!this.required) {
586 str += ', <span class="propOptKey">optional</span>';
589 if (this.values != null) {
590 str += " = <span class='propVals'>['" + this.values.join("' or '") + "']</span>";
592 if (this.descr != null) {
593 str += ': <span class="propDesc">' + this.descr + '</span>';
598 return SwaggerModelProperty;
602 SwaggerOperation = (function() {
603 function SwaggerOperation(nickname, path, method, parameters, summary, notes, type, responseMessages, resource, consumes, produces) {
604 var parameter, v, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3,
606 this.nickname = nickname;
608 this.method = method;
609 this.parameters = parameters != null ? parameters : [];
610 this.summary = summary;
613 this.responseMessages = responseMessages;
614 this.resource = resource;
615 this.consumes = consumes;
616 this.produces = produces;
617 this["do"] = __bind(this["do"], this);
618 if (this.nickname == null) {
619 this.resource.api.fail("SwaggerOperations must have a nickname.");
621 if (this.path == null) {
622 this.resource.api.fail("SwaggerOperation " + nickname + " is missing path.");
624 if (this.method == null) {
625 this.resource.api.fail("SwaggerOperation " + nickname + " is missing method.");
627 this.path = this.path.replace('{format}', 'json');
628 this.method = this.method.toLowerCase();
629 this.isGetMethod = this.method === "get";
630 this.resourceName = this.resource.name;
631 if (((_ref = this.type) != null ? _ref.toLowerCase() : void 0) === 'void') {
634 if (this.type != null) {
635 this.responseClassSignature = this.getSignature(this.type, this.resource.models);
636 this.responseSampleJSON = this.getSampleJSON(this.type, this.resource.models);
638 this.responseMessages = this.responseMessages || [];
639 _ref1 = this.parameters;
640 for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
641 parameter = _ref1[_i];
642 parameter.name = parameter.name || parameter.type || parameter.dataType;
643 type = parameter.type || parameter.dataType;
644 if (type.toLowerCase() === 'boolean') {
645 parameter.allowableValues = {};
646 parameter.allowableValues.values = ["true", "false"];
648 parameter.signature = this.getSignature(type, this.resource.models);
649 parameter.sampleJSON = this.getSampleJSON(type, this.resource.models);
650 if (parameter["enum"] != null) {
651 parameter.isList = true;
652 parameter.allowableValues = {};
653 parameter.allowableValues.descriptiveValues = [];
654 _ref2 = parameter["enum"];
655 for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
657 if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
658 parameter.allowableValues.descriptiveValues.push({
663 parameter.allowableValues.descriptiveValues.push({
670 if (parameter.allowableValues != null) {
671 if (parameter.allowableValues.valueType === "RANGE") {
672 parameter.isRange = true;
674 parameter.isList = true;
676 if (parameter.allowableValues.values != null) {
677 parameter.allowableValues.descriptiveValues = [];
678 _ref3 = parameter.allowableValues.values;
679 for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
681 if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
682 parameter.allowableValues.descriptiveValues.push({
687 parameter.allowableValues.descriptiveValues.push({
696 this.resource[this.nickname] = function(args, callback, error) {
697 return _this["do"](args, callback, error);
699 this.resource[this.nickname].help = function() {
704 SwaggerOperation.prototype.isListType = function(type) {
705 if (type.indexOf('[') >= 0) {
706 return type.substring(type.indexOf('[') + 1, type.indexOf(']'));
712 SwaggerOperation.prototype.getSignature = function(type, models) {
713 var isPrimitive, listType;
714 listType = this.isListType(type);
715 isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
719 if (listType != null) {
720 return models[listType].getMockSignature();
722 return models[type].getMockSignature();
727 SwaggerOperation.prototype.getSampleJSON = function(type, models) {
728 var isPrimitive, listType, val;
729 listType = this.isListType(type);
730 isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
731 val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[type].createJSONSample());
733 val = listType ? [val] : val;
734 return JSON.stringify(val, null, 2);
738 SwaggerOperation.prototype["do"] = function(args, opts, callback, error) {
739 var key, param, params, possibleParams, req, requestContentType, responseContentType, value, _i, _len, _ref;
746 requestContentType = null;
747 responseContentType = null;
748 if ((typeof args) === "function") {
753 if ((typeof opts) === "function") {
758 error = function(xhr, textStatus, error) {
759 return console.log(xhr, textStatus, error);
762 if (callback == null) {
763 callback = function(data) {
766 if (data.content != null) {
767 content = data.content.data;
771 return console.log("default callback: " + content);
776 if (args.headers != null) {
777 params.headers = args.headers;
780 _ref = this.parameters;
781 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
783 if (param.paramType === "header") {
784 if (args[param.name]) {
785 params.headers[param.name] = args[param.name];
789 if (args.body != null) {
790 params.body = args.body;
793 possibleParams = (function() {
794 var _j, _len1, _ref1, _results;
795 _ref1 = this.parameters;
797 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
799 if (param.paramType === "form" || param.paramType.toLowerCase() === "file") {
800 _results.push(param);
805 if (possibleParams) {
806 for (key in possibleParams) {
807 value = possibleParams[key];
808 if (args[value.name]) {
809 params[value.name] = args[value.name];
813 req = new SwaggerRequest(this.method, this.urlify(args), params, opts, callback, error, this);
814 if (opts.mock != null) {
821 SwaggerOperation.prototype.pathJson = function() {
822 return this.path.replace("{format}", "json");
825 SwaggerOperation.prototype.pathXml = function() {
826 return this.path.replace("{format}", "xml");
829 SwaggerOperation.prototype.urlify = function(args) {
830 var param, queryParams, reg, url, _i, _j, _len, _len1, _ref, _ref1;
831 url = this.resource.basePath + this.pathJson();
832 _ref = this.parameters;
833 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
835 if (param.paramType === 'path') {
836 if (args[param.name]) {
837 reg = new RegExp('\{' + param.name + '[^\}]*\}', 'gi');
838 url = url.replace(reg, encodeURIComponent(args[param.name]));
839 delete args[param.name];
841 throw "" + param.name + " is a required path param.";
846 _ref1 = this.parameters;
847 for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
849 if (param.paramType === 'query') {
850 if (args[param.name]) {
851 if (queryParams !== "") {
854 queryParams += encodeURIComponent(param.name) + '=' + encodeURIComponent(args[param.name]);
858 if ((queryParams != null) && queryParams.length > 0) {
859 url += "?" + queryParams;
864 SwaggerOperation.prototype.supportHeaderParams = function() {
865 return this.resource.api.supportHeaderParams;
868 SwaggerOperation.prototype.supportedSubmitMethods = function() {
869 return this.resource.api.supportedSubmitMethods;
872 SwaggerOperation.prototype.getQueryParams = function(args) {
873 return this.getMatchingParams(['query'], args);
876 SwaggerOperation.prototype.getHeaderParams = function(args) {
877 return this.getMatchingParams(['header'], args);
880 SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args) {
881 var matchingParams, name, param, value, _i, _len, _ref, _ref1;
883 _ref = this.parameters;
884 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
886 if (args && args[param.name]) {
887 matchingParams[param.name] = args[param.name];
890 _ref1 = this.resource.api.headers;
891 for (name in _ref1) {
893 matchingParams[name] = value;
895 return matchingParams;
898 SwaggerOperation.prototype.help = function() {
899 var msg, parameter, _i, _len, _ref;
901 _ref = this.parameters;
902 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
903 parameter = _ref[_i];
907 msg += "* " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description;
912 return SwaggerOperation;
916 SwaggerRequest = (function() {
917 function SwaggerRequest(type, url, params, opts, successCallback, errorCallback, operation, execution) {
918 var body, e, fields, headers, key, myHeaders, name, obj, param, parent, possibleParams, requestContentType, responseContentType, urlEncoded, value, values,
922 this.params = params;
924 this.successCallback = successCallback;
925 this.errorCallback = errorCallback;
926 this.operation = operation;
927 this.execution = execution;
928 if (this.type == null) {
929 throw "SwaggerRequest type is required (get/post/put/delete).";
931 if (this.url == null) {
932 throw "SwaggerRequest url is required.";
934 if (this.successCallback == null) {
935 throw "SwaggerRequest successCallback is required.";
937 if (this.errorCallback == null) {
938 throw "SwaggerRequest error callback is required.";
940 if (this.operation == null) {
941 throw "SwaggerRequest operation is required.";
943 this.type = this.type.toUpperCase();
944 headers = params.headers;
947 parent = params["parent"];
948 requestContentType = "application/json";
949 if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH")) {
950 if (this.opts.requestContentType) {
951 requestContentType = this.opts.requestContentType;
955 var _i, _len, _ref, _results;
956 _ref = this.operation.parameters;
958 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
960 if (param.paramType === "form") {
961 _results.push(param);
965 }).call(this)).length > 0) {
966 type = param.type || param.dataType;
968 var _i, _len, _ref, _results;
969 _ref = this.operation.parameters;
971 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
973 if (type.toLowerCase() === "file") {
974 _results.push(param);
978 }).call(this)).length > 0) {
979 requestContentType = "multipart/form-data";
981 requestContentType = "application/x-www-form-urlencoded";
983 } else if (this.type !== "DELETE") {
984 requestContentType = null;
987 if (requestContentType && this.operation.consumes) {
988 if (this.operation.consumes.indexOf(requestContentType) === -1) {
989 console.log("server doesn't consume " + requestContentType + ", try " + JSON.stringify(this.operation.consumes));
990 if (this.requestContentType === null) {
991 requestContentType = this.operation.consumes[0];
995 responseContentType = null;
996 if (this.type === "POST" || this.type === "GET" || this.type === "PATCH") {
997 if (this.opts.responseContentType) {
998 responseContentType = this.opts.responseContentType;
1000 responseContentType = "application/json";
1003 responseContentType = null;
1005 if (responseContentType && this.operation.produces) {
1006 if (this.operation.produces.indexOf(responseContentType) === -1) {
1007 console.log("server can't produce " + responseContentType);
1010 if (requestContentType && requestContentType.indexOf("application/x-www-form-urlencoded") === 0) {
1012 possibleParams = (function() {
1013 var _i, _len, _ref, _results;
1014 _ref = this.operation.parameters;
1016 for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1018 if (param.paramType === "form") {
1019 _results.push(param);
1025 for (key in possibleParams) {
1026 value = possibleParams[key];
1027 if (this.params[value.name]) {
1028 values[value.name] = this.params[value.name];
1032 for (key in values) {
1033 value = values[key];
1034 if (urlEncoded !== "") {
1037 urlEncoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
1041 for (name in headers) {
1042 myHeaders[name] = headers[name];
1044 if (requestContentType) {
1045 myHeaders["Content-Type"] = requestContentType;
1047 if (responseContentType) {
1048 myHeaders["Accept"] = responseContentType;
1050 if (!((headers != null) && (headers.mock != null))) {
1057 error: function(response) {
1058 return _this.errorCallback(response, _this.opts.parent);
1060 redirect: function(response) {
1061 return _this.successCallback(response, _this.opts.parent);
1063 307: function(response) {
1064 return _this.successCallback(response, _this.opts.parent);
1066 response: function(response) {
1067 return _this.successCallback(response, _this.opts.parent);
1072 if (typeof window !== 'undefined') {
1077 e.authorizations.apply(obj);
1078 if (opts.mock == null) {
1079 new SwaggerHttp().execute(obj);
1087 SwaggerRequest.prototype.asCurl = function() {
1088 var header_args, k, v;
1089 header_args = (function() {
1091 _ref = this.headers;
1095 _results.push("--header \"" + k + ": " + v + "\"");
1099 return "curl " + (header_args.join(" ")) + " " + this.url;
1102 return SwaggerRequest;
1106 SwaggerHttp = (function() {
1107 SwaggerHttp.prototype.Shred = null;
1109 SwaggerHttp.prototype.shred = null;
1111 SwaggerHttp.prototype.content = null;
1113 function SwaggerHttp() {
1114 var identity, toString,
1116 if (typeof window !== 'undefined') {
1117 this.Shred = require("./shred");
1119 this.Shred = require("shred");
1121 this.shred = new this.Shred();
1122 identity = function(x) {
1125 toString = function(x) {
1126 return x.toString();
1128 if (typeof window !== 'undefined') {
1129 this.content = require("./shred/content");
1130 this.content.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
1135 this.Shred.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
1142 SwaggerHttp.prototype.execute = function(obj) {
1143 return this.shred.request(obj);
1150 SwaggerAuthorizations = (function() {
1151 SwaggerAuthorizations.prototype.authz = null;
1153 function SwaggerAuthorizations() {
1157 SwaggerAuthorizations.prototype.add = function(name, auth) {
1158 this.authz[name] = auth;
1162 SwaggerAuthorizations.prototype.apply = function(obj) {
1163 var key, value, _ref, _results;
1168 _results.push(value.apply(obj));
1173 return SwaggerAuthorizations;
1177 ApiKeyAuthorization = (function() {
1178 ApiKeyAuthorization.prototype.type = null;
1180 ApiKeyAuthorization.prototype.name = null;
1182 ApiKeyAuthorization.prototype.value = null;
1184 function ApiKeyAuthorization(name, value, type) {
1190 ApiKeyAuthorization.prototype.apply = function(obj) {
1191 if (this.type === "query") {
1192 if (obj.url.indexOf('?') > 0) {
1193 obj.url = obj.url + "&" + this.name + "=" + this.value;
1195 obj.url = obj.url + "?" + this.name + "=" + this.value;
1198 } else if (this.type === "header") {
1199 return obj.headers[this.name] = this.value;
1203 return ApiKeyAuthorization;
1207 PasswordAuthorization = (function() {
1208 PasswordAuthorization.prototype.name = null;
1210 PasswordAuthorization.prototype.username = null;
1212 PasswordAuthorization.prototype.password = null;
1214 function PasswordAuthorization(name, username, password) {
1216 this.username = username;
1217 this.password = password;
1220 PasswordAuthorization.prototype.apply = function(obj) {
1221 return obj.headers["Authorization"] = "Basic " + btoa(this.username + ":" + this.password);
1224 return PasswordAuthorization;
1228 this.SwaggerApi = SwaggerApi;
1230 this.SwaggerResource = SwaggerResource;
1232 this.SwaggerOperation = SwaggerOperation;
1234 this.SwaggerRequest = SwaggerRequest;
1236 this.SwaggerModelProperty = SwaggerModelProperty;
1238 this.ApiKeyAuthorization = ApiKeyAuthorization;
1240 this.PasswordAuthorization = PasswordAuthorization;
1242 this.authorizations = new SwaggerAuthorizations();