2014-10-30 338 views
1

我已经构建了一个RestEasy API并将它与Swagger UI关联。我被要求完成的任务是找到一种方法来减少方法签名中的查询参数,并在某种“DTO”中处理它们。使用Swagger-UI注解@FormParam字段@ApiParam

原来实行将类似于:

@GET 
    @ApiOperation(value = "echo test value", notes = "echo test notes") 
    @ApiResponse(code = HttpServletResponse.SC_OK, message = "Response.status.OK") 
    public Response echoTest(
    @ApiParam("id") @QueryParameter("id") final int id, 
    @ApiParam("fName") @QueryParameter("fName") final String fName, 
    @ApiParam("sName") @QueryParameter("sName") final String sName) { 

    // handle request 

    } 

我已经提取的查询参数处理到DTO,虽然现在我不知道该如何处理的事情扬鞭-UI端。据我猜测,我试图在DTO中注释字段,但这没有奏效。我当前的解决方案没有正确招摇的UI交互:

@GET 
    @ApiOperation(value = "echo test value", notes = "echo test notes") 
    @ApiResponse(code = HttpServletResponse.SC_OK, message = "Response.status.OK") 
    public Response echoTest(@ApiParam("form") @FormParam QueryDTO dto) { 

    //Handle request 

    } 

QueryDTO.java:

public class QueryDTO { 

    @ApiParam(name = "id", value = "user id") @QueryParam("id") private int id; 
    @ApiParam(name = "fName", value = "user first name") @QueryParam("fName") private String fName; 
    @ApiParam(name = "sName", value = "user surname") @QueryParam("sName) private String sName; 

    // Getters,setters etc 

} 

不SwaggerUI支持这种类型的功能?我可以采取哪种方法来适合我的用例?任何建议或帮助表示赞赏,谢谢。

回答

2

这里的问题不是Swagger-UI,而是Swagger-Core。

Swagger-Core不支持RESTEasy的@Form注释,并且仅支持标准JAX-RS注释。

直到您提到它之前,我并不熟悉该注释,但它看起来像在JAX-RS 2.0中引入的@BeanParam一样。 RESTEasy 3.0及更高版本应该支持它。 Swagger核心能够处理@ BeanParam's以产生适当的文档。

如果你仍然只需要支持@Form,你必须在Swagger-Core的仓库上打开一个问题。

+0

我在文档中注意到了这一点,现在尝试使用@BeanParam的解决方案 - 感谢。 – 2014-10-30 12:14:28