【问题标题】:JSON API examples in Swagger 2.0Swagger 2.0 中的 JSON API 示例
【发布时间】:2015-10-06 02:57:13
【问题描述】:

我正在尝试使用 Swagger 2.0 为端点创建示例响应。

    200:
      description: Successful response
      schema:
        type: object
        $ref: "#/definitions/User"
      examples:
        application/vnd.api+json:
            - data:
                attributes:
                  full_name: John Appleseed
            - data:
                attributes:
                  full_name: Mike Appleseed

我的 api 消费并产生application/vnd.api+json,但它不会识别它。如果我删除这些示例,我的规范就会起作用。知道如何指定它吗?

【问题讨论】:

  • 这是由于用于验证的 JSON Schema 中存在的一个错误。虽然它已被修复,但编辑器更新需要几天时间。

标签: swagger json-api swagger-2.0


【解决方案1】:

它是not fully implemented yet,尽管您可以像这样定义一个示例:

   responses:
    "200":
      description: Successful response
      schema: 
        $ref: '#/definitions/User'
      examples:
        application/json:
          data:
            id: 1
            attributes:
              attr1: value1
              attr2: value2

有一个与mime-type有关的错误,你不能使用点,所以我没有放application/vnd.api+json

【讨论】:

  • 你不能用引号吗?
猜你喜欢
  • 2021-06-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-18
  • 2018-08-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多