【问题标题】:Swagger documentation for BeanParamBeanParam 的 Swagger 文档
【发布时间】:2014-09-18 15:34:40
【问题描述】:

我正在尝试使用 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 的内容无关。

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

【问题讨论】:

    标签: cxf jax-rs swagger


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      你可以参考一下。

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-02-25
        • 2014-02-22
        • 1970-01-01
        • 2018-07-16
        • 1970-01-01
        • 1970-01-01
        • 2017-01-19
        • 1970-01-01
        相关资源
        最近更新 更多