如何在 swagger 模型中创建嵌套对象

How can I create a nested object in swagger model

我有一个对象

public GenericBO {

   private int id;

   private String code;

   private int parentId;

   private List<GenericBO> child = new ArrayList<GenericBO>();

  //getters and setters respectively
}

如何在 swagger 中创建相同的模型?

注解嵌套和不嵌套的 Swagger 模型没有区别。

您必须为模型的每个属性添加 io.swagger.annotations.ApiModelProperty 注释。

public GenericModel {

   @ApiModelProperty(value = "ID")
   private int id;

   @ApiModelProperty(value = "Code")
   private String code;

   @ApiModelProperty(value = "Parent Id")
   private int parentId;

   @ApiModelProperty(value = "Children")
   private List<GenericModel> children = new ArrayList<>();

   ...
}

如果列表对象是其他模型的集合,您还必须注释相应的模型(使用 @ApiModelProperty 注释)。