您的定义是正确的,它只是轻率的用户界面当前没有正确地呈现循环引用的定义。参见
issue #3325
有关详细信息。
你能做的就是添加一个模型
example
,并且Swagger UI将显示此示例,而不是尝试从定义中生成示例。
Foo:
type: object
properties:
title:
type: string
related:
type: array
items:
$ref: '#/components/schemas/Foo'
example: # <-------
title: foo
related:
- title: bar
- title: baz
related:
- title: qux
或者,可以添加
例子
只是为了
related
数组:
Foo:
type: object
properties:
title:
type: string
related:
type: array
items:
$ref: '#/components/schemas/Foo'
example: # <--- Make sure "example" is on the same level as "type: array"
- title: bar
- title: baz
related:
- title: qux