我在 OpenAPI 3.0 中有一个数据模型定义,使用 SwaggerHub 来显示 UI。我希望模型的属性之一是related
,它是同一模型的属性数组。
Foo:
properties:
title:
type: string
related:
type: array
items:
$ref: '#/components/schemas/Foo'
解析器似乎不喜欢这个 - 用户界面显示related
属性为空数组。 OpenAPI 3.0 中可以实现这种自引用吗?
您的定义是正确的,只是 Swagger UI 目前无法正确呈现循环引用定义。看问题#3325 https://github.com/swagger-api/swagger-ui/issues/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
或者,您可以添加一个example
只是为了related
array:
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)