【问题标题】:describe in swagger where object first field is a distinct string not named [duplicate]大摇大摆地描述对象第一个字段是一个未命名的不同字符串[重复]
【发布时间】:2018-01-10 12:52:26
【问题描述】:

如果我有一个对象数组,这些对象是各种应用程序,例如像这样

Application Name 1
    _Id: 1
    category: design
    version: xx.xy
Application Name 2
    _Id: 2
    category: spreadsheet
    version: xx.xx

如何描述第一个字段?

所以

我将有一个 $ref 数组:“#/definitions/Application”,其他字段很简单

Application:
    type: object
    properties:
        _Id:
            type: integer
        category: 
            type: string

但是我该如何处理这些名字呢?即应用程序名称1、2等?

【问题讨论】:

标签: node.js express swagger


【解决方案1】:

试试这样:-

    "items":{
        type: array
        items:{
          properties:{
              "Name":{
                  type:object,
                  properties:{
                    _Id:{
                        type: integer
                    },
                    category: {
                        type: string
                    },
                    version:{
                      type: string  
                    }
                  }

              }
        }
    }
}

【讨论】:

  • 那不是漏掉了应用的名字吗?即数组的每个元素都有“应用程序1的名称”:{_id:1,类别:“财务”}“名称2”:{_id:2,类别:“dcvnv”}等
  • 你必须有一个包含所有对象数组的对象吧?
  • "items": [ {"Name 1": { "_id": 191, "version": "2", "category": "B" }}, {"Name 2": {“_id”:192,“版本”:“2”,“类别”:“C”}}]
  • 现在检查我更新了我的答案
猜你喜欢
  • 2015-08-08
  • 2019-05-05
  • 1970-01-01
  • 2013-02-21
  • 1970-01-01
  • 2012-11-24
  • 1970-01-01
  • 2013-06-11
  • 2012-07-12
相关资源
最近更新 更多