0

Here is the snippet of code:

  /getappsettings:
    get:
      summary: Gets the collection of app settings.
      responses:
        200:
          description: The successful get app settings response.
          schema:
            type: array
            items:
              $ref: '#/definitions/KeyValueType'
            example:
              - key: 'APP_SUPPORT_EMAIL_ADDRESS'
                value: 'test@example.com'
              - key: 'APP_SUPPORT_PHONE_NUMBER'
                value: '08 9123 4567'

In the mocked API from SwaggerHub, it returns an empty array.

Helen
  • 87,344
  • 17
  • 243
  • 314
dodgy_coder
  • 12,407
  • 10
  • 54
  • 67

2 Answers2

0

The problem I found was that it should be 'examples:' and up one level instead of 'example:' and also needed specify the content type - here is the working example below ...

Here is the snippet of code

  /getappsettings:
    get:
      summary: Gets the collection of app settings.
      responses:
        200:
          description: The successful get app settings response.
          schema:
            type: array
            items:
              $ref: '#/definitions/KeyValueType'
          examples:
            application/json:
              - key: 'APP_SUPPORT_EMAIL_ADDRESS'
                value: 'test@example.com'
              - key: 'APP_SUPPORT_PHONE_NUMBER'
                value: '08 9123 4567'
dodgy_coder
  • 12,407
  • 10
  • 54
  • 67
  • The spec in your question is also perfectly valid. This ^^ is just another way to write the same thing. – Helen Jan 26 '18 at 15:50
0

It was a bug in SwaggerHub's mock server, which is already fixed. Your definition now produces a mocked response containing the specified example array.

Helen
  • 87,344
  • 17
  • 243
  • 314