ruby-on-rails - 在 Swagger 文档中定义对象数组
问题描述
我现在使用 swagger 已经很长时间了,我们已经开始使用它来记录我们的代码,在一个地方有一个 API 响应,它在包含的块中返回多个对象。
例子:
{
"data": {
"id": "1",
"type": "schoolPositions",
"attributes": {
"description": "teases the students",
"mustHaves": "principle"
},
"relationships": {
"schoolLocation": {
"data": {
"id": "72",
"type": "schoolLocations"
}
},
"schoolCompensation": {
"data": {
"id": "75",
"type": "schoolCompensations"
}
},
"jobSpecs": {
"data": [
{
"id": "82",
"type": "schoolAttachments"
}
]
}
}
},
"included": [
{
"id": "72",
"type": "schoolLocations",
"attributes": {
"city": "Berhampore",
"state": "West Bengal",
"postalCode": "742101",
"country": "India",
"globalRegionId": 30,
"regionId": 683
}
},
{
"id": "75",
"type": "schoolCompensations",
"attributes": {
"salary": "",
"bonus": "",
"equity": "",
"currencyId": null,
"equityType": "percent",
"salaryDescription": null
}
},
{
"id": "82",
"type": "schoolAttachments",
"attributes": {
"attachmentType": "JobSpecificationAttachmentType",
"fileFileName": "vs.jpg",
"fileContentType": "image/jpeg",
"fileFileSize": 2410039,
"fileUpdatedAt": "2018-12-12T07:06:38Z",
"downloadUrl": "001-vs.jpg?1544598398",
"klass": "SchoolAttachments"
}
}
]
我在互联网和文档上浪费了一整天的时间试图记录包含的部分,但我在某个地方出错了
response 200 do
key :description, 'School Data'
schema do
property :data do
key :type, :array
items do
key :'$ref', :School
end
end
property :included do
key :type, :array
items do
key :'$ref', :SchoolLocations
key :'$ref', :SchoolCompensations
key :'$ref', :SchoolAttachments
end
end
end
end
这仅显示SchoolAttachments
包含的部分。
我尝试过使用allOff
,但它不起作用。
解决方案
推荐阅读
- r - 导入数据时出现数字错误
- java - Android Studio:房间中的插入功能未正确存储实体
- php - Live Server 无法加载其他页面并出现 Apache 404 错误
- reactjs - 反应:尝试用 src/ 镜像 __tests__/
- javascript - 评论按钮在 jquery 函数中不起作用
- javascript - 对网站的 Http 请求以获取特定 html 元素的内容
- python - 检查对象是否在python c扩展中是可迭代的
- c - 链接器抱怨可能未初始化的变量(完全优化的构建选项)
- google-apps-script - 如何从另一个 Google App Script 执行 Google App Script API 函数?
- amazon-sns - 如何设置电子邮件通知以识别最后提交用户并发送代码管道状态