【问题标题】:Schema for an object with swagger大摇大摆的对象的架构
【发布时间】:2018-08-17 19:23:36
【问题描述】:

我正在为两个获取路径编写一个模式,其中结果是一个类似的对象

{
  "id":"49077acb6ac8",
  "info":
    {
      "name":"test"
    }
}

其实我得到了这个:

/*
* @swagger
*  definitions:
*    getVCenter:
*      id:
*        type: string
*        format: uuid
*      info:
*        type: object
*      properties:
*        name:
*          type: string
*        fullName:
*          type: string
*        vendor:
*          type: string
* /v1/vcenters/:
*   get:
*     tags:
*       - vcenters
*     summary: Get availables vCenters.
*     description: Get a list of availables vCenters.
*     produces:
*       - application/json
*     responses:
*       200:
*         description: an array of vCenters
*         schema:
*           $ref : '#definitions/getVCenter'
*/

但它不再起作用了。

谁能解释一下我做错了什么?

【问题讨论】:

  • 定义“不起作用”。
  • 我的意思是它不显示文档

标签: node.js object schema yaml swagger


【解决方案1】:

您的注释中有语法错误。

info 属性的缩进应该如下:

*      info:
*        type: object
*        properties:  # <-- "properties" must be on the same level as "type: object"
*          name:
*            type: string
*          fullName:
*            type: string
*          vendor:
*            type: string

$refs 中,# 之后必须有一个/ - 将#definitions 替换为#/definitions

$ref : '#/definitions/getVCenter'

另外,如果响应应该是“一个 vCenter 数组”而不是单个 vCenter,那么响应架构应该是:

*     responses:
*       200:
*         description: an array of vCenters
*         schema:
*           type: array
*           items:
*             $ref : '#/definitions/getVCenter'

【讨论】:

  • 信息前的id在哪里?
  • id 定义很好,但您可能需要删除 format: uuid,因为它是用于 UUIDs 的,而 "49077acb6ac8" 不是 UUID。
  • 这是用于stackoverflow的例子,但在我的情况下它是一个uuid
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-19
  • 2015-12-14
  • 1970-01-01
  • 2018-11-29
  • 2018-12-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多