Glu*_*ear 7 swagger-ui openapi
我在 OpenAPI 3.0 中有一个数据模型定义,使用 SwaggerHub 来显示 UI。我希望模型的一个属性为related,它是同一模型的一组属性。
Foo:
properties:
title:
type: string
related:
type: array
items:
$ref: '#/components/schemas/Foo'
Run Code Online (Sandbox Code Playgroud)
解析器似乎不喜欢这样 - UI 将该related属性显示为空数组。这种自引用在 OpenAPI 3.0 中是否可行?
您的定义是正确的,只是 Swagger UI 当前无法正确呈现循环引用定义。有关详细信息,请参阅问题 #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
Run Code Online (Sandbox Code Playgroud)
或者,您可以example为related数组添加一个just :
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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3319 次 |
| 最近记录: |