首页 > 解决方案 > 如何在 Swagger 的 YAML 中创建相同类型的嵌套对象数组?

问题描述

我正在尝试在 swagger 中创建一个 YAML 模式,它具有如图所示的树状结构。数组中的数组中应该有数组。使用$ref来指代相同的结构,但我变得空白。它没有生成完整的结构。

Asset:
  type: array
  items:
    id:
      type: string
    serial:
      type: number
    ...
    ...
    Asset:
      type: array
      items:
        $ref: '#/components/schemas/Asset'

结果 -在此处输入图像描述

标签: yamlswagger

解决方案


试试这个:

   Asset:
     type: array
     items:
       type: object
       properties:
         id:
           type: string
           example:
             "typeExample"
         serial:
           type: number
           example:
              123

推荐阅读