DApiUI.js 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739
  1. (function ($) {
  2. //初始化类
  3. var DApiUI = {};
  4. DApiUI.init = function () {
  5. DApiUI.createGroupTab();
  6. };
  7. /**
  8. * 创建分组
  9. */
  10. DApiUI.createGroupTab = function () {
  11. $.ajax({
  12. url: "swagger-resources",
  13. type: "get",
  14. async: false,
  15. success: function (data) {
  16. //获取分组名称
  17. var groupData = data;
  18. DApiUI.initGroupSele(groupData);
  19. }
  20. })
  21. };
  22. /***
  23. * 创建面板
  24. */
  25. DApiUI.creatabTab = function () {
  26. var divcontent = $('<div id="myTab" class="tabs-container" style="width:99%;margin:0px auto;"></div>');
  27. var ul = $('<ul class="nav nav-tabs"></ul>')
  28. ul.append($('<li><a data-toggle="tab" href="#tab1" aria-expanded="false"> 接口说明</a></li>'));
  29. ul.append($('<li class=""><a data-toggle="tab" href="#tab2" aria-expanded="true"> 在线调试</a></li>'));
  30. divcontent.append(ul);
  31. var tabcontent = $('<div class="tab-content"></div>');
  32. tabcontent.append($('<div id="tab1" class="tab-pane"><div class="panel-body"><strong>接口详细说明</strong><p>Bootstrap 使用到的某些 HTML 元素和 CSS 属性需要将页面设置为 HTML5 文档类型。在你项目中的每个页面都要参照下面的格式进行设置。</p></div></div>'));
  33. tabcontent.append($('<div id="tab2" class="tab-pane"><div class="panel-body"><strong>正在开发中,敬请期待......</strong></div></div>'));
  34. divcontent.append(tabcontent);
  35. //内容覆盖
  36. DApiUI.getDoc().html("");
  37. DApiUI.getDoc().append(divcontent);
  38. DApiUI.log("动态激活...")
  39. //liapi.addClass("active");
  40. DApiUI.log("动态激活12...")
  41. DApiUI.getDoc().find("#myTab a:first").tab('show')
  42. //$('#myTab a:first').tab('show')
  43. }
  44. /***
  45. * 检查对象属性,in并赋予默认值
  46. * @param obj
  47. * @param key
  48. * @param defaultValue
  49. * @param checkEmpty
  50. * @returns {*}
  51. */
  52. DApiUI.getValue = function (obj, key, defaultValue, checkEmpty) {
  53. var val = defaultValue;
  54. if (obj != null && obj != undefined) {
  55. if (obj.hasOwnProperty(key)) {
  56. val = obj[key];
  57. if (checkEmpty) {
  58. if (val == null || val == "") {
  59. val = defaultValue;
  60. }
  61. }
  62. }
  63. }
  64. return val;
  65. }
  66. /***
  67. * 创建简介table页面
  68. * @param menu
  69. */
  70. DApiUI.createDescription = function (menu) {
  71. var table = $('<table class="table table-hover table-bordered table-text-center"></table>');
  72. var title = "", description = "", name = "", version = "", termsOfService = "";
  73. var host = DApiUI.getValue(menu, "host", "", true);
  74. if (menu.hasOwnProperty("info")) {
  75. var info = menu.info;
  76. title = DApiUI.getValue(info, "title", "Swagger-Bootstrap-UI-前后端api接口文档", true);
  77. description = DApiUI.getValue(info, "description", "", true);
  78. if (info.hasOwnProperty("contact")) {
  79. var contact = info["contact"];
  80. name = DApiUI.getValue(contact, "name", "", true);
  81. }
  82. version = DApiUI.getValue(info, "version", "", true);
  83. termsOfService = DApiUI.getValue(info, "termsOfService", "", true);
  84. }
  85. //修改title
  86. $("title").html("").html(title)
  87. table.append($('<thead><tr><th colspan="2" style="text-align:center">' + title + '</th></tr></thead>'));
  88. var tbody = $('<tbody></tbody>');
  89. tbody.append($('<tr><th class="active">简介</th><td style="text-align: left">' + description + '</td></tr>'));
  90. tbody.append($('<tr><th class="active">作者</th><td style="text-align: left">' + name + '</td></tr>'));
  91. tbody.append($('<tr><th class="active">版本</th><td style="text-align: left">' + version + '</td></tr>'));
  92. tbody.append($('<tr><th class="active">host</th><td style="text-align: left">' + host + '</td></tr>'))
  93. tbody.append($('<tr><th class="active">服务url</th><td style="text-align: left">' + termsOfService + '</td></tr>'));
  94. table.append(tbody);
  95. var div = $('<div style="width:99%;margin:0px auto;"></div>')
  96. div.append(table);
  97. //内容覆盖
  98. DApiUI.getDoc().html("");
  99. DApiUI.getDoc().append(div);
  100. DApiUI.getDoc().data("data", menu);
  101. }
  102. /***
  103. * 离线文档功能页面
  104. * @param menu
  105. */
  106. DApiUI.createMarkdownTab = function (menu) {
  107. var description = "swagger-bootstrap-ui 提供markdwon格式类型的离线文档,开发者可拷贝该内容通过其他markdown转换工具进行转换为html或pdf.";
  108. var divdes = $('<div class="alert alert-info" role="alert">' + description + '</div>');
  109. var div = $('<div style="width:99%;margin:0px auto;"></div>');
  110. div.append(divdes);
  111. //toolbar按钮组
  112. var toolbarDiv = $('<div class="input-inline" style="margin-bottom:10px;">');
  113. var copyBtn = $('<button class="btn btn-primary" type="button" id="btnCopy" data-clipboard-action="copy" data-clipboard-target="#txtDoc">拷贝文档</button></div>');
  114. toolbarDiv.append(copyBtn);
  115. div.append(toolbarDiv);
  116. //添加textarea
  117. var txtDiv = $("<div class='input-inline'><textarea class='form-control' style='width: 100%;height: 100%;' id='txtDoc'></textarea></div>")
  118. div.append(txtDiv);
  119. //内容覆盖
  120. DApiUI.getDoc().html("");
  121. DApiUI.getDoc().append(div);
  122. DApiUI.getDoc().data("data", menu);
  123. //初始化copy按钮功能
  124. var clipboard = new ClipboardJS('#btnCopy');
  125. clipboard.on('success', function (e) {
  126. layer.msg("复制成功")
  127. });
  128. clipboard.on('error', function (e) {
  129. layer.msg("复制失败,您当前浏览器版本不兼容,请手动复制.")
  130. });
  131. }
  132. /***
  133. * 获取菜单结构
  134. */
  135. DApiUI.getMenuConstructs = function () {
  136. return DApiUI.getDoc().data("data");
  137. }
  138. DApiUI.toString = function (obj, defaultStr) {
  139. if (obj != null && typeof (obj) != "undefined") {
  140. return obj.toString();
  141. }
  142. if (obj == undefined) {
  143. return defaultStr;
  144. }
  145. return defaultStr;
  146. }
  147. /***
  148. * 初始化分组菜单
  149. * @param menu
  150. */
  151. DApiUI.initGroupSele = function (groupData) {
  152. //遍历tags
  153. var tags = new Array();
  154. //创建分组flag
  155. var groupli = $('<li class="active"></li>');
  156. var groupSele = $("<select id='groupSel' style='width:100%;'></select>");
  157. $.each(groupData, function (i, group) {
  158. var groupOption = $("<option data-url='" + group.location + "' data-name='" + group.name + "'>" + group.name + "</option>");
  159. groupSele.append(groupOption);
  160. })
  161. groupli.append(groupSele);
  162. groupSele.on("change", function () {
  163. var that = $(this);
  164. DApiUI.log(that)
  165. var apiurl = that.find("option:selected").attr("data-url");
  166. DApiUI.log("分组::");
  167. DApiUI.log(apiurl);
  168. DApiUI.initApiTree(apiurl);
  169. })
  170. DApiUI.getMenu().html("");
  171. DApiUI.getMenu().append(groupli);
  172. var url = groupData[0].location;
  173. //默认加载第一个url
  174. DApiUI.initApiTree(url);
  175. }
  176. DApiUI.initApiTree = function (url) {
  177. var idx = url.indexOf("/");
  178. if (idx == 0) {
  179. url = url.substr(1);
  180. }
  181. DApiUI.log("截取后的url:" + url);
  182. $.ajax({
  183. //url:"v2/api-docs",
  184. url: url,
  185. dataType: "json",
  186. type: "get",
  187. async: false,
  188. success: function (data) {
  189. //var menu=JSON.parse(data)
  190. var menu = data;
  191. DApiUI.definitions(menu);
  192. DApiUI.log(menu);
  193. DApiUI.createDescription(menu);
  194. DApiUI.createDetailMenu(menu);
  195. }
  196. })
  197. }
  198. /***
  199. * 创建分组详情菜单
  200. * @param menu
  201. */
  202. DApiUI.createDetailMenu = function (menu) {
  203. DApiUI.getMenu().find(".detailMenu").remove();
  204. //简介li
  205. var dli = $('<li class="active detailMenu"><a href="javascript:void(0)"><i class="icon-text-width"></i><span class="menu-text"> 简介 </span></a></li>')
  206. dli.on("click", function () {
  207. DApiUI.log("简介click")
  208. DApiUI.createDescription(menu);
  209. dli.addClass("active");
  210. })
  211. DApiUI.getMenu().append(dli);
  212. //离线文档功能
  213. var mddocli = $("<li class=\"detailMenu\"><a href=\"javascript:void(0)\"><i class=\"icon-text-width\"></i><span class=\"menu-text\"> 离线文档(MD) </span></a></li>");
  214. mddocli.on("click", function () {
  215. DApiUI.log("离线文档功能click")
  216. DApiUI.createMarkdownTab(menu);
  217. DApiUI.getMenu().find("li").removeClass("active");
  218. mddocli.addClass("active");
  219. })
  220. DApiUI.getMenu().append(mddocli);
  221. var methodApis = DApiUI.eachPath(menu);
  222. $.each(menu.tags, function (i, tag) {
  223. var tagInfo = new TagInfo(tag.name, tag.description);
  224. //查找childrens
  225. $.each(methodApis, function (i, methodApi) {
  226. //判断tags是否相同
  227. $.each(methodApi.tag, function (i, tagName) {
  228. if (tagName == tagInfo.name) {
  229. tagInfo.childrens.push(methodApi);
  230. }
  231. })
  232. })
  233. var len = tagInfo.childrens.length;
  234. if (len == 0) {
  235. var li = $('<li class="detailMenu"><a href="javascript:void(0)"><i class="icon-text-width"></i><span class="menu-text"> ' + tagInfo.name + ' </span></a></li>');
  236. DApiUI.getMenu().append(li);
  237. } else {
  238. //存在子标签
  239. var li = $('<li class="detailMenu"></li>');
  240. var titleA = $('<a href="#" class="dropdown-toggle"><i class="icon-file-alt"></i><span class="menu-text">' + tagInfo.name + '<span class="badge badge-primary ">' + len + '</span></span><b class="arrow icon-angle-down"></b></a>');
  241. li.append(titleA);
  242. //循环树
  243. var ul = $('<ul class="submenu"></ul>')
  244. $.each(tagInfo.childrens, function (i, children) {
  245. var childrenLi = $('<li class="menuLi" ><div class="mhed"><div>' + children.methodType.toUpperCase() + '-<code>' + children.url + '</code></div><div>' + children.summary + '</div></div></li>');
  246. //console.log(children)
  247. //var childrenA=$('<a href="javascript:void(0)"><i class="icon-double-angle-right"></i><div ><h5><span class="method">['+children.methodType+']</span></h5></div>'+children.summary+'('+children.url+')</a>');
  248. //childrenLi.append(childrenA);
  249. childrenLi.data("data", children);
  250. ul.append(childrenLi);
  251. })
  252. li.append(ul);
  253. DApiUI.getMenu().append(li);
  254. }
  255. })
  256. DApiUI.log("菜单初始化完成...")
  257. DApiUI.initLiClick();
  258. }
  259. DApiUI.eachPath = function (menu) {
  260. var paths = menu.paths;
  261. DApiUI.log(paths);
  262. //paths是object对象,key是api接口地址,
  263. var methodApis = [];
  264. for (var key in paths) {
  265. var obj = paths[key];
  266. //遍历obj,获取api接口访问方式
  267. //八中方式类型,直接判断
  268. if (obj.hasOwnProperty("get")) {
  269. //get方式
  270. var apiInfo = new ApiInfo(obj["get"]);
  271. apiInfo.methodType = "get";
  272. apiInfo.url = key;
  273. methodApis.push(apiInfo);
  274. }
  275. if (obj.hasOwnProperty("post")) {
  276. //post 方式
  277. var apiInfo = new ApiInfo(obj["post"]);
  278. apiInfo.methodType = "post";
  279. apiInfo.url = key;
  280. methodApis.push(apiInfo);
  281. }
  282. if (obj.hasOwnProperty("put")) {
  283. //put
  284. var apiInfo = new ApiInfo(obj["put"]);
  285. apiInfo.methodType = "put";
  286. apiInfo.url = key;
  287. methodApis.push(apiInfo);
  288. }
  289. if (obj.hasOwnProperty("delete")) {
  290. //delete
  291. var apiInfo = new ApiInfo(obj["delete"]);
  292. apiInfo.methodType = "delete";
  293. apiInfo.url = key;
  294. methodApis.push(apiInfo);
  295. }
  296. //扩展 支持http其余请求方法接口
  297. //add by xiaoymin 2018-4-28 07:16:12
  298. if (obj.hasOwnProperty("patch")) {
  299. //patch
  300. var apiInfo = new ApiInfo(obj["patch"]);
  301. apiInfo.methodType = "patch";
  302. apiInfo.url = key;
  303. methodApis.push(apiInfo);
  304. }
  305. if (obj.hasOwnProperty("options")) {
  306. //OPTIONS
  307. var apiInfo = new ApiInfo(obj["options"]);
  308. apiInfo.methodType = "options";
  309. apiInfo.url = key;
  310. methodApis.push(apiInfo);
  311. }
  312. if (obj.hasOwnProperty("trace")) {
  313. //TRACE
  314. var apiInfo = new ApiInfo(obj["trace"]);
  315. apiInfo.methodType = "trace";
  316. apiInfo.url = key;
  317. methodApis.push(apiInfo);
  318. }
  319. if (obj.hasOwnProperty("head")) {
  320. //HEAD
  321. var apiInfo = new ApiInfo(obj["head"]);
  322. apiInfo.methodType = "head";
  323. apiInfo.url = key;
  324. methodApis.push(apiInfo);
  325. }
  326. if (obj.hasOwnProperty("connect")) {
  327. //CONNECT
  328. var apiInfo = new ApiInfo(obj["connect"]);
  329. apiInfo.methodType = "connect";
  330. apiInfo.url = key;
  331. methodApis.push(apiInfo);
  332. }
  333. }
  334. //console.log(methodApis);
  335. return methodApis;
  336. }
  337. /***
  338. * li标签click事件
  339. */
  340. DApiUI.initLiClick = function () {
  341. DApiUI.getMenu().find(".menuLi").bind("click", function (e) {
  342. e.preventDefault();
  343. var that = $(this);
  344. var data = that.data("data");
  345. DApiUI.log("Li标签click事件");
  346. DApiUI.log(data);
  347. //获取parent-Li的class属性值
  348. var parentLi = that.parent().parent();
  349. DApiUI.log(parentLi);
  350. var className = parentLi.prop("class");
  351. DApiUI.log(className)
  352. DApiUI.getMenu().find("li").removeClass("active");
  353. //parentLi.addClass("active");
  354. that.addClass("active");
  355. DApiUI.createApiInfoTable(data);
  356. DApiUI.createDebugTab(data);
  357. })
  358. }
  359. DApiUI.getStringValue = function (obj) {
  360. var str = "";
  361. if (typeof (obj) != 'undefined' && obj != null) {
  362. str = obj.toString();
  363. }
  364. return str;
  365. }
  366. /***
  367. * 格式化json
  368. * @param text_value
  369. */
  370. function formatterJson(text_value) {
  371. var res = "";
  372. for (var i = 0, j = 0, k = 0, ii, ele; i < text_value.length; i++) {//k:缩进,j:""个数
  373. ele = text_value.charAt(i);
  374. if (j % 2 == 0 && ele == "}") {
  375. k--;
  376. for (ii = 0; ii < k; ii++) ele = " " + ele;
  377. ele = "\n" + ele;
  378. }
  379. else if (j % 2 == 0 && ele == "{") {
  380. ele += "\n";
  381. k++;
  382. //debugger;
  383. for (ii = 0; ii < k; ii++) ele += " ";
  384. }
  385. else if (j % 2 == 0 && ele == ",") {
  386. ele += "\n";
  387. for (ii = 0; ii < k; ii++) ele += " ";
  388. }
  389. else if (ele == "\"") j++;
  390. res += ele;
  391. }
  392. return res;
  393. }
  394. /**
  395. * 创建调试面板
  396. */
  397. DApiUI.createDebugTab = function (apiInfo) {
  398. DApiUI.log("创建调试tab")
  399. //方法、请求类型、发送按钮
  400. var div = $('<div style="width: 100%;margin: 0px auto;margin-top: 20px;"></div>');
  401. var headdiv1 = $('<div class="input-group m-bot15"><span class="input-group-btn"><button class="btn btn-default btn-info" type="button">' + DApiUI.getStringValue(apiInfo.methodType) + '</button></span><input type="text" id="txtreqUrl" class="form-control" value="' + DApiUI.getStringValue(apiInfo.url) + '"/><span class="input-group-btn"><button id="btnRequest" class="btn btn-default btn-primary" type="button"> 发 送 </button></span></div>');
  402. div.append(headdiv1);
  403. //请求参数
  404. var divp = $('<div class="panel panel-primary"><div class="panel-heading">请求参数</div></div>')
  405. var divpbody = $('<div class="panel-body"></div>');
  406. //是否是文件上传
  407. var fileform = false;
  408. //判断是否有请求参数
  409. if (typeof (apiInfo.parameters) != 'undefined' && apiInfo.parameters != null) {
  410. var table = $('<table class="table table-hover table-bordered table-text-center"></table>')
  411. var thead = $('<thead><tr><th></th><th>参数名称</th><th>参数值</th><th>操作</th></tr></thead>');
  412. table.append(thead);
  413. var tbody = $('<tbody id="paramBody"></tbody>');
  414. $.each(apiInfo.parameters, function (i, param) {
  415. var tr = $('<tr></tr>');
  416. tr.data("data", param);
  417. //判断parame的in类型
  418. //query--text
  419. //body--textarea
  420. var checkbox = $('<td width="5%"><div class="checkbox"><label><input type="checkbox" value="" checked></label></div></td>');
  421. var key = $('<td width="20%"><input class="form-control p-key" value="' + param.name + '"/></td>')
  422. //var value=$('<td><input class="form-control p-value" data-apiUrl="'+apiInfo.url+'" data-name="'+param.name+'" placeholder="'+DApiUI.getStringValue(param['description'])+'"/></td>');
  423. var value = $('<td></td>');
  424. var val = null;
  425. if (param["in"] == "body") {
  426. tbody.attr("reqtype", "body");
  427. val = $('<textarea class="form-control p-value" style="font-size: 16px;" rows="10" data-apiUrl="' + apiInfo.url + '" name="' + param.name + '" data-name="' + param.name + '" placeholder="' + DApiUI.getStringValue(param['description']) + '"></textarea>')
  428. //判断是否有schma
  429. if (param.hasOwnProperty("schema")) {
  430. var schema = param["schema"];
  431. var ref = schema["$ref"];
  432. var regex = new RegExp("#/definitions/(.*)$", "ig");
  433. if (regex.test(ref)) {
  434. var refType = RegExp.$1;
  435. //这里判断refType是否是MultipartFile类型,如果是该类型,上传组件
  436. if (refType == "MultipartFile") {
  437. fileform = true;
  438. val = $('<input name="' + param.name + '" type="file" class="form-control p-value" data-apiUrl="' + apiInfo.url + '" data-name="' + param.name + '" placeholder="' + DApiUI.getStringValue(param['description']) + '"/>');
  439. } else {
  440. //find in definitionsArray
  441. var definitionsArray = DApiUI.getDoc().data("definitionsArray");
  442. var deftion = null;
  443. for (var i = 0; i < definitionsArray.length; i++) {
  444. var definition = definitionsArray[i];
  445. if (definition.key == refType) {
  446. deftion = definition.value;
  447. break;
  448. }
  449. }
  450. //遍历proprietary
  451. /*create by xjy 此处不能要,不然json数据丢了*/
  452. /*create by xjy 此处不能要,不然json数据丢了*/
  453. /* for (var k in deftion) {
  454. deftion[k] = "";
  455. }*/
  456. if (deftion != null) {
  457. //赋值
  458. /*create by xjy 新的格式化*/
  459. // val.val(formatterJson(JSON.stringify(deftion)));
  460. val.val(JSON.stringify(deftion, null, 4));
  461. }
  462. }
  463. }
  464. }
  465. } else {
  466. val = $('<input class="form-control p-value" name="' + param.name + '" data-apiUrl="' + apiInfo.url + '" data-name="' + param.name + '" placeholder="' + DApiUI.getStringValue(param['description']) + '"/>');
  467. //判断是否有defaultvalue
  468. if (param.hasOwnProperty("default")) {
  469. var defaultValue = param["default"];
  470. val.val(defaultValue);
  471. }
  472. //这里判断param类型,如果是int类型,只能输入数字
  473. }
  474. value.append(val);
  475. var oper = $('<td width="5%"><button class="btn btn-danger btn-circle btn-lg" type="button"><strong>×</strong></button></td>');
  476. //删除事件
  477. oper.find("button").on("click", function (e) {
  478. e.preventDefault();
  479. var that = $(this);
  480. that.parent().parent().remove();
  481. })
  482. //判断参数类型,针对path参数
  483. if (param["in"] == "path") {
  484. //赋予change事件
  485. value.find("input").on("keyup", function () {
  486. var t = $(this);
  487. var name = t.data("name");
  488. var apiUrl = t.attr("data-apiUrl");
  489. var realValue = apiUrl.replace("{" + name + "}", t.val());
  490. //查找是否还存在其他path参数
  491. $("#paramBody").find("tr").each(function (i, itr) {
  492. var itrthat = $(this);
  493. var itrdata = itrthat.data("data");
  494. var itrname = itrdata["name"];
  495. if (itrdata["in"] == "path" && itrdata["name"] != name) {
  496. //查找value值
  497. var itrtdvalue = itrthat.find(".p-value").val();
  498. if (itrtdvalue != "") {
  499. realValue = realValue.replace("{" + itrname + "}", itrtdvalue);
  500. }
  501. }
  502. })
  503. DApiUI.log(realValue);
  504. $("#txtreqUrl").val(realValue);
  505. DApiUI.log("keyup。。。。")
  506. })
  507. }
  508. tr.append(checkbox).append(key).append(value).append(oper);
  509. tbody.append(tr);
  510. })
  511. table.append(tbody);
  512. //如果有文件上传,追加form表单
  513. if (fileform) {
  514. //文件上传使用相对路径
  515. var uploadurltemp = apiInfo.url;
  516. if (uploadurltemp.indexOf("/") == 0) {
  517. uploadurltemp = uploadurltemp.substr(1);
  518. }
  519. DApiUI.log("upload上传接口截取后:" + uploadurltemp)
  520. var form = $('<form id="uploadForm" target="uploadIframe" action="' + uploadurltemp + '" type="" enctype="multipart/form-data" method="' + apiInfo.methodType + '"></form>');
  521. form.append(table);
  522. divpbody.append(form);
  523. } else {
  524. divpbody.append(table);
  525. }
  526. } else {
  527. divpbody.append($('<strong>暂无参数</strong>'))
  528. }
  529. divp.append(divpbody);
  530. //
  531. if (fileform) {
  532. //追加iframe
  533. var resptabframe = $('<div id="resptab" class="tabs-container" ><iframe name="uploadIframe" id="uploadIframe" style="border: none;height: 1%;display: none;"></iframe></div>')
  534. divp.append(resptabframe);
  535. }
  536. div.append(divp);
  537. //创建reesponsebody
  538. var respcleanDiv = $('<div id="responsebody"></div>');
  539. div.append(respcleanDiv);
  540. DApiUI.getDoc().find("#tab2").find(".panel-body").html("")
  541. DApiUI.getDoc().find("#tab2").find(".panel-body").append(div);
  542. //发送事件
  543. headdiv1.find("#btnRequest").bind("click", function (e) {
  544. e.preventDefault();
  545. respcleanDiv.html("")
  546. DApiUI.log("发送请求");
  547. //
  548. var params = {};
  549. var headerparams = {};
  550. var bodyparams = "";
  551. //modify by xiaoyumin 2017-8-9 11:28:16
  552. //增加表单验证
  553. var validateflag = false;
  554. var validateobj = {};
  555. //获取参数
  556. var paramBody = DApiUI.getDoc().find("#tab2").find("#paramBody")
  557. DApiUI.log("paramsbody..")
  558. DApiUI.log(paramBody)
  559. //组装请求url
  560. var url = DApiUI.getStringValue(apiInfo.url);
  561. var cacheData = DApiUI.getDoc().data("data");
  562. if (typeof (cacheData.basePath) != "undefined" && cacheData.basePath != "") {
  563. if (cacheData.basePath != "/") {
  564. DApiUI.log("NOT ROOT PATH:");
  565. url = cacheData.basePath + DApiUI.getStringValue(apiInfo.url);
  566. }
  567. }
  568. paramBody.find("tr").each(function () {
  569. var paramtr = $(this);
  570. var cked = paramtr.find("td:first").find(":checked").prop("checked");
  571. DApiUI.log(cked)
  572. if (cked) {
  573. //如果选中
  574. var trdata = paramtr.data("data");
  575. DApiUI.log("trdata....")
  576. DApiUI.log(trdata);
  577. //获取key
  578. //var key=paramtr.find("td:eq(1)").find("input").val();
  579. var key = trdata["name"];
  580. //获取value
  581. var value = "";
  582. if (trdata["in"] == "body") {
  583. value = paramtr.find("td:eq(2)").find("textarea").val();
  584. //这里需要判断schema
  585. if (trdata.hasOwnProperty("schema")) {
  586. var schema = trdata["schema"];
  587. if (schema.hasOwnProperty("$ref")) {
  588. var ref = schema["$ref"];
  589. var regex = new RegExp("#/definitions/(.*)$", "ig");
  590. if (regex.test(ref)) {
  591. var refType = RegExp.$1;
  592. //这里判断refType是否是MultipartFile类型,如果是该类型,上传组件
  593. if (refType == "MultipartFile") {
  594. value = paramtr.find("td:eq(2)").find("input").val();
  595. }
  596. }
  597. }
  598. }
  599. } else {
  600. value = paramtr.find("td:eq(2)").find("input").val();
  601. }
  602. //var value=paramtr.find("td:eq(2)").find("input").val();
  603. //delete方式参数url传递
  604. if (apiInfo.methodType == "delete") {
  605. //判断是否是path参数
  606. if (trdata["in"] == "path") {
  607. url = url.replace("{" + key + "}", value);
  608. } else {
  609. if (url.indexOf("?") > -1) {
  610. url = url + "&" + key + "=" + value;
  611. } else {
  612. url += "?" + key + "=" + value;
  613. }
  614. }
  615. } else {
  616. if (trdata["in"] == "path") {
  617. url = url.replace("{" + key + "}", value);
  618. } else {
  619. if (trdata["in"] == "body") {
  620. bodyparams += value;
  621. } else {
  622. if (trdata["in"] == "header") {
  623. headerparams[key] = value;
  624. } else {
  625. params[key] = value;
  626. }
  627. }
  628. }
  629. }
  630. //判断是否required
  631. if (trdata.hasOwnProperty("required")) {
  632. var required = trdata["required"];
  633. if (required) {
  634. //必须,验证value是否为空
  635. if (value == null || value == "") {
  636. validateflag = true;
  637. var des = trdata["name"]
  638. validateobj = {message: des + "不能为空"};
  639. return false;
  640. }
  641. }
  642. }
  643. DApiUI.log("key:" + key + ",value:" + value);
  644. }
  645. })
  646. DApiUI.log("获取参数..")
  647. DApiUI.log(params);
  648. DApiUI.log(apiInfo)
  649. DApiUI.log("请求url:" + url);
  650. var reqdata = null;
  651. //console.log(paramBody.attr("reqtype"))
  652. var contType = "application/json; charset=UTF-8";
  653. if (paramBody.attr("reqtype") != null && paramBody.attr("reqtype") != undefined && paramBody.attr("reqtype") == "body") {
  654. reqdata = bodyparams;
  655. } else {
  656. reqdata = params;
  657. contType = "application/x-www-form-urlencoded; charset=UTF-8";
  658. }
  659. //console.log(reqdata)
  660. if (validateflag) {
  661. layer.msg(validateobj.message);
  662. return;
  663. }
  664. //判断是否有表单
  665. var form = $("#uploadForm");
  666. if (form.length > 0) {
  667. form[0].submit();
  668. //console.log("表单提交")
  669. //iframe监听change事件
  670. $("#uploadIframe").on("load", function () {
  671. //console.log("uploadIframe changed....")
  672. $(this).unbind('load');
  673. var framebody = $(this).contents().find("body");
  674. var ret = framebody.html();
  675. //是否存在pre标签
  676. if (framebody.find("pre").length > 0) {
  677. ret = framebody.find("pre").html();
  678. }
  679. var res;
  680. try {
  681. res = JSON.parse(ret);
  682. //console.log(res)
  683. var resptab = $('<div id="resptab" class="tabs-container" ></div>')
  684. var ulresp = $('<ul class="nav nav-tabs">' +
  685. '<li class=""><a data-toggle="tab" href="#tabresp" aria-expanded="false"> 响应内容 </a></li></ul>')
  686. resptab.append(ulresp);
  687. var respcontent = $('<div class="tab-content"></div>');
  688. var resp1 = $('<div id="tabresp" class="tab-pane active"><div class="panel-body"></div></div>');
  689. respcontent.append(resp1);
  690. resptab.append(respcontent)
  691. respcleanDiv.append(resptab);
  692. var jsondiv = $('<div></div>');
  693. jsondiv.JSONView(res);
  694. resp1.find(".panel-body").append(jsondiv);
  695. resptab.find("a:first").tab("show");
  696. } catch (err) {
  697. //nothing to do,default to show
  698. respcleanDiv.html(ret);
  699. }
  700. })
  701. } else {
  702. $.ajax({
  703. url: url,
  704. headers: headerparams,
  705. type: DApiUI.getStringValue(apiInfo.methodType),
  706. data: reqdata,
  707. contentType: contType,
  708. success: function (data, status, xhr) {
  709. var resptab = $('<div id="resptab" class="tabs-container" ></div>')
  710. var ulresp = $('<ul class="nav nav-tabs">' +
  711. '<li class=""><a data-toggle="tab" href="#tabresp" aria-expanded="false"> 响应内容 </a></li>' +
  712. '<li class=""><a data-toggle="tab" href="#tabcookie" aria-expanded="true"> Cookies</a></li>' +
  713. '<li class=""><a data-toggle="tab" href="#tabheader" aria-expanded="true"> Headers </a></li></ul>')
  714. resptab.append(ulresp);
  715. var respcontent = $('<div class="tab-content"></div>');
  716. var resp1 = $('<div id="tabresp" class="tab-pane active"><div class="panel-body"><pre></pre></div></div>');
  717. var resp2 = $('<div id="tabcookie" class="tab-pane active"><div class="panel-body">暂无</div>');
  718. var resp3 = $('<div id="tabheader" class="tab-pane active"><div class="panel-body">暂无</div></div>');
  719. respcontent.append(resp1).append(resp2).append(resp3);
  720. resptab.append(respcontent)
  721. respcleanDiv.append(resptab);
  722. DApiUI.log(xhr);
  723. DApiUI.log(xhr.getAllResponseHeaders());
  724. var allheaders = xhr.getAllResponseHeaders();
  725. if (allheaders != null && typeof (allheaders) != 'undefined' && allheaders != "") {
  726. var headers = allheaders.split("\r\n");
  727. var headertable = $('<table class="table table-hover table-bordered table-text-center"><tr><th>请求头</th><th>value</th></tr></table>');
  728. for (var i = 0; i < headers.length; i++) {
  729. var header = headers[i];
  730. if (header != null && header != "") {
  731. var headerValu = header.split(":");
  732. var headertr = $('<tr><th class="active">' + headerValu[0] + '</th><td>' + headerValu[1] + '</td></tr>');
  733. headertable.append(headertr);
  734. }
  735. }
  736. //设置Headers内容
  737. resp3.find(".panel-body").html("")
  738. resp3.find(".panel-body").append(headertable);
  739. }
  740. var contentType = xhr.getResponseHeader("Content-Type");
  741. DApiUI.log("Content-Type:" + contentType);
  742. DApiUI.log(xhr.hasOwnProperty("responseJSON"))
  743. if (xhr.hasOwnProperty("responseJSON")) {
  744. //如果存在该对象,服务端返回为json格式
  745. resp1.find(".panel-body").html("")
  746. DApiUI.log(xhr["responseJSON"])
  747. var pre = $('<pre></pre>')
  748. var jsondiv = $('<div></div>')
  749. jsondiv.JSONView(xhr["responseJSON"]);
  750. pre.html(JSON.stringify(xhr["responseJSON"], null, 2));
  751. resp1.find(".panel-body").append(jsondiv);
  752. } else {
  753. //判断content-type
  754. //如果是image资源
  755. var regex = new RegExp('image/(jpeg|jpg|png|gif)', 'g');
  756. if (regex.test(contentType)) {
  757. var d = DApiUI.getDoc().data("data");
  758. var imgUrl = "http://" + d.host + apiInfo.url;
  759. var img = document.createElement("img");
  760. img.onload = function (e) {
  761. window.URL.revokeObjectURL(img.src); // 清除释放
  762. };
  763. img.src = imgUrl;
  764. resp1.find(".panel-body").html("")
  765. resp1.find(".panel-body")[0].appendChild(img);
  766. } else {
  767. //判断是否是text
  768. var regex = new RegExp('.*?text.*', 'g');
  769. if (regex.test(contentType)) {
  770. resp1.find(".panel-body").html("")
  771. resp1.find(".panel-body").html(xhr.responseText);
  772. }
  773. }
  774. }
  775. DApiUI.log("tab show...")
  776. resptab.find("a:first").tab("show");
  777. },
  778. error: function (xhr, textStatus, errorThrown) {
  779. DApiUI.log("error.....")
  780. DApiUI.log(xhr);
  781. DApiUI.log(textStatus);
  782. DApiUI.log(errorThrown);
  783. var resptab = $('<div id="resptab" class="tabs-container" ></div>')
  784. var ulresp = $('<ul class="nav nav-tabs">' +
  785. '<li class=""><a data-toggle="tab" href="#tabresp" aria-expanded="false"> 响应内容 </a></li>' +
  786. '<li class=""><a data-toggle="tab" href="#tabcookie" aria-expanded="true"> Cookies</a></li>' +
  787. '<li class=""><a data-toggle="tab" href="#tabheader" aria-expanded="true"> Headers </a></li></ul>')
  788. resptab.append(ulresp);
  789. var respcontent = $('<div class="tab-content"></div>');
  790. var resp1 = $('<div id="tabresp" class="tab-pane active"><div class="panel-body"><pre></pre></div></div>');
  791. var resp2 = $('<div id="tabcookie" class="tab-pane active"><div class="panel-body">暂无</div>');
  792. var resp3 = $('<div id="tabheader" class="tab-pane active"><div class="panel-body">暂无</div></div>');
  793. respcontent.append(resp1).append(resp2).append(resp3);
  794. resptab.append(respcontent)
  795. respcleanDiv.append(resptab);
  796. DApiUI.log(xhr);
  797. DApiUI.log(xhr.getAllResponseHeaders());
  798. var allheaders = xhr.getAllResponseHeaders();
  799. if (allheaders != null && typeof (allheaders) != 'undefined' && allheaders != "") {
  800. var headers = allheaders.split("\r\n");
  801. var headertable = $('<table class="table table-hover table-bordered table-text-center"><tr><th>请求头</th><th>value</th></tr></table>');
  802. for (var i = 0; i < headers.length; i++) {
  803. var header = headers[i];
  804. if (header != null && header != "") {
  805. var headerValu = header.split(":");
  806. var headertr = $('<tr><th class="active">' + headerValu[0] + '</th><td>' + headerValu[1] + '</td></tr>');
  807. headertable.append(headertr);
  808. }
  809. }
  810. //设置Headers内容
  811. resp3.find(".panel-body").html("")
  812. resp3.find(".panel-body").append(headertable);
  813. }
  814. var contentType = xhr.getResponseHeader("Content-Type");
  815. DApiUI.log("Content-Type:" + contentType);
  816. var jsonRegex = "";
  817. DApiUI.log(xhr.hasOwnProperty("responseJSON"))
  818. if (xhr.hasOwnProperty("responseJSON")) {
  819. //如果存在该对象,服务端返回为json格式
  820. resp1.find(".panel-body").html("")
  821. DApiUI.log(xhr["responseJSON"])
  822. var jsondiv = $('<div></div>')
  823. jsondiv.JSONView(xhr["responseJSON"]);
  824. resp1.find(".panel-body").append(jsondiv);
  825. } else {
  826. //判断是否是text
  827. var regex = new RegExp('.*?text.*', 'g');
  828. if (regex.test(contentType)) {
  829. resp1.find(".panel-body").html("")
  830. resp1.find(".panel-body").html(xhr.responseText);
  831. }
  832. }
  833. DApiUI.log("tab show...")
  834. resptab.find("a:first").tab("show");
  835. }
  836. })
  837. }
  838. })
  839. }
  840. DApiUI.createDebugResponseTab = function (parent, data) {
  841. }
  842. DApiUI.writeUTF8 = function (str, isGetBytes) {
  843. var back = [],
  844. byteSize = 0;
  845. for (var i = 0; i < str.length; i++) {
  846. var code = str.charCodeAt(i);
  847. if (code >= 0 && code <= 127) {
  848. byteSize += 1;
  849. back.push(code);
  850. } else if (code >= 128 && code <= 2047) {
  851. byteSize += 2;
  852. back.push((192 | (31 & (code >> 6))));
  853. back.push((128 | (63 & code)))
  854. } else if (code >= 2048 && code <= 65535) {
  855. byteSize += 3;
  856. back.push((224 | (15 & (code >> 12))));
  857. back.push((128 | (63 & (code >> 6))));
  858. back.push((128 | (63 & code)))
  859. }
  860. }
  861. for (i = 0; i < back.length; i++) {
  862. if (back[i] > 255) {
  863. back[i] &= 255
  864. }
  865. }
  866. if (isGetBytes) {
  867. return back
  868. }
  869. if (byteSize <= 255) {
  870. return [0, byteSize].concat(back);
  871. } else {
  872. return [byteSize >> 8, byteSize & 255].concat(back);
  873. }
  874. }
  875. DApiUI.createApiInfoTable = function (apiInfo) {
  876. var table = $('<table class="table table-hover table-bordered table-text-center"></table>');
  877. var thead = $('<thead><tr><th colspan="2" style="text-align:center">API接口文档</th></tr></thead>');
  878. table.append(thead);
  879. var tbody = $('<tbody></tbody>');
  880. var url = $('<tr><th class="active" style="text-align: right;">接口url</th><td style="text-align: left"><code>' + DApiUI.getStringValue(apiInfo.url) + '</code></td></tr>');
  881. tbody.append(url);
  882. var summary = $('<tr><th class="active" style="text-align: right;">接口名称</th><td style="text-align: left">' + DApiUI.getStringValue(apiInfo.summary) + '</td></tr>');
  883. tbody.append(summary);
  884. var description = $('<tr><th class="active" style="text-align: right;">说明</th><td style="text-align: left">' + DApiUI.getStringValue(apiInfo.description) + '</td></tr>');
  885. tbody.append(description);
  886. var methodType = $('<tr><th class="active" style="text-align: right;">请求方式</th><td style="text-align: left"><code>' + DApiUI.getStringValue(apiInfo.methodType) + '</code></td></tr>');
  887. tbody.append(methodType);
  888. var consumesArr = DApiUI.getValue(apiInfo, "consumes", new Array(), true);
  889. var consumes = $('<tr><th class="active" style="text-align: right;">consumes</th><td style="text-align: left"><code>' + consumesArr + '</code></td></tr>');
  890. tbody.append(consumes);
  891. var producesArr = DApiUI.getValue(apiInfo, "produces", new Array(), true);
  892. var produces = $('<tr><th class="active" style="text-align: right;">produces</th><td style="text-align: left"><code>' + producesArr + '</code></td></tr>');
  893. tbody.append(produces);
  894. //请求参数
  895. var args = $('<tr><th class="active" style="text-align: right;">请求参数</th></tr>');
  896. //判断是否有请求参数
  897. if (typeof (apiInfo.parameters) != 'undefined' && apiInfo.parameters != null) {
  898. var ptd = $("<td></td>");
  899. var ptable = $('<table class="table table-bordered" id="requestModelTable"></table>')
  900. var phead = $('<thead><th>参数名称</th><th>说明</th><th>类型</th><th>in</th><th>是否必须</th></thead>');
  901. ptable.append(phead);
  902. var pbody = $('<tbody></tbody>');
  903. var requestArrs = new Array();
  904. $.each(apiInfo.parameters, function (i, param) {
  905. //判断是否是ref,如果是,列出他的属性说明
  906. var refflag = false;
  907. //判断是否有type属性,如果有,则后端为实体类形参
  908. var ptype = "string";
  909. var refType = "";
  910. if (param.hasOwnProperty("type")) {
  911. ptype = param["type"];
  912. } else {
  913. ///判断是有schma
  914. if (param.hasOwnProperty("schema")) {
  915. var schema = param["schema"];
  916. //是否有type
  917. if (schema.hasOwnProperty("type")) {
  918. ptype = schema["type"];
  919. if (ptype == "array") {
  920. var itm = schema["items"];
  921. if (itm.hasOwnProperty("$ref")) {
  922. //是否是ref
  923. var regex = new RegExp("#/definitions/(.*)$", "ig");
  924. if (regex.test(itm["$ref"])) {
  925. refflag = true;
  926. refType = RegExp.$1;
  927. }
  928. }
  929. }
  930. } else if (schema.hasOwnProperty("$ref")) {
  931. //是否是ref
  932. var regex = new RegExp("#/definitions/(.*)$", "ig");
  933. if (regex.test(schema["$ref"])) {
  934. refflag = true;
  935. ptype = RegExp.$1;
  936. }
  937. }
  938. }
  939. }
  940. var ptr = null;
  941. //列出属性
  942. var pobject = {
  943. id: generUUID(),
  944. field: param.name,
  945. description: DApiUI.getStringValue(param['description']),
  946. type: ptype,
  947. in: DApiUI.getStringValue(param['in']),
  948. required: param['required'],
  949. pid: ""
  950. };
  951. requestArrs.push(pobject);
  952. /*if (refflag){
  953. ptr=$('<tr><td>'+param.name+'</td><td style="text-align: center;">'+DApiUI.getStringValue(param['description'])+'</td><td>'+ptype+'</td><td>'+DApiUI.getStringValue(param['in'])+'</td><td>'+param['required']+'</td></tr>');
  954. pbody.append(ptr);
  955. var definitionsArray=DApiUI.getDoc().data("definitionsArray");
  956. var mcs=DApiUI.getMenuConstructs();
  957. for(var k in mcs.definitions){
  958. if(ptype==k){
  959. var tp=mcs.definitions[ptype];
  960. var props=tp["properties"];
  961. for(var prop in props){
  962. var pvalue=props[prop];
  963. var tr=$("<tr></tr>")
  964. tr.append($("<td style='text-align: right;'>"+prop+"</td>"))
  965. tr.append($("<td>"+DApiUI.toString(pvalue.description,"")+"</td>"));
  966. var type=DApiUI.toString(pvalue.type,"string");
  967. tr.append($("<td>"+type+"</td>"));
  968. tr.append($("<td>"+DApiUI.getStringValue(param['in'])+"</td>"));
  969. tr.append($("<td>"+param['required']+"</td>"));
  970. pbody.append(tr);
  971. }
  972. }
  973. }
  974. }else{
  975. ptr=$('<tr><td>'+param.name+'</td><td style="text-align: center;">'+DApiUI.getStringValue(param['description'])+'</td><td>'+ptype+'</td><td>'+DApiUI.getStringValue(param['in'])+'</td><td>'+param['required']+'</td></tr>');
  976. pbody.append(ptr);
  977. }*/
  978. if (refflag) {
  979. myFun(pobject, refType, param, requestArrs);
  980. /* var mcs=DApiUI.getMenuConstructs();
  981. for(var k in mcs.definitions){
  982. if(ptype==k){
  983. var tp=mcs.definitions[ptype];
  984. var props=tp["properties"];
  985. for(var prop in props){
  986. var pvalue=props[prop];
  987. var type=DApiUI.toString(pvalue.type,"string");
  988. var cobj={id:generUUID(),field:prop,description:DApiUI.toString(pvalue.description,""),type:type,in:DApiUI.getStringValue(param['in']),required:param['required'],pid:pobject.id};
  989. requestArrs.push(cobj);
  990. }
  991. }
  992. }*/
  993. }
  994. })
  995. if (requestArrs.length > 0) {
  996. for (var i = 0; i < requestArrs.length; i++) {
  997. var arrInfo = requestArrs[i];
  998. var treeClassId = "treegrid-" + arrInfo.id;
  999. var treeClassPId = "";
  1000. if (arrInfo.pid != "") {
  1001. treeClassPId = "treegrid-parent-" + arrInfo.pid;
  1002. }
  1003. var tr = $("<tr class='" + treeClassId + " " + treeClassPId + "'></tr>");
  1004. tr.append("<td>" + arrInfo.field + "</td><td>" + arrInfo.description + "</td><td>" + arrInfo.type + "</td><td>" + arrInfo.in + "</td><td>" + arrInfo.required + "</td>");
  1005. pbody.append(tr);
  1006. }
  1007. } else {
  1008. tbody.append("<tr><td colspan='5'>暂无</td></tr>")
  1009. }
  1010. ptable.append(pbody);
  1011. ptd.append(ptable);
  1012. args.append(ptd);
  1013. } else {
  1014. args.append($('<td style="text-align: left">暂无</td>'));
  1015. }
  1016. tbody.append(args);
  1017. //响应数据结构
  1018. var responseConstruct = $('<tr><th class="active" style="text-align: right;">响应Model</th></tr>');
  1019. var responseConstructtd = $('<td style="text-align: left"></td>')
  1020. responseConstructtd.append(DApiUI.createResponseDefinition(apiInfo));
  1021. responseConstruct.append(responseConstructtd);
  1022. tbody.append(responseConstruct)
  1023. //响应参数 add by xiaoymin 2017-8-20 16:17:18
  1024. var respParams = $('<tr><th class="active" style="text-align: right;">响应参数说明</th></tr>');
  1025. var respPart = $('<td style="text-align: left"></td>');
  1026. respPart.append(DApiUI.createResponseDefinitionDetail(apiInfo));
  1027. respParams.append(respPart);
  1028. tbody.append(respParams);
  1029. //响应状态码
  1030. var response = $('<tr><th class="active" style="text-align: right;">响应</th></tr>');
  1031. if (typeof (apiInfo.responses) != 'undefined' && apiInfo.responses != null) {
  1032. var resp = apiInfo.responses;
  1033. var ptd = $("<td></td>");
  1034. var ptable = $('<table class="table table-bordered"></table>')
  1035. var phead = $('<thead><th>状态码</th><th>说明</th><th>schema</th></thead>');
  1036. ptable.append(phead);
  1037. var pbody = $('<tbody></tbody>');
  1038. for (var status in resp) {
  1039. var rescrobj = resp[status];
  1040. var schematd = $("<td></td>");
  1041. //判断是否存在schma
  1042. if (rescrobj.hasOwnProperty("schema")) {
  1043. var schema = rescrobj["schema"];
  1044. var regex = new RegExp("#/definitions/(.*)$", "ig");
  1045. if (regex.test(schema["$ref"])) {
  1046. var ptype = RegExp.$1;
  1047. schematd.append(ptype);
  1048. }
  1049. }
  1050. var tr = $("<tr></tr>")
  1051. var statusTd = $("<td>" + status + "</td>");
  1052. var description = $("<td>" + rescrobj["description"] + "</td>");
  1053. tr.append(statusTd).append(description).append(schematd);
  1054. pbody.append(tr);
  1055. }
  1056. /*if(resp.hasOwnProperty("200")){
  1057. var ptr=$('<tr><td>200</td><td>http响应成功</td><td></td></tr>');
  1058. pbody.append(ptr);
  1059. }
  1060. //400
  1061. pbody.append($('<tr><td>400</td><td>Bad Request 请求出现语法错误,一般是请求参数不对</td><td></td></tr>'));
  1062. //404
  1063. pbody.append($('<tr><td>404</td><td>Not Found 无法找到指定位置的资源</td><td></td></tr>'));
  1064. //401
  1065. pbody.append($('<tr><td>401</td><td>Unauthorized 访问被拒绝</td><td></td></tr>'));
  1066. //403
  1067. pbody.append($('<tr><td>403</td><td>Forbidden 资源不可用</td><td></td></tr>'));
  1068. //500
  1069. pbody.append($('<tr><td>500</td><td>服务器内部错误,请联系Java后台开发人员!!!</td><td></td></tr>'));*/
  1070. ptable.append(pbody);
  1071. ptd.append(ptable);
  1072. response.append(ptd);
  1073. } else {
  1074. response.append($("<td>暂无</td>"));
  1075. }
  1076. tbody.append(response);
  1077. table.append(tbody);
  1078. DApiUI.creatabTab();
  1079. //内容覆盖
  1080. //DApiUI.getDoc().html("");
  1081. //查找接口doc
  1082. DApiUI.getDoc().find("#tab1").find(".panel-body").html("")
  1083. DApiUI.getDoc().find("#tab1").find(".panel-body").append(table);
  1084. //DApiUI.getDoc().append(table);
  1085. setTimeout(function () {
  1086. DApiUI.log("执行treegrid方法...")
  1087. //请求参数调用treegruid方法
  1088. $("#requestModelTable").treegrid({
  1089. expanderExpandedClass: 'glyphicon glyphicon-minus',
  1090. expanderCollapsedClass: 'glyphicon glyphicon-plus'
  1091. });
  1092. }, 100);
  1093. }
  1094. /***
  1095. * 响应参数详情
  1096. * @param apiInfo
  1097. */
  1098. DApiUI.createResponseDefinitionDetail = function (apiInfo) {
  1099. var resp = apiInfo.responses;
  1100. var div = $("<div class='panel'></div>");
  1101. if (resp.hasOwnProperty("200")) {
  1102. var ok = resp["200"];
  1103. if (ok.hasOwnProperty("schema")) {
  1104. var schema = ok["schema"];
  1105. var ref = schema["$ref"];
  1106. var regex = new RegExp("#/definitions/(.*)$", "ig");
  1107. if (regex.test(ref)) {
  1108. var refType = RegExp.$1;
  1109. var definitionsArray = DApiUI.getDoc().data("definitionsArray");
  1110. var mcs = DApiUI.getMenuConstructs();
  1111. for (var k in mcs.definitions) {
  1112. if (refType == k) {
  1113. var table = $("<table class=\"table table-bordered\" id='modelPropertisTab'>");
  1114. table.append('<thead><tr><th>参数名称</th><th>类型</th><th>说明</th></tr></thead>');
  1115. var tp = mcs.definitions[refType];
  1116. var props = tp["properties"];
  1117. var arrInfos = new Array();
  1118. var tbody = $("<tbody></tbody>")
  1119. for (var prop in props) {
  1120. deepTree("", prop, props, mcs.definitions, arrInfos);
  1121. }
  1122. if (arrInfos.length > 0) {
  1123. for (var i = 0; i < arrInfos.length; i++) {
  1124. var arrInfo = arrInfos[i];
  1125. var treeClassId = "treegrid-" + arrInfo.id;
  1126. var treeClassPId = "";
  1127. if (arrInfo.pid != "") {
  1128. treeClassPId = "treegrid-parent-" + arrInfo.pid;
  1129. }
  1130. var tr = $("<tr class='" + treeClassId + " " + treeClassPId + "'></tr>");
  1131. tr.append("<td>" + arrInfo.field + "</td><td>" + arrInfo.type + "</td><td>" + arrInfo.description + "</td>");
  1132. tbody.append(tr);
  1133. }
  1134. } else {
  1135. tbody.append("<tr><td colspan='3'>暂无</td></tr>")
  1136. }
  1137. /*for(var prop in props){
  1138. deepTree("",prop,props,mcs.definitions,arrInfos);
  1139. var pvalue=props[prop];
  1140. var tr=$("<tr></tr>")
  1141. //只遍历一级属性
  1142. //判断是否是ref
  1143. if(pvalue.hasOwnProperty("$ref")){
  1144. var param_ref = pvalue["$ref"];
  1145. var regex1 = new RegExp("#/definitions/(.*)$", "ig");
  1146. if(regex1.test((param_ref))){
  1147. var ptype=RegExp.$1;
  1148. tr.append($("<td>"+prop+"</td>"))
  1149. tr.append($("<td>"+ptype+"</td>"))
  1150. tr.append($("<td></td>"))
  1151. tbody.append(tr);
  1152. for(var j in mcs.definitions) {
  1153. if (ptype == j) {
  1154. var tpp=mcs.definitions[ptype];
  1155. var pp_props=tpp["properties"];
  1156. for(var prop1 in pp_props) {
  1157. var tr1=$("<tr></tr>")
  1158. var pvalue1 = pp_props[prop1];
  1159. tr1.append($("<td style='text-align: right;'>" + prop1 + "</td>"));
  1160. tr1.append($("<td>"+DApiUI.getValue(pvalue1,"type","string",true)+"</td>"));
  1161. tr1.append($("<td>"+DApiUI.getValue(pvalue1,"description","",true)+"</td>"));
  1162. tbody.append(tr1);
  1163. }
  1164. }
  1165. }
  1166. }
  1167. }else{
  1168. tr.append($("<td>"+prop+"</td>"))
  1169. var type=DApiUI.toString(pvalue.type,"string");
  1170. tr.append($("<td>"+type+"</td>"));
  1171. tr.append($("<td>"+DApiUI.toString(pvalue.description,"")+"</td>"));
  1172. tbody.append(tr);
  1173. }
  1174. }*/
  1175. DApiUI.log("deepTree")
  1176. DApiUI.log(arrInfos)
  1177. table.append(tbody);
  1178. div.append(table)
  1179. setTimeout(function () {
  1180. DApiUI.log("执行treegrid方法...")
  1181. table.treegrid({
  1182. expanderExpandedClass: 'glyphicon glyphicon-minus',
  1183. expanderCollapsedClass: 'glyphicon glyphicon-plus'
  1184. });
  1185. }, 100);
  1186. }
  1187. }
  1188. }
  1189. }
  1190. }
  1191. return div;
  1192. }
  1193. function deepTree(pid, prop, props, definitions, arrs) {
  1194. var regex1 = new RegExp("#/definitions/(.*)$", "ig");
  1195. var pvalue = props[prop];
  1196. if (pvalue.hasOwnProperty("$ref")) {
  1197. DApiUI.log("deepTree--ref---" + prop)
  1198. var param_ref = pvalue["$ref"];
  1199. if (regex1.test((param_ref))) {
  1200. var ptype = RegExp.$1;
  1201. var arrObj = {id: generUUID(), field: prop, type: ptype, description: "", pid: pid};
  1202. arrs.push(arrObj);
  1203. for (var j in definitions) {
  1204. if (ptype == j) {
  1205. var tpp = definitions[ptype];
  1206. var pp_props = tpp["properties"];
  1207. for (var prop1 in pp_props) {
  1208. if (prop1 != prop) {
  1209. deepTree(arrObj.id, prop1, pp_props, definitions, arrs);
  1210. }
  1211. }
  1212. }
  1213. }
  1214. }
  1215. } else {
  1216. DApiUI.log("deepTree--single---" + prop)
  1217. //属性名称prop
  1218. var id = generUUID();
  1219. var type = DApiUI.toString(pvalue.type, "string");
  1220. var description = DApiUI.toString(pvalue.description, "");
  1221. var obj = {id: id, type: type, field: prop, description: description, pid: pid};
  1222. arrs.push(obj);
  1223. //判断是否是数组
  1224. if (type == "array") {
  1225. DApiUI.log("array...")
  1226. var items = pvalue["items"];
  1227. DApiUI.log(pvalue);
  1228. DApiUI.log(items);
  1229. DApiUI.log(pvalue.items);
  1230. if (items.hasOwnProperty("$ref")) {
  1231. var item_ref = items["$ref"];
  1232. DApiUI.log(item_ref);
  1233. if (regex1.test((item_ref))) {
  1234. var ptype = RegExp.$1;
  1235. DApiUI.log(ptype);
  1236. //获取到对象类名
  1237. for (var j in definitions) {
  1238. if (ptype == j) {
  1239. var tpp = definitions[ptype];
  1240. var pp_props = tpp["properties"];
  1241. for (var prop1 in pp_props) {
  1242. if (prop1 != prop) {
  1243. deepTree(obj.id, prop1, pp_props, definitions, arrs);
  1244. }
  1245. }
  1246. }
  1247. }
  1248. }
  1249. }
  1250. }
  1251. }
  1252. }
  1253. function randomNumber() {
  1254. return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
  1255. }
  1256. /***
  1257. *
  1258. * 生成uuid
  1259. * @returns {string}
  1260. */
  1261. function generUUID() {
  1262. return (randomNumber() + randomNumber() + "-" + randomNumber() + "-" + randomNumber() + "-" + randomNumber() + "-" + randomNumber() + randomNumber() + randomNumber());
  1263. }
  1264. /***
  1265. * 递归
  1266. */
  1267. function deepProperties(ref, obj) {
  1268. var regex = new RegExp("#/definitions/(.*)$", "ig");
  1269. if (regex.test(ref)) {
  1270. var refType = RegExp.$1;
  1271. var definitionsArray = DApiUI.getDoc().data("definitionsArray");
  1272. }
  1273. }
  1274. DApiUI.createResponseDefinition = function (apiInfo) {
  1275. var resp = apiInfo.responses;
  1276. var div = $("<div class='panel'>暂无</div>");
  1277. if (resp.hasOwnProperty("200")) {
  1278. var ok = resp["200"];
  1279. if (ok.hasOwnProperty("schema")) {
  1280. var schema = ok["schema"];
  1281. var ref = schema["$ref"];
  1282. var regex = new RegExp("#/definitions/(.*)$", "ig");
  1283. if (regex.test(ref)) {
  1284. var refType = RegExp.$1;
  1285. //这里去definitionsArrar查找,如果未找到,直接展示refType
  1286. var flag = false;
  1287. var htmlValue = refType;
  1288. var definitionsArray = DApiUI.getDoc().data("definitionsArray");
  1289. for (var i = 0; i < definitionsArray.length; i++) {
  1290. var definition = definitionsArray[i];
  1291. if (definition.key == refType) {
  1292. flag = true;
  1293. htmlValue = definition.value;
  1294. break;
  1295. }
  1296. }
  1297. div.html("")
  1298. if (flag) {
  1299. div.JSONView(htmlValue);
  1300. } else {
  1301. div.html(refType);
  1302. }
  1303. } else {
  1304. //未发现ref属性
  1305. if (schema.hasOwnProperty("type")) {
  1306. div.html("")
  1307. var type = schema["type"];
  1308. if (type == "array") {
  1309. var items = schema["items"];
  1310. ref = items["$ref"];
  1311. var regex = new RegExp("#/definitions/(.*)$", "ig");
  1312. if (regex.test(ref)) {
  1313. var refType = RegExp.$1;
  1314. //这里去definitionsArrar查找,如果未找到,直接展示refType
  1315. var flag = false;
  1316. var htmlValue = refType;
  1317. var definitionsArray = DApiUI.getDoc().data("definitionsArray");
  1318. for (var i = 0; i < definitionsArray.length; i++) {
  1319. var definition = definitionsArray[i];
  1320. if (definition.key == refType) {
  1321. flag = true;
  1322. htmlValue = definition.value;
  1323. break;
  1324. }
  1325. }
  1326. div.html("")
  1327. if (flag) {
  1328. var obj = new Array();
  1329. obj.push(htmlValue);
  1330. div.JSONView(obj);
  1331. } else {
  1332. div.html(refType);
  1333. }
  1334. }
  1335. } else {
  1336. div.html(type);
  1337. }
  1338. }
  1339. }
  1340. }
  1341. }
  1342. return div;
  1343. }
  1344. DApiUI.definitions = function (menu) {
  1345. var definitionsArray = new Array();
  1346. DApiUI.log("definitionsArray....")
  1347. if (menu != null && typeof (menu) != "undefined" && menu.hasOwnProperty("definitions")) {
  1348. var definitions = menu["definitions"];
  1349. for (var definition in definitions) {
  1350. var defiType = new definitionType();
  1351. defiType.key = definition;
  1352. //获取value
  1353. var value = definitions[definition];
  1354. if (checkUndefined(value)) {
  1355. //是否有properties
  1356. if (value.hasOwnProperty("properties")) {
  1357. var properties = value["properties"];
  1358. var defiTypeValue = {};
  1359. for (var property in properties) {
  1360. var propobj = properties[property];
  1361. //默认string类型
  1362. var propValue = "";
  1363. //判断是否有类型
  1364. if (propobj.hasOwnProperty("type")) {
  1365. var type = propobj["type"];
  1366. //判断是否有example
  1367. if (propobj.hasOwnProperty("example")) {
  1368. propValue = propobj["example"];
  1369. } else if (checkIsBasicType(type)) {
  1370. propValue = getBasicTypeValue(type);
  1371. } else {
  1372. if (type == "array") {
  1373. propValue = new Array();
  1374. var items = propobj["items"];
  1375. var ref = items["$ref"];
  1376. var regex = new RegExp("#/definitions/(.*)$", "ig");
  1377. if (regex.test(ref)) {
  1378. var refType = RegExp.$1;
  1379. //这里需要递归判断是否是本身,如果是,则退出递归查找
  1380. if (refType != definition) {
  1381. propValue.push(findRefDefinition(refType, definitions, false));
  1382. } else {
  1383. propValue.push(findRefDefinition(refType, definitions, true));
  1384. }
  1385. }
  1386. }
  1387. }
  1388. } else {
  1389. if (propobj.hasOwnProperty("$ref")) {
  1390. var ref = propobj["$ref"];
  1391. var regex = new RegExp("#/definitions/(.*)$", "ig");
  1392. if (regex.test(ref)) {
  1393. var refType = RegExp.$1;
  1394. //这里需要递归判断是否是本身,如果是,则退出递归查找
  1395. if (refType != definition) {
  1396. propValue = findRefDefinition(refType, definitions, false);
  1397. } else {
  1398. propValue = findRefDefinition(refType, definitions, true);
  1399. }
  1400. }
  1401. } else {
  1402. propValue = {};
  1403. }
  1404. }
  1405. defiTypeValue[property] = propValue;
  1406. }
  1407. defiType.value = defiTypeValue;
  1408. } else {
  1409. defiType.value = {};
  1410. }
  1411. }
  1412. definitionsArray.push(defiType);
  1413. }
  1414. }
  1415. DApiUI.getDoc().data("definitionsArray", definitionsArray);
  1416. }
  1417. DApiUI.getDefinitions = function () {
  1418. return DApiUI.getDoc().data("definitionsArray");
  1419. }
  1420. function checkIsBasicType(type) {
  1421. var basicTypes = ["string", "integer", "number", "object", "boolean"];
  1422. var flag = false;
  1423. if ($.inArray(type, basicTypes) > -1) {
  1424. flag = true;
  1425. }
  1426. return flag;
  1427. }
  1428. function getBasicTypeValue(type) {
  1429. var propValue = "";
  1430. //是否是基本类型
  1431. if (type == "integer") {
  1432. propValue = 0;
  1433. }
  1434. if (type == "boolean") {
  1435. propValue = true;
  1436. }
  1437. if (type == "object") {
  1438. propValue = {};
  1439. }
  1440. if (type == "number") {
  1441. propValue = parseFloat(0);
  1442. }
  1443. return propValue;
  1444. }
  1445. function findRefDefinition(definitionName, definitions, flag) {
  1446. var defaultValue = "";
  1447. for (var definition in definitions) {
  1448. if (definitionName == definition) {
  1449. var value = definitions[definition];
  1450. //是否有properties
  1451. if (value.hasOwnProperty("properties")) {
  1452. var properties = value["properties"];
  1453. var defiTypeValue = {};
  1454. for (var property in properties) {
  1455. var propobj = properties[property];
  1456. //默认string类型
  1457. var propValue = "";
  1458. //判断是否有类型
  1459. if (propobj.hasOwnProperty("type")) {
  1460. var type = propobj["type"];
  1461. //判断是否有example
  1462. if (propobj.hasOwnProperty("example")) {
  1463. propValue = propobj["example"];
  1464. } else if (checkIsBasicType(type)) {
  1465. propValue = getBasicTypeValue(type);
  1466. } else {
  1467. if (type == "array") {
  1468. propValue = new Array();
  1469. var items = propobj["items"];
  1470. var ref = items["$ref"];
  1471. var regex = new RegExp("#/definitions/(.*)$", "ig");
  1472. if (regex.test(ref)) {
  1473. var refType = RegExp.$1;
  1474. if (!flag) {
  1475. //非递归查找
  1476. if (refType != definitionName) {
  1477. propValue.push(findRefDefinition(refType, definitions, flag));
  1478. } else {
  1479. propValue.push(findRefDefinition(refType, definitions, true));
  1480. }
  1481. }
  1482. }
  1483. }
  1484. }
  1485. } else {
  1486. }
  1487. defiTypeValue[property] = propValue;
  1488. }
  1489. defaultValue = defiTypeValue;
  1490. } else {
  1491. defaultValue = {};
  1492. }
  1493. }
  1494. }
  1495. return defaultValue;
  1496. }
  1497. function checkUndefined(obj) {
  1498. var flag = false;
  1499. if (obj != null && typeof (obj) != "undefined") {
  1500. flag = true;
  1501. }
  1502. return flag;
  1503. }
  1504. function definitionType() {
  1505. this.key = "";
  1506. this.value = {};
  1507. }
  1508. /***
  1509. * 获取默认请求参数类型
  1510. * @param obj
  1511. * @returns {string}
  1512. */
  1513. DApiUI.getDefaultRequiredType = function (obj) {
  1514. var t = "string";
  1515. if (typeof (obj) != 'undefined' && obj != null) {
  1516. t = obj.toString();
  1517. }
  1518. return t;
  1519. }
  1520. /***
  1521. * 查找子类
  1522. * @param tagInfo
  1523. * @param menu
  1524. */
  1525. DApiUI.initChildrens = function (tagInfo, menu) {
  1526. }
  1527. DApiUI.getDoc = function () {
  1528. return $("#content");
  1529. }
  1530. DApiUI.getMenu = function () {
  1531. return $("#menu");
  1532. }
  1533. DApiUI.log = function (msg) {
  1534. if (window.console) {
  1535. console.log(msg);
  1536. }
  1537. }
  1538. DApiUI.init();
  1539. /***
  1540. * 标签组信息
  1541. * @constructor
  1542. */
  1543. function TagInfo(name, description) {
  1544. this.name = name;
  1545. this.description = description;
  1546. this.childrens = new Array();
  1547. }
  1548. /***
  1549. * api实体信息
  1550. * @param options
  1551. * @constructor
  1552. */
  1553. function ApiInfo(options) {
  1554. //判断options
  1555. this.tag = [];
  1556. this.url = "";
  1557. this.description = "";
  1558. this.operationId = "";
  1559. this.parameters = new Array();
  1560. this.produces = new Array();
  1561. this.responses = {};
  1562. this.methodType = "post";
  1563. this.consumes = new Array();
  1564. this.summary = "";
  1565. if (options != null && typeof (options) != 'undefined') {
  1566. this.tag = options.tags;
  1567. this.description = options.description;
  1568. this.operationId = options.operationId;
  1569. this.summary = options.summary;
  1570. this.parameters = options.parameters;
  1571. this.produces = options.produces;
  1572. this.responses = options.responses;
  1573. this.consumes = options.consumes;
  1574. }
  1575. }
  1576. /*create by xujingyang 2018/06/30 修复参数类属性还是实体类不显示的问题,递归获取*/
  1577. function myFun(pobject, ptype, param, requestArrs) {
  1578. var mcs = DApiUI.getMenuConstructs();
  1579. for (var k in mcs.definitions) {
  1580. if (ptype == k) {
  1581. var tp = mcs.definitions[ptype];
  1582. var props = tp["properties"];
  1583. for (var prop in props) {
  1584. var pvalue = props[prop];
  1585. var type = DApiUI.toString(pvalue.type, "string");
  1586. var cobj = {
  1587. id: generUUID(),
  1588. field: prop,
  1589. description: DApiUI.toString(pvalue.description, ""),
  1590. type: type,
  1591. in: DApiUI.getStringValue(param['in']),
  1592. required: param['required'],
  1593. pid: pobject.id
  1594. };
  1595. requestArrs.push(cobj);
  1596. if (pvalue.hasOwnProperty("items")) {
  1597. var myItems = pvalue["items"];
  1598. if (myItems.hasOwnProperty("$ref")) {
  1599. //是否是ref
  1600. var regex = new RegExp("#/definitions/(.*)$", "ig");
  1601. if (regex.test(myItems["$ref"])) {
  1602. refflag = true;
  1603. ptype2 = RegExp.$1;
  1604. myFun(cobj, ptype2, param, requestArrs);
  1605. }
  1606. }
  1607. }
  1608. }
  1609. }
  1610. }
  1611. }
  1612. })(jQuery)