为什么不在SwaggerHub上为我的模拟Swagger 2 API显示数组示例?

时间:2018-01-24 05:13:56

标签: swagger swagger-2.0 swaggerhub

以下是代码片段:

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

在来自SwaggerHub的模拟API中,它返回一个空数组。

2 个答案:

答案 0 :(得分:0)

我发现的问题是它应该是'例子:'并且上升一级而不是'例如:'并且还需要指定内容类型 - 这是下面的工作示例...

以下是代码片段

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

答案 1 :(得分:0)

这是SwaggerHub的模拟服务器中的一个错误,已经修复了。您的定义现在生成包含指定示例数组的模拟响应。