首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Openapi3和CSV响应(适用于Dredd)

Openapi3和CSV响应(适用于Dredd)
EN

Stack Overflow用户
提问于 2020-02-17 22:15:50
回答 1查看 960关注 0票数 1

我使用DREDD根据它的规范(考虑用Openapi3编写,painfull limitations of Support by Dredd considered)来测试我的Api。不,我有一个端点,如果设置了Accept-header,它就会生成CSV-data。

代码语言:javascript
运行
复制
    '/my-endpoint':
        summary: ...
        description: ...
        get:
 #          parameters:
 #              - 
 #                  in: header
 #                  name: Accept
 #                  description: "Response format: application/json or text/csv"
 #                  example: "text/csv"
            responses:
                '200':
                    description: ...
                    content:
                        text/csv:
                            schema:
                                type: string
                            example:
                                summary: 'csv table'
                                value: 'cell1, cell2'

当我使用Dredd运行测试时,测试失败

代码语言:javascript
运行
复制
expected: 
headers: 

body: 
[
  {
    "key": "summary",
    "value": "csv table"
  },
  {
    "key": "value",
    "value": "cell1, cell2"
  }
]
statusCode: 200

显然,有些地方被误解了,Dredd希望JSON仍然存在。此外,API也不会被告知生成CSV版本。如果我在代码abvoe的Accept头中提交,我会得到完全相同的结果-上面的expecetd结果,以及作为实际结果的my- commit data的JSON版本,以及ad警告:

代码语言:javascript
运行
复制
warn: API description parser warning in .../tmp/transformed.specs.yml: 'Parameter Object' 'name' in location 'header' should not be 'Accept', 'Content-Type' or 'Authorization'

我读过herehereHeader parameters named Accept, Content-Type and Authorization are not allowed. To describe these headers, use the corresponding OpenAPI keywords --但它们是什么呢?根据thisthis页面的说法,指定给定类型的响应似乎就足够了,但这显然不足以告诉Dredd生成这样的头。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-17 22:43:23

您得到了一个错误,因为example键的值应该是一个文本示例值。因此,在本例中,它被视为具有summaryvalue属性的对象。

将您的定义更改为:

代码语言:javascript
运行
复制
                    content:
                        text/csv:
                            schema:
                                type: string
                            example: 'cell1, cell2'

或者,如果您想提供示例的摘要/描述,请改用examples

代码语言:javascript
运行
复制
                    content:
                        text/csv:
                            schema:
                                type: string
                            examples:
                                csv table:
                                    summary: A CSV table with 2 cells
                                    value: 'cell1, cell2'
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60264392

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档