我正在为JaxRs注释的服务添加Swagger注释。
我的代码如下:
(^{
GET true
Path "/{who}"
ApiOperation {:value "Get a hello" :notes "simple clojure GET"}
Produces ["text/plain; charset=UTF-8"]
ApiResponses {:value [(ApiResponse {:code 200 :message "yay!"})]}
}
如果我反编译生成的类,注释看起来像这样:
@ApiResponses({@com.wordnik.swagger.annotations.ApiResponse(code=200L, message="yay!")})
@Produces({"text/plain; charset=UTF-8"})
@ApiOperation(value="Get a hello", notes="simple clojure GET")
@Path("/{who}")
@GET(true)
注意第一个注释中的代码=200L
在运行时,这个值必须是int类型,但我不知道如何实现
如果我尝试
ApiResponses {:value [(ApiResponse {:code (int 200) :message "yay!"})]}
我遇到一个编译错误(使用Maven Swagger插件)。
Exception in thread "main" java.lang.ClassCastException: clojure.lang.Var cannot be cast to java.lang.Class, compiling:(pocclj/resourceclj.clj:14)
我已经尝试过
(def success (int 200))
...
ApiResponses {:value [(ApiResponse {:code success :message "yay!"})]}
这会导致编译错误:
Exception in thread "main" java.lang.IllegalArgumentException: Unsupported annotation value: success of class class java.lang.Integer, compiling:(pocclj/resourceclj.clj:14)
我尝试了一些其他的方法(如deref等),但找不到解决方案。我对Clojure比较新手,希望能得到一些帮助。提前感谢您。Martin