【发布时间】:2021-09-13 05:14:27
【问题描述】:
在我的项目中,我使用 Open API 3.0 来生成 mmodel 类。
我的要求是我必须将父类属性重用到子类。
例如:
public class Student {
private String id;
private String name;
}
public class Address {
private String id;
private String name;
private String city;
private String state;
}
但问题是 allOf 生成如下所示的 bean 类而不是上面的类。
public class Address {
public Student student;
private String city;
private String state;
}
下面是我的 schema.yaml
Student:
properties :
id:
type: integer
format: int64
description: The ID of the new account
name:
type: string
description: The human-readable description of this account
Address:
properties :
allOf:
$ref : '#/Student'
city:
type: string
description: City
state:
type: string
description: State
如何确保属性是复制而不是创建对象。
任何帮助将不胜感激!!!
【问题讨论】:
-
看来
allOf并没有按照您的预期去做。根据Swagger DocumentationallOf用于组合(这意味着在您的示例中Address由对Student的引用和一些附加字段组成) -
谢谢托马斯!!!我理解 allOf 的目的。还有其他方法可以实现我的需要吗?
标签: java swagger swagger-ui openapi