如何使用 oneOf
将此代码段调整为等效的 OpenAPI 2.0 版本?
formats:
type: array
description: Possible parameter format.
items:
oneOf:
- type: string
- type: object
description: Matched alias formats
properties:
representation:
type: array
description: Alias format representations
items:
type: string
match_multiple:
type: boolean
optional: true
display:
type: string
description: Display string of alias format
最佳答案
在 OpenAPI 2.0 中,您最多能做的就是使用 typeless schema {}
表示 items
,这意味着项目可以是除 null
之外的任何内容 - 数字、对象、字符串等。您无法指定确切的类型对于items
,但您可以添加具有不同项目类型的数组的示例
。
formats:
type: array
items: {} # <--- means "any type" (except null)
example:
# example of a string item
- test
# example of an object item
- representation: [one, two]
match_multiple: false
display: something
注意:无类型架构 {}
只能在 OAS2 主体参数和响应架构中使用。路径、 header 和表单参数需要数组项的原始类型
。
关于swagger - 在 OpenAPI 2 中等效使用 oneOf(来自 OpenAPI 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70112647/