Swagger documentation for BeanParam

I'm trying to document one of my java APIs (implemented in Apache CXF) using Swagger, that receives it's parameters using a Bean Param. Something like:

@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) { ... }

I read that Swagger already implements support for BeanParams, but when I try to run it, in swagger-ui, I only see one parameter called "body" and a text field, nothing related to the contents of my BeanParam.

Can somebody provide some assistance with this?

Upvotes: 2

Views: 2004

Answers (2)

jack
jack

Reputation: 113

You can refer to.

@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;
        }

Upvotes: 0

Ken Joyner
Ken Joyner

Reputation: 921

This is a bit old, but for those who are having the same issues, here is what I found helped.

  • If you are using the DefaultJaxrsConfig, change it to JerseyJaxrsConfig.
  • If you are linking to swagger-jersey-jaxrs_..., change it to swagger-jersey2-jxsrs_...

Upvotes: 1

Related Questions