swagger yaml中的空白数组引用?

时间:2016-08-26 12:02:43

标签: yaml swagger swagger-ui

Iam为我的API使用了swagger文档。现在真的遇到了yaml代码。 我真的想从以下json代码

获取响应部分的yaml代码
{    
    "status":0,
    "gtasks":[],
    "purchased":[],
    "scnt":0    
} 

非常感谢任何帮助..

1 个答案:

答案 0 :(得分:2)

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

以下是YourObjectName的架构定义,代表:

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

请参阅注释以使用数据类型或其他模式对象填充数组类型。

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

最后,如果您需要帮助,请参阅" PetStore"来自http://editor.swagger.io/

的示例API规范 祝你好运。