【问题标题】:How to declare array in array in swagger yaml [duplicate]如何在swagger yaml中声明数组中的数组[重复]
【发布时间】:2021-10-21 02:21:54
【问题描述】:

我想大摇大摆地在数组中声明数组,但不知道该怎么做: 例如我有案例,参数如下:

       "cells": [
           [
               {
                   "field": "testID",
                   "name": "testId",
                   "width": "74px",
                   "sortable": true
               },
               {
                   "field": "test number",
                   "name": "test number name",
                   "width": "100px",
                   "sortable": true
               },
               {
                   "field": "testName",
                   "name": "testNamename",
                   "width": "200px",
                   "sortable": true
               },
           ]
       ]
   },

您可以看到,JSON 参数在数组中,即在数组中。我想把它转换成招摇的 yaml 语法。 我试过写类似的东西:

definitions:
  columns:
    type: object
  cells:
    type: array
    items: {
      type: array
      items: {
      properties: 
        field: 
          type: string
        name:
          type: string
        width:
          type: string
        sortable:
          type: boolean
      }
    }

但在第二个项目上,我收到了“流集合条目之间缺少逗号”的错误消息。有什么想法吗?

【问题讨论】:

    标签: arrays yaml swagger


    【解决方案1】:

    根据swagger docs for array data types 应该是这样的:

    definitions:
      cells:
        type: array
        items:
          type: array
          items: 
            type: object
            properties: 
              field: 
                type: string
              name:
                type: string
              width:
                type: string
              sortable:
                type: boolean
          
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-02
      • 2011-10-05
      • 2023-03-30
      • 2021-11-05
      • 2015-07-31
      • 1970-01-01
      • 2011-05-02
      相关资源
      最近更新 更多