Java 如何在swagger模型中创建嵌套对象
我有一个像Java 如何在swagger模型中创建嵌套对象,java,swagger,swagger-ui,swagger-editor,Java,Swagger,Swagger Ui,Swagger Editor,我有一个像 public GenericBO { private int id; private String code; private int parentId; private List<GenericBO> child = new ArrayList<GenericBO>(); //getters and setters respectively } public GenericBO{ 私有int-id; 私有字符串码; 私
public GenericBO {
private int id;
private String code;
private int parentId;
private List<GenericBO> child = new ArrayList<GenericBO>();
//getters and setters respectively
}
public GenericBO{
私有int-id;
私有字符串码;
私有int-parentId;
private List child=new ArrayList();
//分别是getter和setter
}
如何在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(value=“ID”)
私有int-id;
@ApiModelProperty(value=“Code”)
私有字符串码;
@ApiModelProperty(value=“父Id”)
私有int-parentId;
@ApiModelProperty(value=“Children”)
private List children=new ArrayList();
...
}
如果列表对象是其他模型的集合,则必须对相应的模型进行注释(使用
@ApiModelProperty
注释)。您是手动编写OpenAPI定义还是从代码生成它?我是手动编写的,如何从代码生成?签出或。下面Vladlas Maier的回答显示了如何注释代码。