Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.
 
 
 
 

1251 Zeilen
40 KiB

  1. // Generated by CoffeeScript 1.4.0
  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 (error.status === 0) {
  50. return _this.fail('Can\'t read from server. It may not have the appropriate access-control-origin settings.');
  51. } else if (error.status === 404) {
  52. return _this.fail('Can\'t read swagger JSON from ' + _this.url);
  53. } else {
  54. return _this.fail(error.status + ' : ' + error.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 (isApi) {
  104. newName = response.resourcePath.replace(/\//g, '');
  105. this.resourcePath = response.resourcePath;
  106. res = new SwaggerResource(response, this);
  107. this.apis[newName] = res;
  108. this.apisArray.push(res);
  109. } else {
  110. if (response.basePath) {
  111. this.basePath = response.basePath;
  112. } else if (this.url.indexOf('?') > 0) {
  113. this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
  114. } else {
  115. this.basePath = this.url;
  116. }
  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 (isApi) {
  155. newName = response.resourcePath.replace(/\//g, '');
  156. this.resourcePath = response.resourcePath;
  157. res = new SwaggerResource(response, this);
  158. this.apis[newName] = res;
  159. this.apisArray.push(res);
  160. } else {
  161. if (response.basePath) {
  162. this.basePath = response.basePath;
  163. } else if (this.url.indexOf('?') > 0) {
  164. this.basePath = this.url.substring(0, this.url.lastIndexOf('?'));
  165. } else {
  166. this.basePath = this.url;
  167. }
  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 " + error.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, ref, responseMessages, type, _i, _len, _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. }
  382. o.nickname = this.sanitize(o.nickname);
  383. op = new SwaggerOperation(o.nickname, resource_path, method, o.parameters, o.summary, o.notes, type, responseMessages, this, consumes, produces);
  384. this.operations[op.nickname] = op;
  385. _results.push(this.operationsArray.push(op));
  386. }
  387. return _results;
  388. }
  389. };
  390. SwaggerResource.prototype.sanitize = function(nickname) {
  391. var op;
  392. op = nickname.replace(/[\s!@#$%^&*()_+=\[{\]};:<>|./?,\\'""-]/g, '_');
  393. op = op.replace(/((_){2,})/g, '_');
  394. op = op.replace(/^(_)*/g, '');
  395. op = op.replace(/([_])*$/g, '');
  396. return op;
  397. };
  398. SwaggerResource.prototype.help = function() {
  399. var msg, operation, operation_name, parameter, _i, _len, _ref, _ref1, _results;
  400. _ref = this.operations;
  401. _results = [];
  402. for (operation_name in _ref) {
  403. operation = _ref[operation_name];
  404. msg = " " + operation.nickname;
  405. _ref1 = operation.parameters;
  406. for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  407. parameter = _ref1[_i];
  408. msg.concat(" " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description);
  409. }
  410. _results.push(msg);
  411. }
  412. return _results;
  413. };
  414. return SwaggerResource;
  415. })();
  416. SwaggerModel = (function() {
  417. function SwaggerModel(modelName, obj) {
  418. var prop, propertyName, value;
  419. this.name = obj.id != null ? obj.id : modelName;
  420. this.properties = [];
  421. for (propertyName in obj.properties) {
  422. if (obj.required != null) {
  423. for (value in obj.required) {
  424. if (propertyName === obj.required[value]) {
  425. obj.properties[propertyName].required = true;
  426. }
  427. }
  428. }
  429. prop = new SwaggerModelProperty(propertyName, obj.properties[propertyName]);
  430. this.properties.push(prop);
  431. }
  432. }
  433. SwaggerModel.prototype.setReferencedModels = function(allModels) {
  434. var prop, type, _i, _len, _ref, _results;
  435. _ref = this.properties;
  436. _results = [];
  437. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  438. prop = _ref[_i];
  439. type = prop.type || prop.dataType;
  440. if (allModels[type] != null) {
  441. _results.push(prop.refModel = allModels[type]);
  442. } else if ((prop.refDataType != null) && (allModels[prop.refDataType] != null)) {
  443. _results.push(prop.refModel = allModels[prop.refDataType]);
  444. } else {
  445. _results.push(void 0);
  446. }
  447. }
  448. return _results;
  449. };
  450. SwaggerModel.prototype.getMockSignature = function(modelsToIgnore) {
  451. var classClose, classOpen, prop, propertiesStr, returnVal, strong, strongClose, stronger, _i, _j, _len, _len1, _ref, _ref1;
  452. propertiesStr = [];
  453. _ref = this.properties;
  454. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  455. prop = _ref[_i];
  456. propertiesStr.push(prop.toString());
  457. }
  458. strong = '<span class="strong">';
  459. stronger = '<span class="stronger">';
  460. strongClose = '</span>';
  461. classOpen = strong + this.name + ' {' + strongClose;
  462. classClose = strong + '}' + strongClose;
  463. returnVal = classOpen + '<div>' + propertiesStr.join(',</div><div>') + '</div>' + classClose;
  464. if (!modelsToIgnore) {
  465. modelsToIgnore = [];
  466. }
  467. modelsToIgnore.push(this);
  468. _ref1 = this.properties;
  469. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  470. prop = _ref1[_j];
  471. if ((prop.refModel != null) && (modelsToIgnore.indexOf(prop.refModel)) === -1) {
  472. returnVal = returnVal + ('<br>' + prop.refModel.getMockSignature(modelsToIgnore));
  473. }
  474. }
  475. return returnVal;
  476. };
  477. SwaggerModel.prototype.createJSONSample = function(modelsToIgnore) {
  478. var prop, result, _i, _len, _ref;
  479. result = {};
  480. modelsToIgnore = modelsToIgnore || [];
  481. modelsToIgnore.push(this.name);
  482. _ref = this.properties;
  483. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  484. prop = _ref[_i];
  485. result[prop.name] = prop.getSampleValue(modelsToIgnore);
  486. }
  487. modelsToIgnore.pop(this.name);
  488. return result;
  489. };
  490. return SwaggerModel;
  491. })();
  492. SwaggerModelProperty = (function() {
  493. function SwaggerModelProperty(name, obj) {
  494. this.name = name;
  495. this.dataType = obj.type || obj.dataType || obj["$ref"];
  496. this.isCollection = this.dataType && (this.dataType.toLowerCase() === 'array' || this.dataType.toLowerCase() === 'list' || this.dataType.toLowerCase() === 'set');
  497. this.descr = obj.description;
  498. this.required = obj.required;
  499. if (obj.items != null) {
  500. if (obj.items.type != null) {
  501. this.refDataType = obj.items.type;
  502. }
  503. if (obj.items.$ref != null) {
  504. this.refDataType = obj.items.$ref;
  505. }
  506. }
  507. this.dataTypeWithRef = this.refDataType != null ? this.dataType + '[' + this.refDataType + ']' : this.dataType;
  508. if (obj.allowableValues != null) {
  509. this.valueType = obj.allowableValues.valueType;
  510. this.values = obj.allowableValues.values;
  511. if (this.values != null) {
  512. this.valuesString = "'" + this.values.join("' or '") + "'";
  513. }
  514. }
  515. if (obj["enum"] != null) {
  516. this.valueType = "string";
  517. this.values = obj["enum"];
  518. if (this.values != null) {
  519. this.valueString = "'" + this.values.join("' or '") + "'";
  520. }
  521. }
  522. }
  523. SwaggerModelProperty.prototype.getSampleValue = function(modelsToIgnore) {
  524. var result;
  525. if ((this.refModel != null) && (modelsToIgnore.indexOf(this.refModel.name) === -1)) {
  526. result = this.refModel.createJSONSample(modelsToIgnore);
  527. } else {
  528. if (this.isCollection) {
  529. result = this.refDataType;
  530. } else {
  531. result = this.dataType;
  532. }
  533. }
  534. if (this.isCollection) {
  535. return [result];
  536. } else {
  537. return result;
  538. }
  539. };
  540. SwaggerModelProperty.prototype.toString = function() {
  541. var req, str;
  542. req = this.required ? 'propReq' : 'propOpt';
  543. str = '<span class="propName ' + req + '">' + this.name + '</span> (<span class="propType">' + this.dataTypeWithRef + '</span>';
  544. if (!this.required) {
  545. str += ', <span class="propOptKey">optional</span>';
  546. }
  547. str += ')';
  548. if (this.values != null) {
  549. str += " = <span class='propVals'>['" + this.values.join("' or '") + "']</span>";
  550. }
  551. if (this.descr != null) {
  552. str += ': <span class="propDesc">' + this.descr + '</span>';
  553. }
  554. return str;
  555. };
  556. return SwaggerModelProperty;
  557. })();
  558. SwaggerOperation = (function() {
  559. function SwaggerOperation(nickname, path, method, parameters, summary, notes, type, responseMessages, resource, consumes, produces) {
  560. var parameter, v, _i, _j, _k, _len, _len1, _len2, _ref, _ref1, _ref2, _ref3,
  561. _this = this;
  562. this.nickname = nickname;
  563. this.path = path;
  564. this.method = method;
  565. this.parameters = parameters != null ? parameters : [];
  566. this.summary = summary;
  567. this.notes = notes;
  568. this.type = type;
  569. this.responseMessages = responseMessages;
  570. this.resource = resource;
  571. this.consumes = consumes;
  572. this.produces = produces;
  573. this["do"] = __bind(this["do"], this);
  574. if (this.nickname == null) {
  575. this.resource.api.fail("SwaggerOperations must have a nickname.");
  576. }
  577. if (this.path == null) {
  578. this.resource.api.fail("SwaggerOperation " + nickname + " is missing path.");
  579. }
  580. if (this.method == null) {
  581. this.resource.api.fail("SwaggerOperation " + nickname + " is missing method.");
  582. }
  583. this.path = this.path.replace('{format}', 'json');
  584. this.method = this.method.toLowerCase();
  585. this.isGetMethod = this.method === "get";
  586. this.resourceName = this.resource.name;
  587. if (((_ref = this.type) != null ? _ref.toLowerCase() : void 0) === 'void') {
  588. this.type = void 0;
  589. }
  590. if (this.type != null) {
  591. this.responseClassSignature = this.getSignature(this.type, this.resource.models);
  592. this.responseSampleJSON = this.getSampleJSON(this.type, this.resource.models);
  593. }
  594. this.responseMessages = this.responseMessages || [];
  595. _ref1 = this.parameters;
  596. for (_i = 0, _len = _ref1.length; _i < _len; _i++) {
  597. parameter = _ref1[_i];
  598. parameter.name = parameter.name || parameter.type || parameter.dataType;
  599. type = parameter.type || parameter.dataType;
  600. if (type.toLowerCase() === 'boolean') {
  601. parameter.allowableValues = {};
  602. parameter.allowableValues.values = ["true", "false"];
  603. }
  604. parameter.signature = this.getSignature(type, this.resource.models);
  605. parameter.sampleJSON = this.getSampleJSON(type, this.resource.models);
  606. if (parameter["enum"] != null) {
  607. parameter.isList = true;
  608. parameter.allowableValues = {};
  609. parameter.allowableValues.descriptiveValues = [];
  610. _ref2 = parameter["enum"];
  611. for (_j = 0, _len1 = _ref2.length; _j < _len1; _j++) {
  612. v = _ref2[_j];
  613. if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
  614. parameter.allowableValues.descriptiveValues.push({
  615. value: v,
  616. isDefault: true
  617. });
  618. } else {
  619. parameter.allowableValues.descriptiveValues.push({
  620. value: v,
  621. isDefault: false
  622. });
  623. }
  624. }
  625. }
  626. if (parameter.allowableValues != null) {
  627. if (parameter.allowableValues.valueType === "RANGE") {
  628. parameter.isRange = true;
  629. } else {
  630. parameter.isList = true;
  631. }
  632. if (parameter.allowableValues.values != null) {
  633. parameter.allowableValues.descriptiveValues = [];
  634. _ref3 = parameter.allowableValues.values;
  635. for (_k = 0, _len2 = _ref3.length; _k < _len2; _k++) {
  636. v = _ref3[_k];
  637. if ((parameter.defaultValue != null) && parameter.defaultValue === v) {
  638. parameter.allowableValues.descriptiveValues.push({
  639. value: v,
  640. isDefault: true
  641. });
  642. } else {
  643. parameter.allowableValues.descriptiveValues.push({
  644. value: v,
  645. isDefault: false
  646. });
  647. }
  648. }
  649. }
  650. }
  651. }
  652. this.resource[this.nickname] = function(args, callback, error) {
  653. return _this["do"](args, callback, error);
  654. };
  655. this.resource[this.nickname].help = function() {
  656. return _this.help();
  657. };
  658. }
  659. SwaggerOperation.prototype.isListType = function(type) {
  660. if (type.indexOf('[') >= 0) {
  661. return type.substring(type.indexOf('[') + 1, type.indexOf(']'));
  662. } else {
  663. return void 0;
  664. }
  665. };
  666. SwaggerOperation.prototype.getSignature = function(type, models) {
  667. var isPrimitive, listType;
  668. listType = this.isListType(type);
  669. isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
  670. if (isPrimitive) {
  671. return type;
  672. } else {
  673. if (listType != null) {
  674. return models[listType].getMockSignature();
  675. } else {
  676. return models[type].getMockSignature();
  677. }
  678. }
  679. };
  680. SwaggerOperation.prototype.getSampleJSON = function(type, models) {
  681. var isPrimitive, listType, val;
  682. listType = this.isListType(type);
  683. isPrimitive = ((listType != null) && models[listType]) || (models[type] != null) ? false : true;
  684. val = isPrimitive ? void 0 : (listType != null ? models[listType].createJSONSample() : models[type].createJSONSample());
  685. if (val) {
  686. val = listType ? [val] : val;
  687. return JSON.stringify(val, null, 2);
  688. }
  689. };
  690. SwaggerOperation.prototype["do"] = function(args, opts, callback, error) {
  691. var key, param, params, possibleParams, req, requestContentType, responseContentType, value, _i, _len, _ref;
  692. if (args == null) {
  693. args = {};
  694. }
  695. if (opts == null) {
  696. opts = {};
  697. }
  698. requestContentType = null;
  699. responseContentType = null;
  700. if ((typeof args) === "function") {
  701. error = opts;
  702. callback = args;
  703. args = {};
  704. }
  705. if ((typeof opts) === "function") {
  706. error = callback;
  707. callback = opts;
  708. }
  709. if (error == null) {
  710. error = function(xhr, textStatus, error) {
  711. return console.log(xhr, textStatus, error);
  712. };
  713. }
  714. if (callback == null) {
  715. callback = function(data) {
  716. var content;
  717. content = null;
  718. if (data.content != null) {
  719. content = data.content.data;
  720. } else {
  721. content = "no data";
  722. }
  723. return console.log("default callback: " + content);
  724. };
  725. }
  726. params = {};
  727. params.headers = [];
  728. if (args.headers != null) {
  729. params.headers = args.headers;
  730. delete args.headers;
  731. }
  732. _ref = this.parameters;
  733. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  734. param = _ref[_i];
  735. if (param.paramType === "header") {
  736. if (args[param.name]) {
  737. params.headers[param.name] = args[param.name];
  738. }
  739. }
  740. }
  741. if (args.body != null) {
  742. params.body = args.body;
  743. delete args.body;
  744. }
  745. possibleParams = (function() {
  746. var _j, _len1, _ref1, _results;
  747. _ref1 = this.parameters;
  748. _results = [];
  749. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  750. param = _ref1[_j];
  751. if (param.paramType === "form" || param.paramType.toLowerCase() === "file") {
  752. _results.push(param);
  753. }
  754. }
  755. return _results;
  756. }).call(this);
  757. if (possibleParams) {
  758. for (key in possibleParams) {
  759. value = possibleParams[key];
  760. if (args[value.name]) {
  761. params[value.name] = args[value.name];
  762. }
  763. }
  764. }
  765. req = new SwaggerRequest(this.method, this.urlify(args), params, opts, callback, error, this);
  766. if (opts.mock != null) {
  767. return req;
  768. } else {
  769. return true;
  770. }
  771. };
  772. SwaggerOperation.prototype.pathJson = function() {
  773. return this.path.replace("{format}", "json");
  774. };
  775. SwaggerOperation.prototype.pathXml = function() {
  776. return this.path.replace("{format}", "xml");
  777. };
  778. SwaggerOperation.prototype.urlify = function(args) {
  779. var param, queryParams, reg, url, _i, _j, _len, _len1, _ref, _ref1;
  780. url = this.resource.basePath + this.pathJson();
  781. _ref = this.parameters;
  782. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  783. param = _ref[_i];
  784. if (param.paramType === 'path') {
  785. if (args[param.name]) {
  786. reg = new RegExp('\{' + param.name + '[^\}]*\}', 'gi');
  787. url = url.replace(reg, encodeURIComponent(args[param.name]));
  788. delete args[param.name];
  789. } else {
  790. throw "" + param.name + " is a required path param.";
  791. }
  792. }
  793. }
  794. queryParams = "";
  795. _ref1 = this.parameters;
  796. for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
  797. param = _ref1[_j];
  798. if (param.paramType === 'query') {
  799. if (args[param.name]) {
  800. if (queryParams !== "") {
  801. queryParams += "&";
  802. }
  803. queryParams += encodeURIComponent(param.name) + '=' + encodeURIComponent(args[param.name]);
  804. }
  805. }
  806. }
  807. if ((queryParams != null) && queryParams.length > 0) {
  808. url += "?" + queryParams;
  809. }
  810. return url;
  811. };
  812. SwaggerOperation.prototype.supportHeaderParams = function() {
  813. return this.resource.api.supportHeaderParams;
  814. };
  815. SwaggerOperation.prototype.supportedSubmitMethods = function() {
  816. return this.resource.api.supportedSubmitMethods;
  817. };
  818. SwaggerOperation.prototype.getQueryParams = function(args) {
  819. return this.getMatchingParams(['query'], args);
  820. };
  821. SwaggerOperation.prototype.getHeaderParams = function(args) {
  822. return this.getMatchingParams(['header'], args);
  823. };
  824. SwaggerOperation.prototype.getMatchingParams = function(paramTypes, args) {
  825. var matchingParams, name, param, value, _i, _len, _ref, _ref1;
  826. matchingParams = {};
  827. _ref = this.parameters;
  828. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  829. param = _ref[_i];
  830. if (args && args[param.name]) {
  831. matchingParams[param.name] = args[param.name];
  832. }
  833. }
  834. _ref1 = this.resource.api.headers;
  835. for (name in _ref1) {
  836. value = _ref1[name];
  837. matchingParams[name] = value;
  838. }
  839. return matchingParams;
  840. };
  841. SwaggerOperation.prototype.help = function() {
  842. var msg, parameter, _i, _len, _ref;
  843. msg = "";
  844. _ref = this.parameters;
  845. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  846. parameter = _ref[_i];
  847. if (msg !== "") {
  848. msg += "\n";
  849. }
  850. msg += "* " + parameter.name + (parameter.required ? ' (required)' : '') + " - " + parameter.description;
  851. }
  852. return msg;
  853. };
  854. return SwaggerOperation;
  855. })();
  856. SwaggerRequest = (function() {
  857. function SwaggerRequest(type, url, params, opts, successCallback, errorCallback, operation, execution) {
  858. var body, e, fields, headers, key, myHeaders, name, obj, param, parent, possibleParams, requestContentType, responseContentType, urlEncoded, value, values,
  859. _this = this;
  860. this.type = type;
  861. this.url = url;
  862. this.params = params;
  863. this.opts = opts;
  864. this.successCallback = successCallback;
  865. this.errorCallback = errorCallback;
  866. this.operation = operation;
  867. this.execution = execution;
  868. if (this.type == null) {
  869. throw "SwaggerRequest type is required (get/post/put/delete).";
  870. }
  871. if (this.url == null) {
  872. throw "SwaggerRequest url is required.";
  873. }
  874. if (this.successCallback == null) {
  875. throw "SwaggerRequest successCallback is required.";
  876. }
  877. if (this.errorCallback == null) {
  878. throw "SwaggerRequest error callback is required.";
  879. }
  880. if (this.operation == null) {
  881. throw "SwaggerRequest operation is required.";
  882. }
  883. this.type = this.type.toUpperCase();
  884. headers = params.headers;
  885. myHeaders = {};
  886. body = params.body;
  887. parent = params["parent"];
  888. requestContentType = "application/json";
  889. if (body && (this.type === "POST" || this.type === "PUT" || this.type === "PATCH")) {
  890. if (this.opts.requestContentType) {
  891. requestContentType = this.opts.requestContentType;
  892. }
  893. } else {
  894. if (((function() {
  895. var _i, _len, _ref, _results;
  896. _ref = this.operation.parameters;
  897. _results = [];
  898. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  899. param = _ref[_i];
  900. if (param.paramType === "form") {
  901. _results.push(param);
  902. }
  903. }
  904. return _results;
  905. }).call(this)).length > 0) {
  906. type = param.type || param.dataType;
  907. if (((function() {
  908. var _i, _len, _ref, _results;
  909. _ref = this.operation.parameters;
  910. _results = [];
  911. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  912. param = _ref[_i];
  913. if (type.toLowerCase() === "file") {
  914. _results.push(param);
  915. }
  916. }
  917. return _results;
  918. }).call(this)).length > 0) {
  919. requestContentType = "multipart/form-data";
  920. } else {
  921. requestContentType = "application/x-www-form-urlencoded";
  922. }
  923. } else if (this.type !== "DELETE") {
  924. requestContentType = null;
  925. }
  926. }
  927. if (requestContentType && this.operation.consumes) {
  928. if (this.operation.consumes.indexOf(requestContentType) === -1) {
  929. console.log("server doesn't consume " + requestContentType + ", try " + JSON.stringify(this.operation.consumes));
  930. if (this.requestContentType === null) {
  931. requestContentType = this.operation.consumes[0];
  932. }
  933. }
  934. }
  935. responseContentType = null;
  936. if (this.type === "POST" || this.type === "GET" || this.type === "PATCH") {
  937. if (this.opts.responseContentType) {
  938. responseContentType = this.opts.responseContentType;
  939. } else {
  940. responseContentType = "application/json";
  941. }
  942. } else {
  943. responseContentType = null;
  944. }
  945. if (responseContentType && this.operation.produces) {
  946. if (this.operation.produces.indexOf(responseContentType) === -1) {
  947. console.log("server can't produce " + responseContentType);
  948. }
  949. }
  950. if (requestContentType && requestContentType.indexOf("application/x-www-form-urlencoded") === 0) {
  951. fields = {};
  952. possibleParams = (function() {
  953. var _i, _len, _ref, _results;
  954. _ref = this.operation.parameters;
  955. _results = [];
  956. for (_i = 0, _len = _ref.length; _i < _len; _i++) {
  957. param = _ref[_i];
  958. if (param.paramType === "form") {
  959. _results.push(param);
  960. }
  961. }
  962. return _results;
  963. }).call(this);
  964. values = {};
  965. for (key in possibleParams) {
  966. value = possibleParams[key];
  967. if (this.params[value.name]) {
  968. values[value.name] = this.params[value.name];
  969. }
  970. }
  971. urlEncoded = "";
  972. for (key in values) {
  973. value = values[key];
  974. if (urlEncoded !== "") {
  975. urlEncoded += "&";
  976. }
  977. urlEncoded += encodeURIComponent(key) + '=' + encodeURIComponent(value);
  978. }
  979. body = urlEncoded;
  980. }
  981. for (name in headers) {
  982. myHeaders[name] = headers[name];
  983. }
  984. if (requestContentType) {
  985. myHeaders["Content-Type"] = requestContentType;
  986. }
  987. if (responseContentType) {
  988. myHeaders["Accept"] = responseContentType;
  989. }
  990. if (!((headers != null) && (headers.mock != null))) {
  991. obj = {
  992. url: this.url,
  993. method: this.type,
  994. headers: myHeaders,
  995. body: body,
  996. on: {
  997. error: function(response) {
  998. return _this.errorCallback(response, _this.opts.parent);
  999. },
  1000. redirect: function(response) {
  1001. return _this.successCallback(response, _this.opts.parent);
  1002. },
  1003. 307: function(response) {
  1004. return _this.successCallback(response, _this.opts.parent);
  1005. },
  1006. response: function(response) {
  1007. return _this.successCallback(response, _this.opts.parent);
  1008. }
  1009. }
  1010. };
  1011. e = {};
  1012. if (typeof window !== 'undefined') {
  1013. e = window;
  1014. } else {
  1015. e = exports;
  1016. }
  1017. e.authorizations.apply(obj);
  1018. if (opts.mock == null) {
  1019. new SwaggerHttp().execute(obj);
  1020. } else {
  1021. console.log(obj);
  1022. return obj;
  1023. }
  1024. }
  1025. }
  1026. SwaggerRequest.prototype.asCurl = function() {
  1027. var header_args, k, v;
  1028. header_args = (function() {
  1029. var _ref, _results;
  1030. _ref = this.headers;
  1031. _results = [];
  1032. for (k in _ref) {
  1033. v = _ref[k];
  1034. _results.push("--header \"" + k + ": " + v + "\"");
  1035. }
  1036. return _results;
  1037. }).call(this);
  1038. return "curl " + (header_args.join(" ")) + " " + this.url;
  1039. };
  1040. return SwaggerRequest;
  1041. })();
  1042. SwaggerHttp = (function() {
  1043. SwaggerHttp.prototype.Shred = null;
  1044. SwaggerHttp.prototype.shred = null;
  1045. SwaggerHttp.prototype.content = null;
  1046. function SwaggerHttp() {
  1047. var identity, toString,
  1048. _this = this;
  1049. if (typeof window !== 'undefined') {
  1050. this.Shred = require("./shred");
  1051. } else {
  1052. this.Shred = require("shred");
  1053. }
  1054. this.shred = new this.Shred();
  1055. identity = function(x) {
  1056. return x;
  1057. };
  1058. toString = function(x) {
  1059. return x.toString();
  1060. };
  1061. if (typeof window !== 'undefined') {
  1062. this.content = require("./shred/content");
  1063. this.content.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
  1064. parser: identity,
  1065. stringify: toString
  1066. });
  1067. } else {
  1068. this.Shred.registerProcessor(["application/json; charset=utf-8", "application/json", "json"], {
  1069. parser: identity,
  1070. stringify: toString
  1071. });
  1072. }
  1073. }
  1074. SwaggerHttp.prototype.execute = function(obj) {
  1075. return this.shred.request(obj);
  1076. };
  1077. return SwaggerHttp;
  1078. })();
  1079. SwaggerAuthorizations = (function() {
  1080. SwaggerAuthorizations.prototype.authz = null;
  1081. function SwaggerAuthorizations() {
  1082. this.authz = {};
  1083. }
  1084. SwaggerAuthorizations.prototype.add = function(name, auth) {
  1085. this.authz[name] = auth;
  1086. return auth;
  1087. };
  1088. SwaggerAuthorizations.prototype.apply = function(obj) {
  1089. var key, value, _ref, _results;
  1090. _ref = this.authz;
  1091. _results = [];
  1092. for (key in _ref) {
  1093. value = _ref[key];
  1094. _results.push(value.apply(obj));
  1095. }
  1096. return _results;
  1097. };
  1098. return SwaggerAuthorizations;
  1099. })();
  1100. ApiKeyAuthorization = (function() {
  1101. ApiKeyAuthorization.prototype.type = null;
  1102. ApiKeyAuthorization.prototype.name = null;
  1103. ApiKeyAuthorization.prototype.value = null;
  1104. function ApiKeyAuthorization(name, value, type) {
  1105. this.name = name;
  1106. this.value = value;
  1107. this.type = type;
  1108. }
  1109. ApiKeyAuthorization.prototype.apply = function(obj) {
  1110. if (this.type === "query") {
  1111. if (obj.url.indexOf('?') > 0) {
  1112. obj.url = obj.url + "&" + this.name + "=" + this.value;
  1113. } else {
  1114. obj.url = obj.url + "?" + this.name + "=" + this.value;
  1115. }
  1116. return true;
  1117. } else if (this.type === "header") {
  1118. return obj.headers[this.name] = this.value;
  1119. }
  1120. };
  1121. return ApiKeyAuthorization;
  1122. })();
  1123. PasswordAuthorization = (function() {
  1124. PasswordAuthorization.prototype.name = null;
  1125. PasswordAuthorization.prototype.username = null;
  1126. PasswordAuthorization.prototype.password = null;
  1127. function PasswordAuthorization(name, username, password) {
  1128. this.name = name;
  1129. this.username = username;
  1130. this.password = password;
  1131. }
  1132. PasswordAuthorization.prototype.apply = function(obj) {
  1133. return obj.headers["Authorization"] = "Basic " + btoa(this.username + ":" + this.password);
  1134. };
  1135. return PasswordAuthorization;
  1136. })();
  1137. this.SwaggerApi = SwaggerApi;
  1138. this.SwaggerResource = SwaggerResource;
  1139. this.SwaggerOperation = SwaggerOperation;
  1140. this.SwaggerRequest = SwaggerRequest;
  1141. this.SwaggerModelProperty = SwaggerModelProperty;
  1142. this.ApiKeyAuthorization = ApiKeyAuthorization;
  1143. this.PasswordAuthorization = PasswordAuthorization;
  1144. this.authorizations = new SwaggerAuthorizations();
  1145. }).call(this);