Swagger 3嵌套数组定义结构

时间:2018-02-07 16:04:29

标签: swagger

我希望创建一个如下所示的响应:

permissions:
{
    "customers":['add_update','delete'],
    "employees":['add_update','delete']
    "suppliers":['add_update','delete','search]
}

OR(客户,员工......动态)

permissions:
{
    "customers":['add_update','delete']
}

这可以在swagger中使用ref吗?

我已经尝试了这个,但无法弄清楚如何让#34;客户",#34;员工",#34;供应商"作为钥匙。

EmployeePermissions:
  type: object
  properties:
    module:
     type: string
     example: 'customers'

1 个答案:

答案 0 :(得分:0)

每个属性(propertiesemployeessuppliers)都需要在properties下拥有自己的条目。

EmployeePermissions:
  type: object
  properties:
    customers:     # <----- property name
      type: array  # <----- property type
      items:
        type: string
    employees:     # <----- property name
      type: array
      items:
        type: string
    suppliers:     # <----- property name
      type: array
      items:
        type: string

有关在OpenAPI中定义对象的更多信息:https://swagger.io/docs/specification/data-models/data-types/#object