Swagger UI - 无法扩展操作

时间:2015-01-08 05:24:59

标签: playframework-2.0 swagger swagger-ui swagger-play2

我正在尝试使用游戏框架的招摇。

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

访问它

本地主机:9000 / API-文档

{
    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"
                 },
              ]
            }
         ]
      }
   ]
}

但是当我尝试用昂首阔步的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"));

我错过了任何配置。请提供建议或指示。

1 个答案:

答案 0 :(得分:0)

有两个问题。

  1. 未正确配置基本网址。我在conf文件中添加了以下字段来修复它。

    swagger.api.basepath = “HTTP://本地主机:9000 /”

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

相关问题