【发布时间】: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