yaml - Return an array of object in Swaggerhub -


i defining api specification in swaggerhub. /contacts request returns array of contacts. definition below:

/contacts:      get:   tags:   - contacts   summary: contacts   description: displays contacts present user.   operationid: getcontact   produces:   - application/json   - application/xml     responses:    200:     description: successful operation     schema:       $ref: '#/definitions/allcontacts'    400:     description: invalid id supplied    404:     description: contact not found    500:     description: server error definitions:   allcontacts:    type: array    items:    -  $ref: '#/definitions/contactmodel1'    -  $ref: '#/definitions/contactmodel2'     contactmodel1:     type: object     properties:       id:         type: integer         example: 1       firstname:         type: string         example: 'somevalue'       lastname:         type: string         example: 'somevalue'     contactmodel2:     type: object     properties:       id:         type: integer         example: 2       firstname:         type: string         example: 'somevalue1'       lastname:         type: string         example: 'somevalue1' 

for reason, returns second object not whole array of objects. using openapi spec 2.0 , suspect arrays not supported in version

an array of objects defined follows. value of items must single model describes array items.

definitions:   allcontacts:     type: array     items:       $ref: '#/definitions/contactmodel'    contactmodel:     type: object     properties:       id:         type: integer         example: 1       firstname:         type: string         example: sherlock       lastname:         type: string         example: holmes 

by default, swagger ui displays array examples 1 item, so:

[   {      "id": 1,      "firstname": "sherlock",      "lastname": "holmes"   } ] 

if want array example include multiple items, specify multi-item example in array model:

definitions:   allcontacts:     type: array     items:       $ref: '#/definitions/contactmodel1'     example:       - id: 1         firstname: sherlock         lastname: holmes       - id: 2         firstname: john         lastname: watson 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -