Swagger.js 4.7 KB

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