【问题标题】:How to reference another schema from an array schema in OpenAPI 3.0?如何从 OpenAPI 3.0 中的数组模式中引用另一个模式?
【发布时间】:2020-03-11 07:19:37
【问题描述】:

我有一个 OpenAPI 3.0 架构,其中一个属性(taskRequireSkills 数组)需要引用另一个架构(TaskRequireUserSkill),如下所示:

components:
  schemas:

    Task:
      properties:
        id:
          type: integer
        name:
          type: string

        taskRequireSkills:
          type: array
            schema:  # ERROR : bad indentation of a mapping entry
              $ref: '#/components/schemas/TaskRequireUserSkill'

        created_at:
          type: string
          format: datetime

    TaskRequireUserSkill:
      properties:
        id:
          type: integer
        skill_id:
          type: integer
        skill_name:
          type: string
        ordering:
          type: integer
        created_at:
          type: string
          format: datetime

但我收到“映射条目的缩进错误”错误。 我想我的语法无效。 但哪种语法有效?

【问题讨论】:

    标签: openapi


    【解决方案1】:

    $refs 数组定义如下:

            taskRequireSkills:
              type: array
              items:
                $ref: '#/components/schemas/TaskRequireUserSkill'
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-20
      • 2017-06-09
      • 2015-05-18
      • 2015-05-15
      • 1970-01-01
      相关资源
      最近更新 更多