Swagger.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. 'use strict';
  2. //document.title = "智慧推演引擎API";
  3. $("#logo").html("智慧应急演练培训平台 开放性接口").attr("href", "/Home/Index");
  4. $("#header form").hide();
  5. $('[rel="icon"]').attr("href", "http://shvber.com/favicon/we/favicon.ico");
  6. $('[rel="shortcut icon"]').attr("href", "http://shvber.com/favicon/we/favicon.ico");
  7. $('body').append('<style type="text/css">.controller-summary{color:#10a54a !important;word-break:keep-all;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;max-width:250px;text-align:right;cursor:default;} </style>');
  8. window.SwaggerTranslator = {
  9. _words: [],
  10. translate: function () {
  11. var $this = this;
  12. $('[data-sw-translate]').each(function () {
  13. $(this).html($this._tryTranslate($(this).html()));
  14. $(this).val($this._tryTranslate($(this).val()));
  15. $(this).attr('title', $this._tryTranslate($(this).attr('title')));
  16. });
  17. },
  18. setControllerSummary: function () {
  19. $.ajax({
  20. type: "get",
  21. async: true,
  22. url: $("#input_baseUrl").val(),
  23. dataType: "json",
  24. success: function (data) {
  25. var summaryDict = data.ControllerDesc;
  26. var id, controllerName, strSummary;
  27. $("#resources_container .resource").each(function (i, item) {
  28. id = $(item).attr("id");
  29. if (id) {
  30. controllerName = id.substring(9);
  31. strSummary = summaryDict[controllerName];
  32. if (strSummary) {
  33. $(item).children(".heading").find("h2 a").text(strSummary);
  34. $(item).children(".heading").children(".options").first().prepend('<li class="controller-summary" title="' + strSummary + '">' + strSummary + '</li>');
  35. }
  36. }
  37. });
  38. }
  39. });
  40. },
  41. _tryTranslate: function (word) {
  42. return this._words[$.trim(word)] !== undefined ? this._words[$.trim(word)] : word;
  43. },
  44. learn: function (wordsMap) {
  45. this._words = wordsMap;
  46. }
  47. };
  48. /* jshint quotmark: double */
  49. window.SwaggerTranslator.learn({
  50. "Warning: Deprecated": "警告:已过时",
  51. "Implementation Notes": "实现备注",
  52. "Response Class": "响应类",
  53. "Status": "状态",
  54. "Parameters": "参数",
  55. "Parameter": "参数",
  56. "Value": "值",
  57. "Description": "描述",
  58. "Parameter Type": "参数类型",
  59. "Data Type": "数据类型",
  60. "Response Messages": "响应消息",
  61. "HTTP Status Code": "HTTP状态码",
  62. "Reason": "原因",
  63. "Response Model": "响应模型",
  64. "Request URL": "请求URL",
  65. "Response Body": "响应体",
  66. "Response Code": "响应码",
  67. "Response Headers": "响应头",
  68. "Hide Response": "隐藏响应",
  69. "Headers": "头",
  70. "Try it out!": "试一下!",
  71. "Show/Hide": "显示/隐藏",
  72. "List Operations": "隐藏操作",
  73. "Expand Operations": "展开操作",
  74. "Raw": "原始",
  75. "can't parse JSON. Raw result": "无法解析JSON. 原始结果",
  76. "Model Schema": "模型架构",
  77. "Model": "模型",
  78. "apply": "应用",
  79. "Username": "用户名",
  80. "Password": "密码",
  81. "Terms of service": "服务条款",
  82. "Created by": "创建者",
  83. "See more at": "查看更多:",
  84. "Contact the developer": "联系开发者",
  85. "api version": "api版本",
  86. "Response Content Type": "响应Content Type",
  87. "fetching resource": "正在获取资源",
  88. "fetching resource list": "正在获取资源列表",
  89. "Explore": "浏览",
  90. "Show Swagger Petstore Example Apis": "显示 Swagger Petstore 示例 Apis",
  91. "Can't read from server. It may not have the appropriate access-control-origin settings.": "无法从服务器读取。可能没有正确设置access-control-origin。",
  92. "Please specify the protocol for": "请指定协议:",
  93. "Can't read swagger JSON from": "无法读取swagger JSON于",
  94. "Finished Loading Resource Information. Rendering Swagger UI": "已加载资源信息。正在渲染Swagger UI",
  95. "Unable to read api": "无法读取api",
  96. "from path": "从路径",
  97. "server returned": "服务器返回",
  98. });
  99. $(function () {
  100. window.SwaggerTranslator.translate();
  101. window.SwaggerTranslator.setControllerSummary();
  102. var getCookieValue = function (key) {
  103. var equalities = document.cookie.split('; ');
  104. for (var i = 0; i < equalities.length; i++) {
  105. if (!equalities[i]) {
  106. continue;
  107. }
  108. var splitted = equalities[i].split('=');
  109. if (splitted.length !== 2) {
  110. continue;
  111. }
  112. if (decodeURIComponent(splitted[0]) === key) {
  113. return decodeURIComponent(splitted[1] || '');
  114. }
  115. }
  116. return null;
  117. };
  118. var csrfCookie = getCookieValue("XSRF-TOKEN");
  119. var csrfCookieAuth = new SwaggerClient.ApiKeyAuthorization("X-XSRF-TOKEN", csrfCookie, "header");
  120. swaggerUi.api.clientAuthorizations.add("X-XSRF-TOKEN", csrfCookieAuth);
  121. });