BeanParam的Swagger文档

时间:2014-09-18 15:34:40

标签: cxf jax-rs swagger

我正在尝试使用Swagger记录我的一个Java API(在Apache CXF中实现),它使用Bean Param接收它的参数。类似的东西:

@GET
@Produces({SemanticMediaType.JSON_LD, MediaType.APPLICATION_JSON_VALUE})
@ApiOperation(value = "Retrieves Themes", position = 0)
@ApiResponses(value = {@ApiResponse(code = 200,
        message = "Retrieval was successful"), @ApiResponse(code = 403,
        message = "Missing or invalid x-business-group-id header"), @ApiResponse(code = 500,
        message = "Internal server error")})
public Response get(@QueryParam(URI_PARAM_NAME) String uri,
                    final @ApiParam @Valid @BeanParam ThemeParams themeParams) { ... }

我读到Swagger已经实现了对BeanParams的支持,但是当我尝试运行它时,在swagger-ui中,我只看到一个名为“body”的参数和一个文本字段,与BeanParam的内容无关。 / p>

有人可以为此提供一些帮助吗?

2 个答案:

答案 0 :(得分:1)

这有点旧,但对于那些遇到同样问题的人来说,这是我发现的帮助。

  • 如果您使用的是DefaultJaxrsConfig,请将其更改为JerseyJaxrsConfig。
  • 如果您要链接到swagger-jersey-jaxrs _...,请将其更改为swagger-jersey2-jxsrs _...

答案 1 :(得分:0)

你可以参考。

@POST
    @Path("/users")
    @ApiOperation(value = "vdc", position = 1, notes = "vdc")
    @ApiResponses(value = {
            @ApiResponse(code = 200, message = "OK",response=UserCreateResponse.class),
            @ApiResponse(code = 30601, message = "'httpcode': 400 'Errormsg': Request Params Not Valid"),
            @ApiResponse(code = 30602, message = "'httpcode':404 'Errormsg': Data Required Not Found"),
            @ApiResponse(code = 30603, message = "'httpcode':405 'Errormsg': Method Not Allowed"),
            @ApiResponse(code = 30604, message = "'httpcode':408 'Errormsg': Request Time Expires Timeout"),
            @ApiResponse(code = 30605, message = "'httpcode':500 'Errormsg': Internal Server Error") })
    public Response createUsersWithArrayInput(
            @ApiParam(value = "ID", name = "platform_id", required = true) @QueryParam(value = "platform_id") String platformId,
            @ApiParam(value="body",name="user",required=true)UserCreate userCreate) {}

UserCreate.java

@ApiModel("UserCreate")
public class UserCreate {
        @ApiModelProperty(value="VDC Id",required=false)
        @JsonStringSchema(optional=true,description="VDC Id")
        private String vdcId;
        @ApiModelProperty(value="description",required=true)

        private String name;
        @ApiModelProperty(value="description",required=false)

        private String password;
        }