我试图使用Dredd来测试我的OpenAPI指定的API,但是我无法让Dredd识别我的POST请求的JSON,它总是用一个空的正文发送我的POST请求。根据Dredd的文档,它使用schema.example来表示"in":" body“,这正是我正在做的事情,但是Dredd一直在用空体发布帖子。
我尝试过OpenAPI3和OpenAPI2,结果都是一样的。我在OpenAPI2规范中的POST操作如下所示:
/availableCounters:
post:
summary: Get the available counters for a specified time range
description: This API returns the available counters for the specific time range requested.
responses:
'200':
description: OK
schema:
type: object
properties:
properties:
type: array
items:
$ref: '#/definitions/property_spec'
'400':
description: 'Could not retrieve available Counters: ${error}'
parameters:
- required: true
name: body
in: body
schema:
example: {"searchSpan": {"from": {"dateTime": "2019-01-20T21:50:37.349Z"},"to": {"dateTime": "2019-01-22T21:50:37.349Z"}}}
type: object
properties:
searchSpan:
$ref: '#/definitions/from_to'但是,当我使用Dredd测试这个OpenAPI定义时,对于这个操作,它并不像它应该的那样发送主体:
request:
method: POST
uri: /availableCounters
headers:
User-Agent: Dredd/8.0.0 (Windows_NT 10.0.17134; x64)
body:
expected:
headers:
statusCode: 200
bodySchema: {"type":"object","properties":{"properties":{"type":"array","items":{"$ref":"#/definitions/property_spec"}}},"definitions":{"property_spec":{"type":"object","properties":{"name":{"type":"string"},"type":{"type":"string","enum":["Double","String","DateTime"]}}}}}
actual:
statusCode: 400
headers:
connection: close
date: Tue, 12 Feb 2019 23:22:09 GMT
content-type: text/plain; charset=utf-8
server: Kestrel
content-length: 96
bodyEncoding: utf-8
body:
Could not retrieve available Counters: TypeError: Cannot read property 'searchSpan' of undefined我试过使用schema.example和schema.x-示例,但是Dredd不会发送身体。如前所述,我也尝试过OpenAPI3,并得到了相同的结果。
任何帮助都将不胜感激。
发布于 2019-02-28 12:45:06
这个问题已经很久了,但问题仍然存在: Dredd似乎忽略了body参数,如果消费字段丢失了。
所以试着:
/availableCounters:
post:
summary: Get the available counters for a specified time range
consumes:
- application/json
[...]https://stackoverflow.com/questions/54677500
复制相似问题