【问题标题】:Swagger UI - not able to expand operationsSwagger UI - 无法扩展操作
【发布时间】:2015-01-08 05:24:59
【问题描述】:

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

我已经在代码中添加了API注解,我可以通过

localhost: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"));

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

【问题讨论】:

  • 你使用哪个版本的 swagger-ui?
  • 我使用的是最新版本。不知何故,我找到了原因。 ApiOperation Annotation 中有一个昵称字段。这是必需的。如果昵称字段没有配置,那么我们将无法展开操作。

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


【解决方案1】:

有两个问题。

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

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

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

【讨论】:

    猜你喜欢
    • 2016-03-01
    • 1970-01-01
    • 2013-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-14
    • 2016-04-04
    相关资源
    最近更新 更多