2

我目前正在使用 Swagger 记录 Play 2.1 应用程序。我设法让它编译成功,但它没有显示任何关于生成的 JSON 的信息。

本地主机:9000/api-docs.json

{
  apiVersion: "0.1",
  swaggerVersion: "1.1",
  basePath: "http://localhost:9000"
}

本地主机:9000/api-docs.json/items

{
  code: 500,
  message: "api listing for path /api-docs.json/items not found",
  type: "unknown"
}

这是控制器对象的注释:

@Api(value = "/items", listingPath = "/api-docs.{format}/items", description = "Operations about Items")
object ItemController extends Controller {

这些是控制器方法的注释:

  @ApiOperation(value = "Gets the item of a specific ID", notes = "Returns an Item", responseClass = "Item", httpMethod = "GET")
  @ApiErrors(Array(
    new ApiError(code = 400, reason = "Invalid ID supplied"),
    new ApiError(code = 404, reason = "Item not found")))
  def get(@ApiParam(value="Id of the Item to Fetch")@PathParam("id") id: Long) = Action{ request => controller.get(id: Long) }

这些是 application.conf 上所需的配置:

api.version="0.1"
swagger.api.basepath="http://localhost:9000"
#swagger.security.filter="security.AuthorizationFilter"

上面显示的代码遵循 Swagger 的文档提供的示例应用程序。您知道 Play 2.1 上的任何工作示例吗?关于什么是错的或缺少什么的任何线索?

提前致谢。

编辑:路由文件部分:

GET     /api-docs.json                 controllers.ApiHelpController.getResources
GET     /api-docs.json/items           controllers.ApiHelpController.getResource(path = "/api-docs.json/items")
4

2 回答 2

0

play2 的 swagger-core 中的示例适用于 play 2.1:

https://github.com/wordnik/swagger-core/tree/scala_2.10.0/samples/scala-play2

看到你有最新的 swagger-play2 模块:

val appDependencies: Seq[sbt.ModuleID] = Seq("com.wordnik" %% "swagger-play2" % "1.2.4" )

住在 Maven 中心

于 2013-07-17T23:35:54.937 回答
0
GET     /api-docs.json/items           controllers.ApiHelpController.getResource(path = "/api-docs.json/items")

should be

GET     /api-docs.json/items           controllers.ApiHelpController.getResource(path = "/items")
于 2015-08-25T07:51:54.277 回答