swagger - Swagger 2.0 中的 JSON API 示例

标签 swagger json-api swagger-2.0

我正在尝试使用 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,但它无法识别它。如果我删除这些示例,我的规范就可以工作。知道如何指定它吗?

error

最佳答案

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 类型相关的错误,你不能使用点,这就是为什么我没有放置 application/vnd.api+json

关于swagger - Swagger 2.0 中的 JSON API 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31458005/

相关文章:

node.js - 从nodejs/express 项目中提供 swagger-ui

c# - 如何向 "Request and Response Model"添加 swagger 注释?

azure - Azure AD 中的 API 权限和公开 API 之间有什么区别?

rest - 应该对 json-api 响应中的链接进行编码吗?

Azure API 管理 - 使用 Swagger 2.0 规范导入 API - 不考虑响应的架构属性

java - swagger是否保存任何文件

swagger - 如何更改 Swagger Codegen 生成的 JavaScript 模块名称?

java - Katharsis 2.8.2 升级问题

node.js - 找不到合适的模拟服务器来提供带有预定义 url 的 json 响应

swagger - 是否可以在 Swagger ui 之前添加登录页面?