Swagger.js 4.9 KB

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