[英]Openapi3 and CSV response (for Dredd)
I test my Api with DREDD against it's specification (written in Openapi3 considering, painfull limitations of Support by Dredd considered ).我用 DREDD 根据它的规范测试我的 Api(考虑到用 Openapi3 编写, Dredd 考虑了支持的痛苦限制)。 No I have one endpoint, which produces CSV-data if the Accept-header is set so.
不,我有一个端点,如果设置了 Accept-header,它会生成 CSV 数据。
'/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'
When I run the test with Dredd the test fails with当我用 Dredd 运行测试时,测试失败
expected:
headers:
body:
[
{
"key": "summary",
"value": "csv table"
},
{
"key": "value",
"value": "cell1, cell2"
}
]
statusCode: 200
Clearly there is something misunderstood and Dredd expects still JSON.显然存在一些误解,Dredd 仍然希望使用 JSON。 Also the API is not told to produce the CSV Version.
此外,API 不会被告知生成 CSV 版本。 If I commit in the Accept header in the code abvoe I get the very same result - the expecetd result above and as actual result the JSON version of the my-endpoint-data and also ad warning:
如果我在代码 abvoe 的 Accept 标头中提交,我会得到完全相同的结果 - 上面的预期结果和实际结果 my-endpoint-data 的 JSON 版本以及广告警告:
warn: API description parser warning in .../tmp/transformed.specs.yml: 'Parameter Object' 'name' in location 'header' should not be 'Accept', 'Content-Type' or 'Authorization'
I read here and here : Header parameters named Accept, Content-Type and Authorization are not allowed. To describe these headers, use the corresponding OpenAPI keywords
我在这里和这里阅读:
Header parameters named Accept, Content-Type and Authorization are not allowed. To describe these headers, use the corresponding OpenAPI keywords
Header parameters named Accept, Content-Type and Authorization are not allowed. To describe these headers, use the corresponding OpenAPI keywords
- but what are they? Header parameters named Accept, Content-Type and Authorization are not allowed. To describe these headers, use the corresponding OpenAPI keywords
- 但它们是什么? According to this and this page it seems to be enough to specify a response of the given type but that is clearly not enough to tell Dredd to produce such a header.根据this和this page似乎足以指定给定类型的响应,但这显然不足以告诉Dredd生成这样的标题。
You got an error because the value of the example
key is meant to be a literal example value.您收到错误,因为
example
键的值是文字示例值。 So in your case it's treated as an object with the summary
and value
properties.因此,在您的情况下,它被视为具有
summary
和value
属性的对象。
Change your definition to:将您的定义更改为:
content:
text/csv:
schema:
type: string
example: 'cell1, cell2'
Or if you want to provide a summary/description for an example, use examples
instead:或者,如果您想为示例提供摘要/描述,请改用
examples
:
content:
text/csv:
schema:
type: string
examples:
csv table:
summary: A CSV table with 2 cells
value: 'cell1, cell2'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.