【问题标题】:How to create a nested array of objects of same type in YAML in Swagger?如何在 Swagger 的 YAML 中创建相同类型的嵌套对象数组?
【发布时间】:2021-12-17 19:24:48
【问题描述】:

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

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

结果 -

【问题讨论】:

  • 你能添加一个你试图描述的 JSON 结构的例子吗?
  • 更新 - 所以,它按预期工作。虽然我看不到结构,但类是以树格式生成的。

标签: yaml swagger


【解决方案1】:

试试这个:

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

【讨论】:

  • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 2019-10-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-02
  • 1970-01-01
  • 2014-01-10
相关资源
最近更新 更多