2

I'm trying to use Dredd to test my OpenAPI specified API but I can't get Dredd to recognize the JSON body of my POST requests, it keeps sending my POST requests with an empty body. According to Dredd's documentation it uses the schema.example for "in": "body" and that's exactly what I am doing but Dredd keeps issuing the POST with empty body.

I've tried both OpenAPI3 and OpenAPI2 with the same result. My POST operation in OpenAPI2 specification looks like this:

  /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'

But when I use Dredd to test this OpenAPI definition, for this operation it doesn't send the body as it should:

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

I've tried using both schema.example and schema.x-example but Dredd will not send the body. As I've said previously I've also tried OpenAPI3 and I get the same result.

Any help would be greatly appreciated.

1 Answers1

2

The question is old, but the problem is still there: Dredd seems to ignore the body parameter, if the consumes field is missing.

So try:

/availableCounters:
  post:
    summary: Get the available counters for a specified time range
    consumes:
     - application/json
[...]
Tommy
  • 579
  • 7
  • 21
  • Even though I had a body parameter of schema `type: string` and an `example` value, without `consumes` with `text/plain`, Dredd would not send the body! Although to be fair, it does output the problem, just not with a clear action to fix: `fail: headers: At '/content-type' No enum match for: "application/problem+json"` – Henry Blyth Dec 10 '19 at 11:00