简体   繁体   中英

Schema for an object with swagger

I am writing a schema for two get routes where the result is an object like

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

Actually I got this :

/*
* @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'
*/

But it doesn't work anymore.

Can someone explain to me what I did wrong please?

There are syntax errors in your annotation.

The indentation of info properties should be as follows:

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

In $ref s, there must be a / after # - replace #definitions with #/definitions :

$ref : '#/definitions/getVCenter'

Also, if the response is supposed to be "an array of vCenters" and not a single vCenter, then the response schema should be:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM