请在我的合同 yaml 文件中找到架构:
Foo:
allOf:
- $ref: "#/components/schemas/Bar"
properties:
ancestors:
items:
$ref: "#/components/schemas/Bar"
type: array
description:
type: object
additionalProperties:
type: string
id:
description: id
type: string
type: object
Bar:
properties:
accessAllowed:
items:
type: string
type: array
catalog:
type: boolean
children:
items:
$ref: "#/components/schemas/Bar"
type: array
Run Code Online (Sandbox Code Playgroud)
使用 swagger 2 时,生成的类 Foo 扩展了 Bar。但是使用 openAPI 3 后,在使用allOf. 它所做的就是将 Bar 的所有属性复制到 Foo 类。
尽管现在 Foo 类将包含 Bar 的所有属性,但当我们查看 java 代码方面时,Foo 实际上并没有继承。使用 OpenAPI 3 时,有没有办法生成扩展 Bar 的类 Foo,因为在很多情况下需要生成继承父类的类。