簡體   English   中英

帶有對象的對象的架構

[英]Schema for an object with swagger

我正在為兩個get路由編寫一個模式,結果是一個像

{
  "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'
*/

但是,它不再起作用了。

有人可以向我解釋我做錯了什么嗎?

注釋中有語法錯誤。

info屬性的縮進應如下所示:

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

$ref s中,在#之后必須有一個/ -用#/definitions替換#definitions

$ref : '#/definitions/getVCenter'

另外,如果響應應為“ vCenter的陣列”而不是單個vCenter,則響應架構應為:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM