Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

773 lignes
27 KiB

  1. // Generated by CoffeeScript 1.4.0
  2. (function() {
  3. var SwaggerApi, SwaggerModel, SwaggerModelProperty, SwaggerOperation, SwaggerRequest, SwaggerResource,
  4. __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  5. SwaggerApi = (function() {
  6. SwaggerApi.prototype.discoveryUrl = "http://api.wordnik.com/v4/resources.json";
  7. SwaggerApi.prototype.debug = false;
  8. SwaggerApi.prototype.api_key = null;
  9. SwaggerApi.prototype.basePath = null;
  10. function SwaggerApi(options) {
  11. if (options == null) {
  12. options = {};
  13. }
  14. if (options.discoveryUrl != null) {
  15. this.discoveryUrl = options.discoveryUrl;
  16. }
  17. if (options.debug != null) {
  18. this.debug = options.debug;
  19. }
  20. this.apiKeyName = options.apiKeyName != null ? options.apiKeyName : 'api_key';
  21. if (options.apiKey != null) {
  22. this.api_key = options.apiKey;
  23. }
  24. if (options.api_key != null) {
  25. this.api_key = options.api_key;
  26. }
  27. if (options.verbose != null) {
  28. this.verbose = options.verbose;
  29. }
  30. this.supportHeaderParams = options.supportHeaderParams != null ? options.supportHeaderParams : false;
  31. this.supportedSubmitMethods = options.supportedSubmitMethods != null ? options.supportedSubmitMethods : ['get'];
  32. if (options.success != null) {
  33. this.success = options.success;
  34. }
  35. this.failure = options.failure != null ? options.failure : function() {};
  36. this.progress = options.progress != null ? options.progress : function() {};
  37. this.headers = options.headers != null ? options.headers : {};
  38. this.booleanValues = options.booleanValues != null ? options.booleanValues : new Array('true', 'false');
  39. this.discoveryUrl = this.suffixApiKey(this.discoveryUrl);
  40. if (options.success != null) {
  41. this.build();
  42. }
  43. }
  44. SwaggerApi.prototype.build = function() {
  45. var _this = this;
  46. this.progress('fetching resource list: ' + this.discoveryUrl);
  47. return jQuery.getJSON(this.discoveryUrl, function(response) {
  48. var res, resource, _i, _j, _len, _len1, _ref, _ref1;
  49. if (response.apiVersion != null) {
  50. _this.apiVersion = response.apiVersion;
  51. }
  52. if ((response.basePath != null) && jQuery.trim(response.basePath).length > 0) {
  53. _this.basePath = response.basePath;
  54. if (_this.basePath.match(/^HTTP/i) == null) {
  55. _this.fail("discoveryUrl basePath must be a URL.");
  56. }
  57. _this.basePath = _this.basePath.replace(/\/$/, '');
  58. } else {
  59. _this.basePath = _this.discoveryUrl.substring(0, _this.discoveryUrl.lastIndexOf('/'));
  60. log('derived basepath from discoveryUrl as ' + _this.basePath);
  61. }
  62. _this.apis = {};
  63. _this.apisArray = [];
  64. if (response.resourcePath != null) {
  65. _this.resourcePath = response.resourcePath;
  66. res = null;
  67. _ref = response.apis;
  68. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  69. resource = _ref[_i];
  70. if (res === null) {
  71. res = new SwaggerResource(resource, _this);
  72. } else {
  73. res.addOperations(resource.path, resource.operations);
  74. }
  75. }
  76. if (res != null) {
  77. _this.apis[res.name] = res;
  78. _this.apisArray.push(res);
  79. res.ready = true;
  80. _this.selfReflect();
  81. }
  82. } else {
  83. _ref1 = response.apis;
  84. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  85. resource = _ref1[_j];
  86. res = new SwaggerResource(resource, _this);
  87. _this.apis[res.name] = res;
  88. _this.apisArray.push(res);
  89. }
  90. }
  91. return _this;
  92. }).error(function(error) {
  93. if (_this.discoveryUrl.substring(0, 4) !== 'http') {
  94. return _this.fail('Please specify the protocol for ' + _this.discoveryUrl);
  95. } else if (error.status === 0) {
  96. return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
  97. } else if (error.status === 404) {
  98. return _this.fail('Can\'t read swagger JSON from ' + _this.discoveryUrl);
  99. } else {
  100. return _this.fail(error.status + ' : ' + error.statusText + ' ' + _this.discoveryUrl);
  101. }
  102. });
  103. };
  104. SwaggerApi.prototype.selfReflect = function() {
  105. var resource, resource_name, _ref;
  106. if (this.apis == null) {
  107. return false;
  108. }
  109. _ref = this.apis;
  110. for (resource_name in _ref) {
  111. resource = _ref[resource_name];
  112. if (resource.ready == null) {
  113. return false;
  114. }
  115. }
  116. this.setConsolidatedModels();
  117. this.ready = true;
  118. if (this.success != null) {
  119. return this.success();
  120. }
  121. };
  122. SwaggerApi.prototype.fail = function(message) {
  123. this.failure(message);
  124. throw message;
  125. };
  126. SwaggerApi.prototype.setConsolidatedModels = function() {
  127. var model, modelName, resource, resource_name, _i, _len, _ref, _ref1, _results;
  128. this.modelsArray = [];
  129. this.models = {};
  130. _ref = this.apis;
  131. for (resource_name in _ref) {
  132. resource = _ref[resource_name];
  133. for (modelName in resource.models) {
  134. if (!(this.models[modelName] != null)) {
  135. this.models[modelName] = resource.models[modelName];
  136. this.modelsArray.push(resource.models[modelName]);
  137. }
  138. }
  139. }
  140. _ref1 = this.modelsArray;
  141. _results = [];
  142. for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  143. model = _ref1[_i];
  144. _results.push(model.setReferencedModels(this.models));
  145. }
  146. return _results;
  147. };
  148. SwaggerApi.prototype.suffixApiKey = function(url) {
  149. var sep;
  150. if ((this.api_key != null) && jQuery.trim(this.api_key).length > 0 && (url != null)) {
  151. sep = url.indexOf('?') > 0 ? '&' : '?';
  152. return url + sep + this.apiKeyName + '=' + this.api_key;
  153. } else {
  154. return url;
  155. }
  156. };
  157. SwaggerApi.prototype.help = function() {
  158. var operation, operation_name, parameter, resource, resource_name, _i, _len, _ref, _ref1, _ref2;
  159. _ref = this.apis;
  160. for (resource_name in _ref) {
  161. resource = _ref[resource_name];
  162. console.log(resource_name);
  163. _ref1 = resource.operations;
  164. for (operation_name in _ref1) {
  165. operation = _ref1[operation_name];
  166. console.log(" " + operation.nickname);
  167. _ref2 = operation.parameters;
  168. for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
  169. parameter = _ref2[_i];
  170. console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
  171. }
  172. }
  173. }
  174. return this;
  175. };
  176. return SwaggerApi;
  177. })();
  178. SwaggerResource = (function() {
  179. function SwaggerResource(resourceObj, api) {
  180. var parts,
  181. _this = this;
  182. this.api = api;
  183. this.path = this.api.resourcePath != null ? this.api.resourcePath : resourceObj.path;
  184. this.description = resourceObj.description;
  185. parts = this.path.split("/");
  186. this.name = parts[parts.length - 1].replace('.{format}', '');
  187. this.basePath = this.api.basePath;
  188. this.operations = {};
  189. this.operationsArray = [];
  190. this.modelsArray = [];
  191. this.models = {};
  192. if ((resourceObj.operations != null) && (this.api.resourcePath != null)) {
  193. this.api.progress('reading resource ' + this.name + ' models and operations');
  194. this.addModels(resourceObj.models);
  195. this.addOperations(resourceObj.path, resourceObj.operations);
  196. this.api[this.name] = this;
  197. } else {
  198. if (this.path == null) {
  199. this.api.fail("SwaggerResources must have a path.");
  200. }
  201. this.url = this.api.suffixApiKey(this.api.basePath + this.path.replace('{format}', 'json'));
  202. this.api.progress('fetching resource ' + this.name + ': ' + this.url);
  203. jQuery.getJSON(this.url, function(response) {
  204. var endpoint, _i, _len, _ref;
  205. if ((response.basePath != null) && jQuery.trim(response.basePath).length > 0) {
  206. _this.basePath = response.basePath;
  207. _this.basePath = _this.basePath.replace(/\/$/, '');
  208. }
  209. _this.addModels(response.models);
  210. if (response.apis) {
  211. _ref = response.apis;
  212. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  213. endpoint = _ref[_i];
  214. _this.addOperations(endpoint.path, endpoint.operations);
  215. }
  216. }
  217. _this.api[_this.name] = _this;
  218. _this.ready = true;
  219. return _this.api.selfReflect();
  220. }).error(function(error) {
  221. return _this.api.fail("Unable to read api '" + _this.name + "' from path " + _this.url + " (server returned " + error.statusText + ")");
  222. });
  223. }
  224. }
  225. SwaggerResource.prototype.addModels = function(models) {
  226. var model, modelName, swaggerModel, _i, _len, _ref, _results;
  227. if (models != null) {
  228. for (modelName in models) {
  229. if (!(this.models[modelName] != null)) {
  230. swaggerModel = new SwaggerModel(modelName, models[modelName]);
  231. this.modelsArray.push(swaggerModel);
  232. this.models[modelName] = swaggerModel;
  233. }
  234. }
  235. _ref = this.modelsArray;
  236. _results = [];
  237. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  238. model = _ref[_i];
  239. _results.push(model.setReferencedModels(this.models));
  240. }
  241. return _results;
  242. }
  243. };
  244. SwaggerResource.prototype.addOperations = function(resource_path, ops) {
  245. var consumes, o, op, _i, _len, _results;
  246. if (ops) {
  247. _results = [];
  248. for (_i = 0, _len = ops.length; _i < _len; _i++) {
  249. o = ops[_i];
  250. consumes = o.consumes;
  251. if (o.supportedContentTypes) {
  252. consumes = o.supportedContentTypes;
  253. }
  254. op = new SwaggerOperation(o.nickname, resource_path, o.httpMethod, o.parameters, o.summary, o.notes, o.responseClass, o.errorResponses, this, o.consumes, o.produces);
  255. this.operations[op.nickname] = op;
  256. _results.push(this.operationsArray.push(op));
  257. }
  258. return _results;
  259. }
  260. };
  261. SwaggerResource.prototype.help = function() {
  262. var operation, operation_name, parameter, _i, _len, _ref, _ref1;
  263. _ref = this.operations;
  264. for (operation_name in _ref) {
  265. operation = _ref[operation_name];
  266. console.log(" " + operation.nickname);
  267. _ref1 = operation.parameters;
  268. for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  269. parameter = _ref1[_i];
  270. console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
  271. }
  272. }
  273. return this;
  274. };
  275. return SwaggerResource;
  276. })();
  277. SwaggerModel = (function() {
  278. function SwaggerModel(modelName, obj) {
  279. var propertyName;
  280. this.name = obj.id != null ? obj.id : modelName;
  281. this.properties = [];
  282. for (propertyName in obj.properties) {
  283. this.properties.push(new SwaggerModelProperty(propertyName, obj.properties[propertyName]));
  284. }
  285. }
  286. SwaggerModel.prototype.setReferencedModels = function(allModels) {
  287. var prop, _i, _len, _ref, _results;
  288. _ref = this.properties;
  289. _results = [];
  290. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  291. prop = _ref[_i];
  292. if (allModels[prop.dataType] != null) {
  293. _results.push(prop.refModel = allModels[prop.dataType]);
  294. } else if ((prop.refDataType != null) && (allModels[prop.refDataType] != null)) {
  295. _results.push(prop.refModel = allModels[prop.refDataType]);
  296. } else {
  297. _results.push(void 0);
  298. }
  299. }
  300. return _results;
  301. };
  302. SwaggerModel.prototype.getMockSignature = function(modelsToIgnore) {
  303. var classClose, classOpen, prop, propertiesStr, returnVal, strong, strongClose, stronger, _i, _j, _len, _len1, _ref, _ref1;
  304. propertiesStr = [];
  305. _ref = this.properties;
  306. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  307. prop = _ref[_i];
  308. propertiesStr.push(prop.toString());
  309. }
  310. strong = '<span class="strong">';
  311. stronger = '<span class="stronger">';
  312. strongClose = '</span>';
  313. classOpen = strong + this.name + ' {' + strongClose;
  314. classClose = strong + '}' + strongClose;
  315. returnVal = classOpen + '<div>' + propertiesStr.join(',</div><div>') + '</div>' + classClose;
  316. if (!modelsToIgnore) {
  317. modelsToIgnore = [];
  318. }
  319. modelsToIgnore.push(this);
  320. _ref1 = this.properties;
  321. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  322. prop = _ref1[_j];
  323. if ((prop.refModel != null) && (modelsToIgnore.indexOf(prop.refModel)) === -1) {
  324. returnVal = returnVal + ('<br>' + prop.refModel.getMockSignature(modelsToIgnore));
  325. }
  326. }
  327. return returnVal;
  328. };
  329. SwaggerModel.prototype.createJSONSample = function(modelsToIgnore) {
  330. var prop, result, _i, _len, _ref;
  331. result = {};
  332. modelsToIgnore = modelsToIgnore || [];
  333. modelsToIgnore.push(this.name);
  334. _ref = this.properties;
  335. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  336. prop = _ref[_i];
  337. result[prop.name] = prop.getSampleValue(modelsToIgnore);
  338. }
  339. return result;
  340. };
  341. return SwaggerModel;
  342. })();
  343. SwaggerModelProperty = (function() {
  344. function SwaggerModelProperty(name, obj) {
  345. this.name = name;
  346. this.dataType = obj.type;
  347. this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set');
  348. this.descr = obj.description;
  349. this.required = obj.required;
  350. if (obj.items != null) {
  351. if (obj.items.type != null) {
  352. this.refDataType = obj.items.type;
  353. }
  354. if (obj.items.$ref != null) {
  355. this.refDataType = obj.items.$ref;
  356. }
  357. }
  358. this.dataTypeWithRef = this.refDataType != null ? this.dataType + '[' + this.refDataType + ']' : this.dataType;
  359. if (obj.allowableValues != null) {
  360. this.valueType = obj.allowableValues.valueType;
  361. this.values = obj.allowableValues.values;
  362. if (this.values != null) {
  363. this.valuesString = "'" + this.values.join("' or '") + "'";
  364. }
  365. }
  366. }
  367. SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
  368. var result;
  369. if ((this.refModel != null) && (modelsToIgnore.indexOf(this.refModel.name) === -1)) {
  370. result = this.refModel.createJSONSample(modelsToIgnore);
  371. } else {
  372. if (this.isCollection) {
  373. result = this.refDataType;
  374. } else {
  375. result = this.dataType;
  376. }
  377. }
  378. if (this.isCollection) {
  379. return [result];
  380. } else {
  381. return result;
  382. }
  383. };
  384. SwaggerModelProperty.prototype.toString = function() {
  385. var req, str;
  386. req = this.required ? 'propReq' : 'propOpt';
  387. str = '<span class="propName ' + req + '">' + this.name + '</span> (<span class="propType">' + this.dataTypeWithRef + '</span>';
  388. if (!this.required) {
  389. str += ', <span class="propOptKey">optional</span>';
  390. }
  391. str += ')';
  392. if (this.values != null) {
  393. str += " = <span class='propVals'>['" + this.values.join("' or '") + "']</span>";
  394. }
  395. if (this.descr != null) {
  396. str += ': <span class="propDesc">' + this.descr + '</span>';
  397. }
  398. return str;
  399. };
  400. return SwaggerModelProperty;
  401. })();
  402. SwaggerOperation = (function() {
  403. function SwaggerOperation(nickname, path, httpMethod, parameters, summary, notes, responseClass, errorResponses, resource, consumes, produces) {
  404. var parameter, v, _i, _j, _len, _len1, _ref, _ref1, _ref2,
  405. _this = this;
  406. this.nickname = nickname;
  407. this.path = path;
  408. this.httpMethod = httpMethod;
  409. this.parameters = parameters != null ? parameters : [];
  410. this.summary = summary;
  411. this.notes = notes;
  412. this.responseClass = responseClass;
  413. this.errorResponses = errorResponses;
  414. this.resource = resource;
  415. this.consumes = consumes;
  416. this.produces = produces;
  417. this["do"] = __bind(this["do"], this);
  418. if (this.nickname == null) {
  419. this.resource.api.fail("SwaggerOperations must have a nickname.");
  420. }
  421. if (this.path == null) {
  422. this.resource.api.fail("SwaggerOperation " + nickname + " is missing path.");
  423. }
  424. if (this.httpMethod == null) {
  425. this.resource.api.fail("SwaggerOperation " + nickname + " is missing httpMethod.");
  426. }
  427. this.path = this.path.replace('{format}', 'json');
  428. this.httpMethod = this.httpMethod.toLowerCase();
  429. this.isGetMethod = this.httpMethod === "get";
  430. this.resourceName = this.resource.name;
  431. if (((_ref = this.responseClass) != null ? _ref.toLowerCase() : void 0) === 'void') {
  432. this.responseClass = void 0;
  433. }
  434. if (this.responseClass != null) {
  435. this.responseClassSignature = this.getSignature(this.responseClass, this.resource.models);
  436. this.responseSampleJSON = this.getSampleJSON(this.responseClass, this.resource.models);
  437. }
  438. this.errorResponses = this.errorResponses || [];
  439. _ref1 = this.parameters;
  440. for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  441. parameter = _ref1[_i];
  442. parameter.name = parameter.name || parameter.dataType;
  443. if (parameter.dataType.toLowerCase() === 'boolean') {
  444. parameter.allowableValues = {};
  445. parameter.allowableValues.values = this.resource.api.booleanValues;
  446. }
  447. parameter.signature = this.getSignature(parameter.dataType, this.resource.models);
  448. parameter.sampleJSON = this.getSampleJSON(parameter.dataType, this.resource.models);
  449. if (parameter.allowableValues != null) {
  450. if (parameter.allowableValues.valueType === "RANGE") {
  451. parameter.isRange = true;
  452. } else {
  453. parameter.isList = true;
  454. }
  455. if (parameter.allowableValues.values != null) {
  456. parameter.allowableValues.descriptiveValues = [];
  457. _ref2 = parameter.allowableValues.values;
  458. for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
  459. v = _ref2[_j];
  460. if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
  461. parameter.allowableValues.descriptiveValues.push({
  462. value: v,
  463. isDefault: true
  464. });
  465. } else {
  466. parameter.allowableValues.descriptiveValues.push({
  467. value: v,
  468. isDefault: false
  469. });
  470. }
  471. }
  472. }
  473. }
  474. }
  475. this.resource[this.nickname] = function(args, callback, error) {
  476. return _this["do"](args, callback, error);
  477. };
  478. }
  479. SwaggerOperation.prototype.isListType = function(dataType) {
  480. if (dataType.indexOf('[') >= 0) {
  481. return dataType.substring(dataType.indexOf('[') + 1, dataType.indexOf(']'));
  482. } else {
  483. return void 0;
  484. }
  485. };
  486. SwaggerOperation.prototype.getSignature = function(dataType, models) {
  487. var isPrimitive, listType;
  488. listType = this.isListType(dataType);
  489. isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true;
  490. if (isPrimitive) {
  491. return dataType;
  492. } else {
  493. if (listType != null) {
  494. return models[listType].getMockSignature();
  495. } else {
  496. return models[dataType].getMockSignature();
  497. }
  498. }
  499. };
  500. SwaggerOperation.prototype.getSampleJSON = function(dataType, models) {
  501. var isPrimitive, listType, val;
  502. listType = this.isListType(dataType);
  503. isPrimitive = ((listType != null) && models[listType]) || (models[dataType] != null) ? false : true;
  504. val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[dataType].createJSONSample());
  505. if (val) {
  506. val = listType ? [val] : val;
  507. return JSON.stringify(val, null, 2);
  508. }
  509. };
  510. SwaggerOperation.prototype["do"] = function(args, callback, error) {
  511. var body, headers;
  512. if (args == null) {
  513. args = {};
  514. }
  515. if ((typeof args) === "function") {
  516. error = callback;
  517. callback = args;
  518. args = {};
  519. }
  520. if (error == null) {
  521. error = function(xhr, textStatus, error) {
  522. return console.log(xhr, textStatus, error);
  523. };
  524. }
  525. if (callback == null) {
  526. callback = function(data) {
  527. return console.log(data);
  528. };
  529. }
  530. if (args.headers != null) {
  531. headers = args.headers;
  532. delete args.headers;
  533. }
  534. if (args.body != null) {
  535. body = args.body;
  536. delete args.body;
  537. }
  538. return new SwaggerRequest(this.httpMethod, this.urlify(args), headers, body, callback, error, this);
  539. };
  540. SwaggerOperation.prototype.pathJson = function() {
  541. return this.path.replace("{format}", "json");
  542. };
  543. SwaggerOperation.prototype.pathXml = function() {
  544. return this.path.replace("{format}", "xml");
  545. };
  546. SwaggerOperation.prototype.urlify = function(args, includeApiKey) {
  547. var param, queryParams, reg, url, _i, _len, _ref;
  548. if (includeApiKey == null) {
  549. includeApiKey = true;
  550. }
  551. url = this.resource.basePath + this.pathJson();
  552. _ref = this.parameters;
  553. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  554. param = _ref[_i];
  555. if (param.paramType === 'path') {
  556. if (args[param.name]) {
  557. reg = new RegExp('\{' + param.name + '[^\}]*\}', 'gi');
  558. url = url.replace(reg, encodeURIComponent(args[param.name]));
  559. delete args[param.name];
  560. } else {
  561. throw "" + param.name + " is a required path param.";
  562. }
  563. }
  564. }
  565. if (includeApiKey && (this.resource.api.api_key != null) && this.resource.api.api_key.length > 0) {
  566. args[this.apiKeyName] = this.resource.api.api_key;
  567. }
  568. if (this.supportHeaderParams()) {
  569. queryParams = jQuery.param(this.getQueryParams(args, includeApiKey));
  570. } else {
  571. queryParams = jQuery.param(this.getQueryAndHeaderParams(args, includeApiKey));
  572. }
  573. if ((queryParams != null) && queryParams.length > 0) {
  574. url += "?" + queryParams;
  575. }
  576. return url;
  577. };
  578. SwaggerOperation.prototype.supportHeaderParams = function() {
  579. return this.resource.api.supportHeaderParams;
  580. };
  581. SwaggerOperation.prototype.supportedSubmitMethods = function() {
  582. return this.resource.api.supportedSubmitMethods;
  583. };
  584. SwaggerOperation.prototype.getQueryAndHeaderParams = function(args, includeApiKey) {
  585. if (includeApiKey == null) {
  586. includeApiKey = true;
  587. }
  588. return this.getMatchingParams(['query', 'header'], args, includeApiKey);
  589. };
  590. SwaggerOperation.prototype.getQueryParams = function(args, includeApiKey) {
  591. if (includeApiKey == null) {
  592. includeApiKey = true;
  593. }
  594. return this.getMatchingParams(['query'], args, includeApiKey);
  595. };
  596. SwaggerOperation.prototype.getHeaderParams = function(args, includeApiKey) {
  597. if (includeApiKey == null) {
  598. includeApiKey = true;
  599. }
  600. return this.getMatchingParams(['header'], args, includeApiKey);
  601. };
  602. SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args, includeApiKey) {
  603. var matchingParams, name, param, value, _i, _len, _ref, _ref1;
  604. matchingParams = {};
  605. _ref = this.parameters;
  606. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  607. param = _ref[_i];
  608. if ((jQuery.inArray(param.paramType, paramTypes) >= 0) && args[param.name]) {
  609. matchingParams[param.name] = args[param.name];
  610. }
  611. }
  612. if (includeApiKey && (this.resource.api.api_key != null) && this.resource.api.api_key.length > 0) {
  613. matchingParams[this.resource.api.apiKeyName] = this.resource.api.api_key;
  614. }
  615. if (jQuery.inArray('header', paramTypes) >= 0) {
  616. _ref1 = this.resource.api.headers;
  617. for (name in _ref1) {
  618. value = _ref1[name];
  619. matchingParams[name] = value;
  620. }
  621. }
  622. return matchingParams;
  623. };
  624. SwaggerOperation.prototype.help = function() {
  625. var parameter, _i, _len, _ref;
  626. _ref = this.parameters;
  627. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  628. parameter = _ref[_i];
  629. console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
  630. }
  631. return this;
  632. };
  633. return SwaggerOperation;
  634. })();
  635. SwaggerRequest = (function() {
  636. function SwaggerRequest(type, url, headers, body, successCallback, errorCallback, operation) {
  637. var obj,
  638. _this = this;
  639. this.type = type;
  640. this.url = url;
  641. this.headers = headers;
  642. this.body = body;
  643. this.successCallback = successCallback;
  644. this.errorCallback = errorCallback;
  645. this.operation = operation;
  646. if (this.type == null) {
  647. throw "SwaggerRequest type is required (get/post/put/delete).";
  648. }
  649. if (this.url == null) {
  650. throw "SwaggerRequest url is required.";
  651. }
  652. if (this.successCallback == null) {
  653. throw "SwaggerRequest successCallback is required.";
  654. }
  655. if (this.errorCallback == null) {
  656. throw "SwaggerRequest error callback is required.";
  657. }
  658. if (this.operation == null) {
  659. throw "SwaggerRequest operation is required.";
  660. }
  661. if (this.operation.resource.api.verbose) {
  662. console.log(this.asCurl());
  663. }
  664. this.headers || (this.headers = {});
  665. if (this.operation.resource.api.api_key != null) {
  666. this.headers[this.apiKeyName] = this.operation.resource.api.api_key;
  667. }
  668. if (this.headers.mock == null) {
  669. obj = {
  670. type: this.type,
  671. url: this.url,
  672. data: JSON.stringify(this.body),
  673. dataType: 'json',
  674. error: function(xhr, textStatus, error) {
  675. return _this.errorCallback(xhr, textStatus, error);
  676. },
  677. success: function(data) {
  678. return _this.successCallback(data);
  679. }
  680. };
  681. if (obj.type.toLowerCase() === "post" || obj.type.toLowerCase() === "put") {
  682. obj.contentType = "application/json";
  683. }
  684. jQuery.ajax(obj);
  685. }
  686. }
  687. SwaggerRequest.prototype.asCurl = function() {
  688. var header_args, k, v;
  689. header_args = (function() {
  690. var _ref, _results;
  691. _ref = this.headers;
  692. _results = [];
  693. for (k in _ref) {
  694. v = _ref[k];
  695. _results.push("--header \"" + k + ": " + v + "\"");
  696. }
  697. return _results;
  698. }).call(this);
  699. return "curl " + (header_args.join(" ")) + " " + this.url;
  700. };
  701. return SwaggerRequest;
  702. })();
  703. window.SwaggerApi = SwaggerApi;
  704. window.SwaggerResource = SwaggerResource;
  705. window.SwaggerOperation = SwaggerOperation;
  706. window.SwaggerRequest = SwaggerRequest;
  707. window.SwaggerModelProperty = SwaggerModelProperty;
  708. }).call(this);