首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法使DREDD使用schema.example作为POST体

无法使DREDD使用schema.example作为POST体
EN

Stack Overflow用户
提问于 2019-02-13 18:57:46
回答 1查看 590关注 0票数 2

我试图使用Dredd来测试我的OpenAPI指定的API,但是我无法让Dredd识别我的POST请求的JSON,它总是用一个空的正文发送我的POST请求。根据Dredd的文档,它使用schema.example来表示"in":" body“,这正是我正在做的事情,但是Dredd一直在用空体发布帖子。

我尝试过OpenAPI3和OpenAPI2,结果都是一样的。我在OpenAPI2规范中的POST操作如下所示:

代码语言:javascript
复制
  /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定义时,对于这个操作,它并不像它应该的那样发送主体:

代码语言:javascript
复制
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,并得到了相同的结果。

任何帮助都将不胜感激。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2019-02-28 12:45:06

这个问题已经很久了,但问题仍然存在: Dredd似乎忽略了body参数,如果消费字段丢失了。

所以试着:

代码语言:javascript
复制
/availableCounters:
  post:
    summary: Get the available counters for a specified time range
    consumes:
     - application/json
[...]
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54677500

复制
相关文章

相似问题

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