如何在OpenAPI中定义具有多个属性(包括对象数组)的Object



我很难在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

感谢您的帮助。谢谢

使用currect 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

最新更新