在Swagger文档中定义对象数组

时间:2018-12-12 13:50:33

标签: ruby-on-rails swagger swagger-2.0 code-documentation

我已经使用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,但不起作用。

0 个答案:

没有答案