Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

swagger.js 40 KiB

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