【问题标题】:Blank array reference in swagger yaml?swagger yaml中的空白数组引用?
【发布时间】:2016-08-26 12:02:43
【问题描述】:

我正在为我的 API 使用 swagger 文档。现在真的被 yaml 代码打动了。 我真的想要来自以下 json 代码的响应部分的 yaml 代码

{    
    "status":0,
    "gtasks":[],
    "purchased":[],
    "scnt":0    
} 

任何帮助将不胜感激..

【问题讨论】:

    标签: yaml swagger swagger-ui


    【解决方案1】:

    空白数组只是这些键没有项目时的状态。但是,如果有任何项目,则数组将被这些项目填充。在这种情况下,您仍然需要定义这些数组中的内容。

    这是YourObjectName 的架构定义,它表示:

    {    
        "status":0,
        "gtasks":[],
        "purchased":[],
        "scnt":0    
    } 
    

    查看 cmets 以使用数据类型或其他模式对象填充数组类型。

    definitions:
    
      YourObjectName:
        type: object
        required:
          - status
        properties:
          status:
            type: integer
            format: int32 # you need
          gtasks:
            type: array
            items: # Need to define item type, could be any data type of object
              type: string
          purchased:
            type: array
            items:
              type: string # For reference to different schema object use $ref: "#/definitions/PurchasedItems"
          scnt:
            type: integer
            format: int32
    

    最后,如果您需要帮助,请参阅http://editor.swagger.io/ 中的“PetStore”示例 API 规范

    祝你好运。

    【讨论】:

      猜你喜欢
      • 2019-10-02
      • 2023-01-04
      • 2019-11-21
      • 2021-10-21
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 2019-06-27
      • 1970-01-01
      相关资源
      最近更新 更多