Swagger注解遍历DB中所有表

Swagger annotation traversing all tables in DB

我正在看一个 Java 应用程序,它提供 REST API 来访问数据库。除了 JAX-RS 之外,它还使用 Swagger 生成文档和测试网站。在其中一条路线上,我意识到 Swagger 给出的结果示例非常长(超过 140000)行:

此路由使用以下代码定义:

@GET
@Path("/getUsers")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Operation(
        summary = "Get available users",
        responses = {
                @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = OauthClientDetailsEntity.class)), description = "Get users list"),
                @ApiResponse(responseCode = "401", content = @Content(schema = @Schema(implementation = ErrorResponse.class)), description = "Error: Unauthorized"),
                @ApiResponse(responseCode = "500", description = "Error: Internal Server Error")
        }
)
public Response getUsers() {
  // ....
}

"trouble-maker"就是idCliente字段,在实体class中是这样定义的:

@JoinColumn(name = "idCliente", referencedColumnName = "id")
@ManyToOne
private Cliente idCliente;

table Cliente(英文customer)与数据库中的很多table有关,所以我认为问题在于Swagger正在遍历所有这些tables,所以示例结果很长。 class 有 40 多个字段,看起来像这样:

@Entity
@Table(name = "cliente")
@XmlRootElement
public class Cliente implements Serializable {
    @OneToMany(mappedBy = "idCliente")
    private List<FacturaCliente> facturaClienteList;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idCliente")
    private List<OauthClientDetailsEntity> oauthClientDetailsEntityList;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "cliente")
    private List<OauthAccessTokenEntity> oauthAccessTokenEntityList;

    @Column(name = "codigoPlantillaFacturacion")
    private String codigoPlantillaFacturacion;
    // etc...
}

我是 Swagger 的新手,所以我不确定如何处理这个问题。有没有办法让Swagger不遍历所有相关的table?或者,还有什么其他方法会更有效?

提前致谢,

您可以使用 @ApiModelProperty(hidden=true) 忽略此字段 但是您必须知道,无论如何都会呈现所有内容。如果您不需要此字段,更好的方法是不呈现它(例如 @JsonIgnore 注释)。最好的选择是 return DTO 只包含必要的字段,而不是整个实体及其层次结构。