【问题标题】:What could i put in response in @ApiOperation of Swagger我可以在 Swagger 的 @ApiOperation 中做出什么回应
【发布时间】:2015-07-21 21:56:57
【问题描述】:

在此代码中,当此方法返回 Response.noContent.build(); 时,我可以使用 Status.class @ApiOperation 吗?

    @DELETE
    @Path("/property/{id}")
    @ApiOperation(value = "Delete", notes = "Delete a persisted property from data source.", response = Status.class??)
    public Response delete(String id){
    ...
    ...
    return Response.noContent().build();
    }

【问题讨论】:

  • 是javax.ws.rs.core.Response.Status
  • 由于您没有返回尸体,我认为使用 Status 没有任何意义。现在那个端点只会返回一个204 No Content,这很好。
  • 确实如此。我没有返回正文,我返回 204 No Content。
  • 此方法返回 204 No Content 但我的问题是我可以用@ApiOperation 作为回报吗?

标签: java rest swagger swagger-2.0


【解决方案1】:

您可以省略response 部分,默认情况下它将使用Void.class。来自docs

public abstract Class<?> response

操作的响应类型。 在 JAX-RS 应用程序中,将自动使用方法的返回类型,除非它是 javax.ws.rs.core.Response。在这种情况下,操作返回类型将默认为 void,因为无法知道实际的响应类型。(强调我的)

设置此属性将覆盖任何自动派生的数据类型。

如果使用的值是表示原始类型(IntegerLong、...)的类,则将使用相应的原始类型。

默认

java.lang.Void.class

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-10-25
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    • 2010-12-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多