我正在尝试创建一个包含键-值数组的架构,但是属性本身是单独定义的。例如,假设我要描述一个具有以下属性的文件:
其中,fileType是一个具有ID的对象,并带有一组特定的可接受键/值组合,例如
我对如何用OpenApi 3描述这一点感到有些困惑,因为从文档中我似乎找不到找到描述具有特定键值组合的数组的方法。
现在我正在使用下面的枚举
components:
schemas:
fileType:
type: string
description: file type
enum:
- Word
- Excel
- PDF
但这是不够的。 谢谢
答案 0 :(得分:1)
您可以使用类似这样的内容:
您的
fileType
模式
components:
schemas:
fileType:
type: object
description: file type
properties:
1:
type: string
example: "Word"
2:
type: string
example: "Excel"
3:
type: string
example: "PDF"
这是您的
requestBudy
requestBody:
description: File
content:
'*/*':
schema:
properties:
id:
type: string
fileName:
type: string
fileType:
$ref: '#/components/schemas/fileType'
看起来像
希望获得帮助。