我正在努力在OpenApi中定义请求正文。我想强制用户向我发送以下形式的数据:
{
"test": {
"a": "a",
"b": "b",
"abc": [
{
"type": "abc",
"name": "name"
},
{
"type": "abc",
"name": "name"
}
...more
]
}
}
这是我尝试过的方法,但似乎不起作用:
schemas:
SampleRequest:
required:
- abc
properties:
abc:
$ref: "#/components/schemas/ABCType"
ABCType:
type: object
required:
- test
properties:
test:
type: array
items:
type: object
properties:
type:
type: string
name:
type: string
任何帮助表示赞赏。谢谢
答案 0 :(得分:2)
使用当前的json,我无法理解,但创建了它。这创建了一个复制您的json。
ABCType:
type: object
additionalProperties: false
required:
- a
- b
- abc
properties:
a:
description: A of ABCType
type: string
b:
description: B of ABCType
type: string
abc:
description: Array of ABCType
type: array
items:
$ref: '#/components/schemas/ABCArrayValue'
ABCArrayValue:
type: object
additionalProperties: false
required:
- type
- name
properties:
type:
description: Type of this array value
type: string
name:
description: Name of this array value
type: string