[英]How to define Object with multiple properties including an array of objects in OpenAPI?
我正在努力在 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
任何帮助表示赞赏。 谢谢
使用正确的 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.