Swagger与Play Framework 2不兼容

时间:2014-02-10 15:34:53

标签: scala swagger playframework-2.2

我使用Play Framework 2.2.1(Java)处理RESTful API。我使用IDEA,我想将Swagger添加到我的项目中。

所以,首先我创建了`project / Build.scala'文件,因为默认项目没有它。其内容如下:

import sbt._
import Keys._

object ApplicationBuild extends Build {

  val appName = "speeder"
  val appVersion = "0.1-beta"

  val appDependencies: Seq[sbt.ModuleID] = Seq(
    "com.wordnik" %% "swagger-play2" % "1.3-SNAPSHOT",
    "com.wordnik" %% "swagger-play2-utils" % "1.3-SNAPSHOT"
  )

  val main = play.Project(appName, appVersion, appDependencies).settings(
    resolvers := Seq(
      "Local Maven Repository" at "file://"+Path.userHome.absolutePath+"/.m2/repository",
      "sonatype-snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
      "sonatype-releases" at "https://oss.sonatype.org/content/repositories/releases",
      "java-net" at "http://download.java.net/maven/2",
      "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"))
}

IDEA已经认可并建议进口项目,我做了什么。我这样注释我的控制器:

@Api(value = "/accounts", description = "Operation with accounts")
public class Accounts extends BaseController {

    @ApiOperation(value = "Create user", notes = "This can only be done by the logged in user.", httpMethod = "POST")
    @ApiImplicitParams(@ApiImplicitParam(name = "body", value = "Created user object", required = true, dataType = "User", paramType = "body"))
    public static Result signup() { //... }
}

我还添加了API文档的路径:

GET         /api-docs.json        controllers.ApiHelpController.getResources

然后我从控制台运行play dependencies并重新启动服务器。所以现在我打开http://localhost:9000/api-docs.json,我看到了:

{"apiVersion":"0.2","swaggerVersion":"1.2","apis":[{"path":"/accounts","description":"Operation with accounts"}]}

正如您所注意到的,没有关于注释方法的信息,它只是关于类。我的IDEA没有看到com.wordnik.swagger.annotations包或controllers.ApiHelpController.getResources控制器。该应用程序仍然可编译。

那我做错了什么?

4 个答案:

答案 0 :(得分:1)

或者您可以使用此库https://github.com/iheartradio/play-swagger

这个库采用的方法与注释不同(强迫您学习新的API),您可以直接在路径文件中将swagger规范写为注释。它会根据路径文件

自动生成参数定义

答案 1 :(得分:0)

如果你获得了JSON,那么你的设置是非常严格的,最后你需要像其他api方法一样添加更多信息。

然后转到此页

http://swagger.wordnik.com/

并复制你的.server:9000 / api-docs.json,在开头的绿色区域然后去,你有很好的文档api,那么你可以在你自己的游戏应用程序中创建该页面

答案 2 :(得分:0)

您可能需要1.3.9-SNAPSHOT。您可能还需要指定

api.version="1.0"
swagger.api.basepath="http://localhost:9000"
你的application.conf中的

答案 3 :(得分:0)

http://localhost:9000/api-docs.json上 输出路径/帐户

您可以在此处找到方法信息 http://localhost:9000/api-docs.json/accounts

相关问题