Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

1245 wiersze
40 KiB

  1. // Generated by CoffeeScript 1.6.3
  2. (function() {
  3. var ApiKeyAuthorization, PasswordAuthorization, SwaggerApi, SwaggerAuthorizations, SwaggerHttp, SwaggerModel, SwaggerModelProperty, SwaggerOperation, SwaggerRequest, SwaggerResource,
  4. __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
  5. SwaggerApi = (function() {
  6. SwaggerApi.prototype.url = "http://api.wordnik.com/v4/resources.json";
  7. SwaggerApi.prototype.debug = false;
  8. SwaggerApi.prototype.basePath = null;
  9. SwaggerApi.prototype.authorizations = null;
  10. SwaggerApi.prototype.authorizationScheme = null;
  11. SwaggerApi.prototype.info = null;
  12. function SwaggerApi(url, options) {
  13. if (options == null) {
  14. options = {};
  15. }
  16. if (url) {
  17. if (url.url) {
  18. options = url;
  19. } else {
  20. this.url = url;
  21. }
  22. } else {
  23. options = url;
  24. }
  25. if (options.url != null) {
  26. this.url = options.url;
  27. }
  28. if (options.success != null) {
  29. this.success = options.success;
  30. }
  31. this.failure = options.failure != null ? options.failure : function() {};
  32. this.progress = options.progress != null ? options.progress : function() {};
  33. if (options.success != null) {
  34. this.build();
  35. }
  36. }
  37. SwaggerApi.prototype.build = function() {
  38. var e, obj,
  39. _this = this;
  40. this.progress('fetching resource list: ' + this.url);
  41. obj = {
  42. url: this.url,
  43. method: "get",
  44. headers: {},
  45. on: {
  46. error: function(response) {
  47. if (_this.url.substring(0, 4) !== 'http') {
  48. return _this.fail('Please specify the protocol for ' + _this.url);
  49. } else if (response.status === 0) {
  50. return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
  51. } else if (response.status === 404) {
  52. return _this.fail('Can\'t read swagger JSON from ' + _this.url);
  53. } else {
  54. return _this.fail(response.status + ' : ' + response.statusText + ' ' + _this.url);
  55. }
  56. },
  57. response: function(rawResponse) {
  58. var response;
  59. response = JSON.parse(rawResponse.content.data);
  60. _this.swaggerVersion = response.swaggerVersion;
  61. if (_this.swaggerVersion === "1.2") {
  62. return _this.buildFromSpec(response);
  63. } else {
  64. return _this.buildFrom1_1Spec(response);
  65. }
  66. }
  67. }
  68. };
  69. e = {};
  70. if (typeof window !== 'undefined') {
  71. e = window;
  72. } else {
  73. e = exports;
  74. }
  75. e.authorizations.apply(obj);
  76. new SwaggerHttp().execute(obj);
  77. return this;
  78. };
  79. SwaggerApi.prototype.buildFromSpec = function(response) {
  80. var api, isApi, newName, operation, res, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
  81. if (response.apiVersion != null) {
  82. this.apiVersion = response.apiVersion;
  83. }
  84. this.apis = {};
  85. this.apisArray = [];
  86. this.produces = response.produces;
  87. this.authSchemes = response.authorizations;
  88. if (response.info != null) {
  89. this.info = response.info;
  90. }
  91. isApi = false;
  92. _ref = response.apis;
  93. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  94. api = _ref[_i];
  95. if (api.operations) {
  96. _ref1 = api.operations;
  97. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  98. operation = _ref1[_j];
  99. isApi = true;
  100. }
  101. }
  102. }
  103. if (response.basePath) {
  104. this.basePath = response.basePath;
  105. } else if (this.url.indexOf('?') > 0) {
  106. this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
  107. } else {
  108. this.basePath = this.url;
  109. }
  110. if (isApi) {
  111. newName = response.resourcePath.replace(/\//g, '');
  112. this.resourcePath = response.resourcePath;
  113. res = new SwaggerResource(response, this);
  114. this.apis[newName] = res;
  115. this.apisArray.push(res);
  116. } else {
  117. _ref2 = response.apis;
  118. for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
  119. resource = _ref2[_k];
  120. res = new SwaggerResource(resource, this);
  121. this.apis[res.name] = res;
  122. this.apisArray.push(res);
  123. }
  124. }
  125. if (this.success) {
  126. this.success();
  127. }
  128. return this;
  129. };
  130. SwaggerApi.prototype.buildFrom1_1Spec = function(response) {
  131. var api, isApi, newName, operation, res, resource, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2;
  132. console.log("This API is using a deprecated version of Swagger! Please see http://github.com/wordnik/swagger-core/wiki for more info");
  133. if (response.apiVersion != null) {
  134. this.apiVersion = response.apiVersion;
  135. }
  136. this.apis = {};
  137. this.apisArray = [];
  138. this.produces = response.produces;
  139. if (response.info != null) {
  140. this.info = response.info;
  141. }
  142. isApi = false;
  143. _ref = response.apis;
  144. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  145. api = _ref[_i];
  146. if (api.operations) {
  147. _ref1 = api.operations;
  148. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  149. operation = _ref1[_j];
  150. isApi = true;
  151. }
  152. }
  153. }
  154. if (response.basePath) {
  155. this.basePath = response.basePath;
  156. } else if (this.url.indexOf('?') > 0) {
  157. this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
  158. } else {
  159. this.basePath = this.url;
  160. }
  161. if (isApi) {
  162. newName = response.resourcePath.replace(/\//g, '');
  163. this.resourcePath = response.resourcePath;
  164. res = new SwaggerResource(response, this);
  165. this.apis[newName] = res;
  166. this.apisArray.push(res);
  167. } else {
  168. _ref2 = response.apis;
  169. for (_k = 0, _len2 = _ref2.length; _k < _len2; _k++) {
  170. resource = _ref2[_k];
  171. res = new SwaggerResource(resource, this);
  172. this.apis[res.name] = res;
  173. this.apisArray.push(res);
  174. }
  175. }
  176. if (this.success) {
  177. this.success();
  178. }
  179. return this;
  180. };
  181. SwaggerApi.prototype.selfReflect = function() {
  182. var resource, resource_name, _ref;
  183. if (this.apis == null) {
  184. return false;
  185. }
  186. _ref = this.apis;
  187. for (resource_name in _ref) {
  188. resource = _ref[resource_name];
  189. if (resource.ready == null) {
  190. return false;
  191. }
  192. }
  193. this.setConsolidatedModels();
  194. this.ready = true;
  195. if (this.success != null) {
  196. return this.success();
  197. }
  198. };
  199. SwaggerApi.prototype.fail = function(message) {
  200. this.failure(message);
  201. throw message;
  202. };
  203. SwaggerApi.prototype.setConsolidatedModels = function() {
  204. var model, modelName, resource, resource_name, _i, _len, _ref, _ref1, _results;
  205. this.modelsArray = [];
  206. this.models = {};
  207. _ref = this.apis;
  208. for (resource_name in _ref) {
  209. resource = _ref[resource_name];
  210. for (modelName in resource.models) {
  211. if (this.models[modelName] == null) {
  212. this.models[modelName] = resource.models[modelName];
  213. this.modelsArray.push(resource.models[modelName]);
  214. }
  215. }
  216. }
  217. _ref1 = this.modelsArray;
  218. _results = [];
  219. for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  220. model = _ref1[_i];
  221. _results.push(model.setReferencedModels(this.models));
  222. }
  223. return _results;
  224. };
  225. SwaggerApi.prototype.help = function() {
  226. var operation, operation_name, parameter, resource, resource_name, _i, _len, _ref, _ref1, _ref2;
  227. _ref = this.apis;
  228. for (resource_name in _ref) {
  229. resource = _ref[resource_name];
  230. console.log(resource_name);
  231. _ref1 = resource.operations;
  232. for (operation_name in _ref1) {
  233. operation = _ref1[operation_name];
  234. console.log(" " + operation.nickname);
  235. _ref2 = operation.parameters;
  236. for (_i = 0, _len = _ref2.length; _i < _len; _i++) {
  237. parameter = _ref2[_i];
  238. console.log(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
  239. }
  240. }
  241. }
  242. return this;
  243. };
  244. return SwaggerApi;
  245. })();
  246. SwaggerResource = (function() {
  247. SwaggerResource.prototype.api = null;
  248. SwaggerResource.prototype.produces = null;
  249. SwaggerResource.prototype.consumes = null;
  250. function SwaggerResource(resourceObj, api) {
  251. var consumes, e, obj, parts, produces,
  252. _this = this;
  253. this.api = api;
  254. this.api = this.api;
  255. produces = [];
  256. consumes = [];
  257. this.path = this.api.resourcePath != null ? this.api.resourcePath : resourceObj.path;
  258. this.description = resourceObj.description;
  259. parts = this.path.split("/");
  260. this.name = parts[parts.length - 1].replace('.{format}', '');
  261. this.basePath = this.api.basePath;
  262. this.operations = {};
  263. this.operationsArray = [];
  264. this.modelsArray = [];
  265. this.models = {};
  266. if ((resourceObj.apis != null) && (this.api.resourcePath != null)) {
  267. this.addApiDeclaration(resourceObj);
  268. } else {
  269. if (this.path == null) {
  270. this.api.fail("SwaggerResources must have a path.");
  271. }
  272. if (this.path.substring(0, 4) === 'http') {
  273. this.url = this.path.replace('{format}', 'json');
  274. } else {
  275. this.url = this.api.basePath + this.path.replace('{format}', 'json');
  276. }
  277. this.api.progress('fetching resource ' + this.name + ': ' + this.url);
  278. obj = {
  279. url: this.url,
  280. method: "get",
  281. headers: {},
  282. on: {
  283. error: function(response) {
  284. return _this.api.fail("Unable to read api '" + _this.name + "' from path " + _this.url + " (server returned " + response.statusText + ")");
  285. },
  286. response: function(rawResponse) {
  287. var response;
  288. response = JSON.parse(rawResponse.content.data);
  289. return _this.addApiDeclaration(response);
  290. }
  291. }
  292. };
  293. e = {};
  294. if (typeof window !== 'undefined') {
  295. e = window;
  296. } else {
  297. e = exports;
  298. }
  299. e.authorizations.apply(obj);
  300. new SwaggerHttp().execute(obj);
  301. }
  302. }
  303. SwaggerResource.prototype.addApiDeclaration = function(response) {
  304. var endpoint, _i, _len, _ref;
  305. if (response.produces != null) {
  306. this.produces = response.produces;
  307. }
  308. if (response.consumes != null) {
  309. this.consumes = response.consumes;
  310. }
  311. if ((response.basePath != null) && response.basePath.replace(/\s/g, '').length > 0) {
  312. this.basePath = response.basePath;
  313. }
  314. this.addModels(response.models);
  315. if (response.apis) {
  316. _ref = response.apis;
  317. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  318. endpoint = _ref[_i];
  319. this.addOperations(endpoint.path, endpoint.operations, response.consumes, response.produces);
  320. }
  321. }
  322. this.api[this.name] = this;
  323. this.ready = true;
  324. return this.api.selfReflect();
  325. };
  326. SwaggerResource.prototype.addModels = function(models) {
  327. var model, modelName, swaggerModel, _i, _len, _ref, _results;
  328. if (models != null) {
  329. for (modelName in models) {
  330. if (this.models[modelName] == null) {
  331. swaggerModel = new SwaggerModel(modelName, models[modelName]);
  332. this.modelsArray.push(swaggerModel);
  333. this.models[modelName] = swaggerModel;
  334. }
  335. }
  336. _ref = this.modelsArray;
  337. _results = [];
  338. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  339. model = _ref[_i];
  340. _results.push(model.setReferencedModels(this.models));
  341. }
  342. return _results;
  343. }
  344. };
  345. SwaggerResource.prototype.addOperations = function(resource_path, ops, consumes, produces) {
  346. var method, o, op, r, ref, responseMessages, type, _i, _j, _len, _len1, _results;
  347. if (ops) {
  348. _results = [];
  349. for (_i = 0, _len = ops.length; _i < _len; _i++) {
  350. o = ops[_i];
  351. consumes = this.consumes;
  352. produces = this.produces;
  353. if (o.consumes != null) {
  354. consumes = o.consumes;
  355. } else {
  356. consumes = this.consumes;
  357. }
  358. if (o.produces != null) {
  359. produces = o.produces;
  360. } else {
  361. produces = this.produces;
  362. }
  363. type = o.type || o.responseClass;
  364. if (type === "array") {
  365. ref = null;
  366. if (o.items) {
  367. ref = o.items["type"] || o.items["$ref"];
  368. }
  369. type = "array[" + ref + "]";
  370. }
  371. responseMessages = o.responseMessages;
  372. method = o.method;
  373. if (o.httpMethod) {
  374. method = o.httpMethod;
  375. }
  376. if (o.supportedContentTypes) {
  377. consumes = o.supportedContentTypes;
  378. }
  379. if (o.errorResponses) {
  380. responseMessages = o.errorResponses;
  381. for (_j = 0, _len1 = responseMessages.length; _j < _len1; _j++) {
  382. r = responseMessages[_j];
  383. r.message = r.reason;
  384. r.reason = null;
  385. }
  386. }
  387. o.nickname = this.sanitize(o.nickname);
  388. op = new SwaggerOperation(o.nickname, resource_path, method, o.parameters, o.summary, o.notes, type, responseMessages, this, consumes, produces);
  389. this.operations[op.nickname] = op;
  390. _results.push(this.operationsArray.push(op));
  391. }
  392. return _results;
  393. }
  394. };
  395. SwaggerResource.prototype.sanitize = function(nickname) {
  396. var op;
  397. op = nickname.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|./?,\\'""-]/g, '_');
  398. op = op.replace(/((_){2,})/g, '_');
  399. op = op.replace(/^(_)*/g, '');
  400. op = op.replace(/([_])*$/g, '');
  401. return op;
  402. };
  403. SwaggerResource.prototype.help = function() {
  404. var msg, operation, operation_name, parameter, _i, _len, _ref, _ref1, _results;
  405. _ref = this.operations;
  406. _results = [];
  407. for (operation_name in _ref) {
  408. operation = _ref[operation_name];
  409. msg = " " + operation.nickname;
  410. _ref1 = operation.parameters;
  411. for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  412. parameter = _ref1[_i];
  413. msg.concat(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
  414. }
  415. _results.push(msg);
  416. }
  417. return _results;
  418. };
  419. return SwaggerResource;
  420. })();
  421. SwaggerModel = (function() {
  422. function SwaggerModel(modelName, obj) {
  423. var prop, propertyName, value;
  424. this.name = obj.id != null ? obj.id : modelName;
  425. this.properties = [];
  426. for (propertyName in obj.properties) {
  427. if (obj.required != null) {
  428. for (value in obj.required) {
  429. if (propertyName === obj.required[value]) {
  430. obj.properties[propertyName].required = true;
  431. }
  432. }
  433. }
  434. prop = new SwaggerModelProperty(propertyName, obj.properties[propertyName]);
  435. this.properties.push(prop);
  436. }
  437. }
  438. SwaggerModel.prototype.setReferencedModels = function(allModels) {
  439. var prop, type, _i, _len, _ref, _results;
  440. _ref = this.properties;
  441. _results = [];
  442. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  443. prop = _ref[_i];
  444. type = prop.type || prop.dataType;
  445. if (allModels[type] != null) {
  446. _results.push(prop.refModel = allModels[type]);
  447. } else if ((prop.refDataType != null) && (allModels[prop.refDataType] != null)) {
  448. _results.push(prop.refModel = allModels[prop.refDataType]);
  449. } else {
  450. _results.push(void 0);
  451. }
  452. }
  453. return _results;
  454. };
  455. SwaggerModel.prototype.getMockSignature = function(modelsToIgnore) {
  456. var classClose, classOpen, prop, propertiesStr, returnVal, strong, strongClose, stronger, _i, _j, _len, _len1, _ref, _ref1;
  457. propertiesStr = [];
  458. _ref = this.properties;
  459. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  460. prop = _ref[_i];
  461. propertiesStr.push(prop.toString());
  462. }
  463. strong = '<span class="strong">';
  464. stronger = '<span class="stronger">';
  465. strongClose = '</span>';
  466. classOpen = strong + this.name + ' {' + strongClose;
  467. classClose = strong + '}' + strongClose;
  468. returnVal = classOpen + '<div>' + propertiesStr.join(',</div><div>') + '</div>' + classClose;
  469. if (!modelsToIgnore) {
  470. modelsToIgnore = [];
  471. }
  472. modelsToIgnore.push(this);
  473. _ref1 = this.properties;
  474. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  475. prop = _ref1[_j];
  476. if ((prop.refModel != null) && (modelsToIgnore.indexOf(prop.refModel)) === -1) {
  477. returnVal = returnVal + ('<br>' + prop.refModel.getMockSignature(modelsToIgnore));
  478. }
  479. }
  480. return returnVal;
  481. };
  482. SwaggerModel.prototype.createJSONSample = function(modelsToIgnore) {
  483. var prop, result, _i, _len, _ref;
  484. result = {};
  485. modelsToIgnore = modelsToIgnore || [];
  486. modelsToIgnore.push(this.name);
  487. _ref = this.properties;
  488. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  489. prop = _ref[_i];
  490. result[prop.name] = prop.getSampleValue(modelsToIgnore);
  491. }
  492. modelsToIgnore.pop(this.name);
  493. return result;
  494. };
  495. return SwaggerModel;
  496. })();
  497. SwaggerModelProperty = (function() {
  498. function SwaggerModelProperty(name, obj) {
  499. this.name = name;
  500. this.dataType = obj.type || obj.dataType || obj["$ref"];
  501. this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set');
  502. this.descr = obj.description;
  503. this.required = obj.required;
  504. if (obj.items != null) {
  505. if (obj.items.type != null) {
  506. this.refDataType = obj.items.type;
  507. }
  508. if (obj.items.$ref != null) {
  509. this.refDataType = obj.items.$ref;
  510. }
  511. }
  512. this.dataTypeWithRef = this.refDataType != null ? this.dataType + '[' + this.refDataType + ']' : this.dataType;
  513. if (obj.allowableValues != null) {
  514. this.valueType = obj.allowableValues.valueType;
  515. this.values = obj.allowableValues.values;
  516. if (this.values != null) {
  517. this.valuesString = "'" + this.values.join("' or '") + "'";
  518. }
  519. }
  520. if (obj["enum"] != null) {
  521. this.valueType = "string";
  522. this.values = obj["enum"];
  523. if (this.values != null) {
  524. this.valueString = "'" + this.values.join("' or '") + "'";
  525. }
  526. }
  527. }
  528. SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
  529. var result;
  530. if ((this.refModel != null) && (modelsToIgnore.indexOf(this.refModel.name) === -1)) {
  531. result = this.refModel.createJSONSample(modelsToIgnore);
  532. } else {
  533. if (this.isCollection) {
  534. result = this.refDataType;
  535. } else {
  536. result = this.dataType;
  537. }
  538. }
  539. if (this.isCollection) {
  540. return [result];
  541. } else {
  542. return result;
  543. }
  544. };
  545. SwaggerModelProperty.prototype.toString = function() {
  546. var req, str;
  547. req = this.required ? 'propReq' : 'propOpt';
  548. str = '<span class="propName ' + req + '">' + this.name + '</span> (<span class="propType">' + this.dataTypeWithRef + '</span>';
  549. if (!this.required) {
  550. str += ', <span class="propOptKey">optional</span>';
  551. }
  552. str += ')';
  553. if (this.values != null) {
  554. str += " = <span class='propVals'>['" + this.values.join("' or '") + "']</span>";
  555. }
  556. if (this.descr != null) {
  557. str += ': <span class="propDesc">' + this.descr + '</span>';
  558. }
  559. return str;
  560. };
  561. return SwaggerModelProperty;
  562. })();
  563. SwaggerOperation = (function() {
  564. function SwaggerOperation(nickname, path, method, parameters, summary, notes, type, responseMessages, resource, consumes, produces) {
  565. var parameter, v, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3,
  566. _this = this;
  567. this.nickname = nickname;
  568. this.path = path;
  569. this.method = method;
  570. this.parameters = parameters != null ? parameters : [];
  571. this.summary = summary;
  572. this.notes = notes;
  573. this.type = type;
  574. this.responseMessages = responseMessages;
  575. this.resource = resource;
  576. this.consumes = consumes;
  577. this.produces = produces;
  578. this["do"] = __bind(this["do"], this);
  579. if (this.nickname == null) {
  580. this.resource.api.fail("SwaggerOperations must have a nickname.");
  581. }
  582. if (this.path == null) {
  583. this.resource.api.fail("SwaggerOperation " + nickname + " is missing path.");
  584. }
  585. if (this.method == null) {
  586. this.resource.api.fail("SwaggerOperation " + nickname + " is missing method.");
  587. }
  588. this.path = this.path.replace('{format}', 'json');
  589. this.method = this.method.toLowerCase();
  590. this.isGetMethod = this.method === "get";
  591. this.resourceName = this.resource.name;
  592. if (((_ref = this.type) != null ? _ref.toLowerCase() : void 0) === 'void') {
  593. this.type = void 0;
  594. }
  595. if (this.type != null) {
  596. this.responseClassSignature = this.getSignature(this.type, this.resource.models);
  597. this.responseSampleJSON = this.getSampleJSON(this.type, this.resource.models);
  598. }
  599. this.responseMessages = this.responseMessages || [];
  600. _ref1 = this.parameters;
  601. for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  602. parameter = _ref1[_i];
  603. parameter.name = parameter.name || parameter.type || parameter.dataType;
  604. type = parameter.type || parameter.dataType;
  605. if (type.toLowerCase() === 'boolean') {
  606. parameter.allowableValues = {};
  607. parameter.allowableValues.values = ["true", "false"];
  608. }
  609. parameter.signature = this.getSignature(type, this.resource.models);
  610. parameter.sampleJSON = this.getSampleJSON(type, this.resource.models);
  611. if (parameter["enum"] != null) {
  612. parameter.isList = true;
  613. parameter.allowableValues = {};
  614. parameter.allowableValues.descriptiveValues = [];
  615. _ref2 = parameter["enum"];
  616. for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
  617. v = _ref2[_j];
  618. if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
  619. parameter.allowableValues.descriptiveValues.push({
  620. value: v,
  621. isDefault: true
  622. });
  623. } else {
  624. parameter.allowableValues.descriptiveValues.push({
  625. value: v,
  626. isDefault: false
  627. });
  628. }
  629. }
  630. }
  631. if (parameter.allowableValues != null) {
  632. if (parameter.allowableValues.valueType === "RANGE") {
  633. parameter.isRange = true;
  634. } else {
  635. parameter.isList = true;
  636. }
  637. if (parameter.allowableValues.values != null) {
  638. parameter.allowableValues.descriptiveValues = [];
  639. _ref3 = parameter.allowableValues.values;
  640. for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
  641. v = _ref3[_k];
  642. if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
  643. parameter.allowableValues.descriptiveValues.push({
  644. value: v,
  645. isDefault: true
  646. });
  647. } else {
  648. parameter.allowableValues.descriptiveValues.push({
  649. value: v,
  650. isDefault: false
  651. });
  652. }
  653. }
  654. }
  655. }
  656. }
  657. this.resource[this.nickname] = function(args, callback, error) {
  658. return _this["do"](args, callback, error);
  659. };
  660. this.resource[this.nickname].help = function() {
  661. return _this.help();
  662. };
  663. }
  664. SwaggerOperation.prototype.isListType = function(type) {
  665. if (type.indexOf('[') >= 0) {
  666. return type.substring(type.indexOf('[') + 1, type.indexOf(']'));
  667. } else {
  668. return void 0;
  669. }
  670. };
  671. SwaggerOperation.prototype.getSignature = function(type, models) {
  672. var isPrimitive, listType;
  673. listType = this.isListType(type);
  674. isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
  675. if (isPrimitive) {
  676. return type;
  677. } else {
  678. if (listType != null) {
  679. return models[listType].getMockSignature();
  680. } else {
  681. return models[type].getMockSignature();
  682. }
  683. }
  684. };
  685. SwaggerOperation.prototype.getSampleJSON = function(type, models) {
  686. var isPrimitive, listType, val;
  687. listType = this.isListType(type);
  688. isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
  689. val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[type].createJSONSample());
  690. if (val) {
  691. val = listType ? [val] : val;
  692. return JSON.stringify(val, null, 2);
  693. }
  694. };
  695. SwaggerOperation.prototype["do"] = function(args, opts, callback, error) {
  696. var key, param, params, possibleParams, req, requestContentType, responseContentType, value, _i, _len, _ref;
  697. if (args == null) {
  698. args = {};
  699. }
  700. if (opts == null) {
  701. opts = {};
  702. }
  703. requestContentType = null;
  704. responseContentType = null;
  705. if ((typeof args) === "function") {
  706. error = opts;
  707. callback = args;
  708. args = {};
  709. }
  710. if ((typeof opts) === "function") {
  711. error = callback;
  712. callback = opts;
  713. }
  714. if (error == null) {
  715. error = function(xhr, textStatus, error) {
  716. return console.log(xhr, textStatus, error);
  717. };
  718. }
  719. if (callback == null) {
  720. callback = function(data) {
  721. var content;
  722. content = null;
  723. if (data.content != null) {
  724. content = data.content.data;
  725. } else {
  726. content = "no data";
  727. }
  728. return console.log("default callback: " + content);
  729. };
  730. }
  731. params = {};
  732. params.headers = [];
  733. if (args.headers != null) {
  734. params.headers = args.headers;
  735. delete args.headers;
  736. }
  737. _ref = this.parameters;
  738. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  739. param = _ref[_i];
  740. if (param.paramType === "header") {
  741. if (args[param.name]) {
  742. params.headers[param.name] = args[param.name];
  743. }
  744. }
  745. }
  746. if (args.body != null) {
  747. params.body = args.body;
  748. delete args.body;
  749. }
  750. possibleParams = (function() {
  751. var _j, _len1, _ref1, _results;
  752. _ref1 = this.parameters;
  753. _results = [];
  754. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  755. param = _ref1[_j];
  756. if (param.paramType === "form" || param.paramType.toLowerCase() === "file") {
  757. _results.push(param);
  758. }
  759. }
  760. return _results;
  761. }).call(this);
  762. if (possibleParams) {
  763. for (key in possibleParams) {
  764. value = possibleParams[key];
  765. if (args[value.name]) {
  766. params[value.name] = args[value.name];
  767. }
  768. }
  769. }
  770. req = new SwaggerRequest(this.method, this.urlify(args), params, opts, callback, error, this);
  771. if (opts.mock != null) {
  772. return req;
  773. } else {
  774. return true;
  775. }
  776. };
  777. SwaggerOperation.prototype.pathJson = function() {
  778. return this.path.replace("{format}", "json");
  779. };
  780. SwaggerOperation.prototype.pathXml = function() {
  781. return this.path.replace("{format}", "xml");
  782. };
  783. SwaggerOperation.prototype.urlify = function(args) {
  784. var param, queryParams, reg, url, _i, _j, _len, _len1, _ref, _ref1;
  785. url = this.resource.basePath + this.pathJson();
  786. _ref = this.parameters;
  787. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  788. param = _ref[_i];
  789. if (param.paramType === 'path') {
  790. if (args[param.name]) {
  791. reg = new RegExp('\{' + param.name + '[^\}]*\}', 'gi');
  792. url = url.replace(reg, encodeURIComponent(args[param.name]));
  793. delete args[param.name];
  794. } else {
  795. throw "" + param.name + " is a required path param.";
  796. }
  797. }
  798. }
  799. queryParams = "";
  800. _ref1 = this.parameters;
  801. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  802. param = _ref1[_j];
  803. if (param.paramType === 'query') {
  804. if (args[param.name]) {
  805. if (queryParams !== "") {
  806. queryParams += "&";
  807. }
  808. queryParams += encodeURIComponent(param.name) + '=' + encodeURIComponent(args[param.name]);
  809. }
  810. }
  811. }
  812. if ((queryParams != null) && queryParams.length > 0) {
  813. url += "?" + queryParams;
  814. }
  815. return url;
  816. };
  817. SwaggerOperation.prototype.supportHeaderParams = function() {
  818. return this.resource.api.supportHeaderParams;
  819. };
  820. SwaggerOperation.prototype.supportedSubmitMethods = function() {
  821. return this.resource.api.supportedSubmitMethods;
  822. };
  823. SwaggerOperation.prototype.getQueryParams = function(args) {
  824. return this.getMatchingParams(['query'], args);
  825. };
  826. SwaggerOperation.prototype.getHeaderParams = function(args) {
  827. return this.getMatchingParams(['header'], args);
  828. };
  829. SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args) {
  830. var matchingParams, name, param, value, _i, _len, _ref, _ref1;
  831. matchingParams = {};
  832. _ref = this.parameters;
  833. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  834. param = _ref[_i];
  835. if (args && args[param.name]) {
  836. matchingParams[param.name] = args[param.name];
  837. }
  838. }
  839. _ref1 = this.resource.api.headers;
  840. for (name in _ref1) {
  841. value = _ref1[name];
  842. matchingParams[name] = value;
  843. }
  844. return matchingParams;
  845. };
  846. SwaggerOperation.prototype.help = function() {
  847. var msg, parameter, _i, _len, _ref;
  848. msg = "";
  849. _ref = this.parameters;
  850. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  851. parameter = _ref[_i];
  852. if (msg !== "") {
  853. msg += "\n";
  854. }
  855. msg += "* " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description;
  856. }
  857. return msg;
  858. };
  859. return SwaggerOperation;
  860. })();
  861. SwaggerRequest = (function() {
  862. function SwaggerRequest(type, url, params, opts, successCallback, errorCallback, operation, execution) {
  863. var body, e, fields, headers, key, myHeaders, name, obj, param, parent, possibleParams, requestContentType, responseContentType, urlEncoded, value, values,
  864. _this = this;
  865. this.type = type;
  866. this.url = url;
  867. this.params = params;
  868. this.opts = opts;
  869. this.successCallback = successCallback;
  870. this.errorCallback = errorCallback;
  871. this.operation = operation;
  872. this.execution = execution;
  873. if (this.type == null) {
  874. throw "SwaggerRequest type is required (get/post/put/delete).";
  875. }
  876. if (this.url == null) {
  877. throw "SwaggerRequest url is required.";
  878. }
  879. if (this.successCallback == null) {
  880. throw "SwaggerRequest successCallback is required.";
  881. }
  882. if (this.errorCallback == null) {
  883. throw "SwaggerRequest error callback is required.";
  884. }
  885. if (this.operation == null) {
  886. throw "SwaggerRequest operation is required.";
  887. }
  888. this.type = this.type.toUpperCase();
  889. headers = params.headers;
  890. myHeaders = {};
  891. body = params.body;
  892. parent = params["parent"];
  893. requestContentType = "application/json";
  894. if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH")) {
  895. if (this.opts.requestContentType) {
  896. requestContentType = this.opts.requestContentType;
  897. }
  898. } else {
  899. if (((function() {
  900. var _i, _len, _ref, _results;
  901. _ref = this.operation.parameters;
  902. _results = [];
  903. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  904. param = _ref[_i];
  905. if (param.paramType === "form") {
  906. _results.push(param);
  907. }
  908. }
  909. return _results;
  910. }).call(this)).length > 0) {
  911. type = param.type || param.dataType;
  912. if (((function() {
  913. var _i, _len, _ref, _results;
  914. _ref = this.operation.parameters;
  915. _results = [];
  916. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  917. param = _ref[_i];
  918. if (type.toLowerCase() === "file") {
  919. _results.push(param);
  920. }
  921. }
  922. return _results;
  923. }).call(this)).length > 0) {
  924. requestContentType = "multipart/form-data";
  925. } else {
  926. requestContentType = "application/x-www-form-urlencoded";
  927. }
  928. } else if (this.type !== "DELETE") {
  929. requestContentType = null;
  930. }
  931. }
  932. if (requestContentType && this.operation.consumes) {
  933. if (this.operation.consumes.indexOf(requestContentType) === -1) {
  934. console.log("server doesn't consume " + requestContentType + ", try " + JSON.stringify(this.operation.consumes));
  935. if (this.requestContentType === null) {
  936. requestContentType = this.operation.consumes[0];
  937. }
  938. }
  939. }
  940. responseContentType = null;
  941. if (this.type === "POST" || this.type === "GET" || this.type === "PATCH") {
  942. if (this.opts.responseContentType) {
  943. responseContentType = this.opts.responseContentType;
  944. } else {
  945. responseContentType = "application/json";
  946. }
  947. } else {
  948. responseContentType = null;
  949. }
  950. if (responseContentType && this.operation.produces) {
  951. if (this.operation.produces.indexOf(responseContentType) === -1) {
  952. console.log("server can't produce " + responseContentType);
  953. }
  954. }
  955. if (requestContentType && requestContentType.indexOf("application/x-www-form-urlencoded") === 0) {
  956. fields = {};
  957. possibleParams = (function() {
  958. var _i, _len, _ref, _results;
  959. _ref = this.operation.parameters;
  960. _results = [];
  961. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  962. param = _ref[_i];
  963. if (param.paramType === "form") {
  964. _results.push(param);
  965. }
  966. }
  967. return _results;
  968. }).call(this);
  969. values = {};
  970. for (key in possibleParams) {
  971. value = possibleParams[key];
  972. if (this.params[value.name]) {
  973. values[value.name] = this.params[value.name];
  974. }
  975. }
  976. urlEncoded = "";
  977. for (key in values) {
  978. value = values[key];
  979. if (urlEncoded !== "") {
  980. urlEncoded += "&";
  981. }
  982. urlEncoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
  983. }
  984. body = urlEncoded;
  985. }
  986. for (name in headers) {
  987. myHeaders[name] = headers[name];
  988. }
  989. if (requestContentType) {
  990. myHeaders["Content-Type"] = requestContentType;
  991. }
  992. if (responseContentType) {
  993. myHeaders["Accept"] = responseContentType;
  994. }
  995. if (!((headers != null) && (headers.mock != null))) {
  996. obj = {
  997. url: this.url,
  998. method: this.type,
  999. headers: myHeaders,
  1000. body: body,
  1001. on: {
  1002. error: function(response) {
  1003. return _this.errorCallback(response, _this.opts.parent);
  1004. },
  1005. redirect: function(response) {
  1006. return _this.successCallback(response, _this.opts.parent);
  1007. },
  1008. 307: function(response) {
  1009. return _this.successCallback(response, _this.opts.parent);
  1010. },
  1011. response: function(response) {
  1012. return _this.successCallback(response, _this.opts.parent);
  1013. }
  1014. }
  1015. };
  1016. e = {};
  1017. if (typeof window !== 'undefined') {
  1018. e = window;
  1019. } else {
  1020. e = exports;
  1021. }
  1022. e.authorizations.apply(obj);
  1023. if (opts.mock == null) {
  1024. new SwaggerHttp().execute(obj);
  1025. } else {
  1026. console.log(obj);
  1027. return obj;
  1028. }
  1029. }
  1030. }
  1031. SwaggerRequest.prototype.asCurl = function() {
  1032. var header_args, k, v;
  1033. header_args = (function() {
  1034. var _ref, _results;
  1035. _ref = this.headers;
  1036. _results = [];
  1037. for (k in _ref) {
  1038. v = _ref[k];
  1039. _results.push("--header \"" + k + ": " + v + "\"");
  1040. }
  1041. return _results;
  1042. }).call(this);
  1043. return "curl " + (header_args.join(" ")) + " " + this.url;
  1044. };
  1045. return SwaggerRequest;
  1046. })();
  1047. SwaggerHttp = (function() {
  1048. SwaggerHttp.prototype.Shred = null;
  1049. SwaggerHttp.prototype.shred = null;
  1050. SwaggerHttp.prototype.content = null;
  1051. function SwaggerHttp() {
  1052. var identity, toString,
  1053. _this = this;
  1054. if (typeof window !== 'undefined') {
  1055. this.Shred = require("./shred");
  1056. } else {
  1057. this.Shred = require("shred");
  1058. }
  1059. this.shred = new this.Shred();
  1060. identity = function(x) {
  1061. return x;
  1062. };
  1063. toString = function(x) {
  1064. return x.toString();
  1065. };
  1066. if (typeof window !== 'undefined') {
  1067. this.content = require("./shred/content");
  1068. this.content.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
  1069. parser: identity,
  1070. stringify: toString
  1071. });
  1072. } else {
  1073. this.Shred.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
  1074. parser: identity,
  1075. stringify: toString
  1076. });
  1077. }
  1078. }
  1079. SwaggerHttp.prototype.execute = function(obj) {
  1080. return this.shred.request(obj);
  1081. };
  1082. return SwaggerHttp;
  1083. })();
  1084. SwaggerAuthorizations = (function() {
  1085. SwaggerAuthorizations.prototype.authz = null;
  1086. function SwaggerAuthorizations() {
  1087. this.authz = {};
  1088. }
  1089. SwaggerAuthorizations.prototype.add = function(name, auth) {
  1090. this.authz[name] = auth;
  1091. return auth;
  1092. };
  1093. SwaggerAuthorizations.prototype.apply = function(obj) {
  1094. var key, value, _ref, _results;
  1095. _ref = this.authz;
  1096. _results = [];
  1097. for (key in _ref) {
  1098. value = _ref[key];
  1099. _results.push(value.apply(obj));
  1100. }
  1101. return _results;
  1102. };
  1103. return SwaggerAuthorizations;
  1104. })();
  1105. ApiKeyAuthorization = (function() {
  1106. ApiKeyAuthorization.prototype.type = null;
  1107. ApiKeyAuthorization.prototype.name = null;
  1108. ApiKeyAuthorization.prototype.value = null;
  1109. function ApiKeyAuthorization(name, value, type) {
  1110. this.name = name;
  1111. this.value = value;
  1112. this.type = type;
  1113. }
  1114. ApiKeyAuthorization.prototype.apply = function(obj) {
  1115. if (this.type === "query") {
  1116. if (obj.url.indexOf('?') > 0) {
  1117. obj.url = obj.url + "&" + this.name + "=" + this.value;
  1118. } else {
  1119. obj.url = obj.url + "?" + this.name + "=" + this.value;
  1120. }
  1121. return true;
  1122. } else if (this.type === "header") {
  1123. return obj.headers[this.name] = this.value;
  1124. }
  1125. };
  1126. return ApiKeyAuthorization;
  1127. })();
  1128. PasswordAuthorization = (function() {
  1129. PasswordAuthorization.prototype.name = null;
  1130. PasswordAuthorization.prototype.username = null;
  1131. PasswordAuthorization.prototype.password = null;
  1132. function PasswordAuthorization(name, username, password) {
  1133. this.name = name;
  1134. this.username = username;
  1135. this.password = password;
  1136. }
  1137. PasswordAuthorization.prototype.apply = function(obj) {
  1138. return obj.headers["Authorization"] = "Basic " + btoa(this.username + ":" + this.password);
  1139. };
  1140. return PasswordAuthorization;
  1141. })();
  1142. this.SwaggerApi = SwaggerApi;
  1143. this.SwaggerResource = SwaggerResource;
  1144. this.SwaggerOperation = SwaggerOperation;
  1145. this.SwaggerRequest = SwaggerRequest;
  1146. this.SwaggerModelProperty = SwaggerModelProperty;
  1147. this.ApiKeyAuthorization = ApiKeyAuthorization;
  1148. this.PasswordAuthorization = PasswordAuthorization;
  1149. this.authorizations = new SwaggerAuthorizations();
  1150. }).call(this);