0

我正在尝试将 swagger 与播放框架一起使用。

我在代码中添加了 API 注释,我可以通过

本地主机:9000/api-docs

{
    apiVersion: "beta",
    swaggerVersion: "1.2",
    basePath: "http://localhost",
    resourcePath: "/metrics",
    produces: [
      "application/json"
    ],
    apis: [
      {
         path: "/metrics",
         operations: [
            {
              method: "POST",
              summary: "Save metrics",
              ...
              authorizations: { },
              parameters: [ ],
              responseMessages: [
                 {
                    code: 400,
                    message: "Expecting Json data"
                 },
              ]
            }
         ]
      }
   ]
}

但是当我尝试使用 swagger ui 探索它时,我无法扩展或列出操作。

在 swagger ui index.html 中,我进行了以下更改。

$(function () {
  var url = window.location.search.match(/url=([^&]+)/);
  if (url && url.length > 1) {
    url = url[1];
  } else {
    url = "http://localhost:9000/api-docs";
  }
...

  window.authorizations.add("Accept", new ApiKeyAuthorization("Accept", "application/json", "header"));

我是否缺少任何配置。请提供建议或指点。

4

1 回答 1

0

有两个问题。

  1. 未正确配置基本 URL。我在 conf 文件中添加了以下字段来解决这个问题。

    swagger.api.basepath="http://localhost:9000/"

  2. ApiOperation Annotation 中有一个昵称字段。这是必需的。如果没有给出昵称字段,那么我们将无法在 UI 中展开操作。

于 2015-01-09T04:55:36.757 回答