dredd icon indicating copy to clipboard operation
dredd copied to clipboard

OpenAPI3 Cannot read property 'toValue' of undefined on valid contract

Open eelessam opened this issue 6 years ago • 2 comments

Describe the bug I've seen existing bugs reported for similar error messages but I think the error message is a generic one.

Dredd gives me an error when using an OpenAPI 3 contract. It's been working for me with Swagger contracts but now fails as I try to move to OpenAPI 3

2019-09-27T12:47:42.444Z - debug: Loading configuration file: ./dredd.yml
2019-09-27T12:47:42.447Z - debug: Dredd version: 12.0.8
2019-09-27T12:47:42.447Z - debug: Node.js version: v12.10.0
2019-09-27T12:47:42.447Z - debug: Node.js environment: node=12.10.0, v8=7.6.303.29-node.16, uv=1.31.0, zlib=1.2.11, brotli=1.0.7, ares=1.15.0, modules=72, nghttp2=1.39.2, napi=4, llhttp=1.1.4, http_parser=2.8.0, openssl=1.1.1c, cldr=35.1, icu=64.2, tz=2019a, unicode=12.1
2019-09-27T12:47:42.448Z - debug: System version: Darwin 18.5.0 x64
2019-09-27T12:47:42.671Z - debug: npm version: 6.11.3
2019-09-27T12:47:42.671Z - debug: Configuration: {"_":["/Users/sam.eeles/workspace/contract-producer-app/src/main/resources/new-open-api.yaml"],"color":true,"l":"debug","loglevel":"debug","dry-run":null,"y":null,"hookfiles":null,"f":null,"language":"nodejs","a":"nodejs","require":null,"server":"localhost:8080","g":null,"server-wait":3,"init":false,"i":false,"custom":{"cwd":"/Users/sam.eeles/workspace/contract-producer-app","argv":["-l","debug","/Users/sam.eeles/workspace/contract-producer-app/src/main/resources/new-open-api.yaml","localhost:8080"]},"j":[],"names":false,"n":false,"only":[],"x":[],"reporter":[],"r":[],"output":[],"o":[],"header":[],"h":[],"sorted":false,"s":false,"user":null,"u":null,"inline-errors":false,"e":false,"details":false,"d":false,"method":[],"m":[],"path":["/Users/sam.eeles/workspace/contract-producer-app/src/main/resources/new-open-api.yaml","/Users/sam.eeles/workspace/contract-producer-app/src/main/resources/new-open-api.yaml"],"p":["/Users/sam.eeles/workspace/contract-producer-app/src/main/resources/new-open-api.yaml","/Users/sam.eeles/workspace/contract-producer-app/src/main/resources/new-open-api.yaml"],"hooks-worker-timeout":5000,"hooks-worker-connect-timeout":1500,"hooks-worker-connect-retry":500,"hooks-worker-after-connect-wait":100,"hooks-worker-term-timeout":5000,"hooks-worker-term-retry":500,"hooks-worker-handler-host":"127.0.0.1","hooks-worker-handler-port":61321,"config":"./dredd.yml","$0":"/usr/local/Cellar/node/12.10.0/bin/node /usr/local/bin/dredd"}
2019-09-27T12:47:42.676Z - debug: No backend server process specified, starting testing at once
2019-09-27T12:47:42.676Z - debug: Running Dredd instance.
2019-09-27T12:47:42.676Z - debug: Resolving --require
2019-09-27T12:47:42.676Z - debug: Configuring reporters
2019-09-27T12:47:42.677Z - debug: Using 'base' reporter.
2019-09-27T12:47:42.678Z - debug: Configuring reporters: []
2019-09-27T12:47:42.679Z - debug: Using 'cli' reporter.
2019-09-27T12:47:42.679Z - debug: Preparing API description documents
2019-09-27T12:47:42.679Z - debug: Resolving locations of API description documents
2019-09-27T12:47:42.683Z - debug: Reading API description documents
2019-09-27T12:47:42.691Z - debug: Parsing API description documents
2019-09-27T12:47:42.759Z - debug: Compiling HTTP transactions from API description documents
2019-09-27T12:47:42.766Z - debug: Dredd instance run finished.
2019-09-27T12:47:42.766Z - error: Unable to compile HTTP transactions from API description document '/Users/sam.eeles/workspace/contract-producer-app/src/main/resources/new-open-api.yaml': Cannot read property 'toValue' of undefined: Cannot read property 'toValue' of undefined
2019-09-27T12:47:42.767Z - debug: Using native process.exit() method to terminate the Dredd process with status '1'.
2019-09-27T12:47:42.767Z - debug: No backend server process to terminate.

To Reproduce Run dredd with this contract:

 openapi: 3.0.0
info:
  title: ban-check
  version: '1.0'
servers:
  - url: 'http://localhost:3000'
paths:
  /demo-app/ban-check:
    post:
      summary: ban-check
      tags: []
      responses:
        201:
          description: Created
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    enum:
                      - BANNED
                      - NOT_BANNED
                  tom:
                    type: string
                    enum:
                      - BANNED
                      - NOT_BANNED
                required:
                  - status
      parameters:
        - schema:
            type: string
            enum:
              - VENTURE1
              - VENTURE2
          in: header
          name: Venture-Name
          required: true
      requestBody:
        content:
          application/json:
            schema:
              type: object
              properties:
                dni:
                  type: string
                  minLength: 9
                  maxLength: 9
                  pattern: '^[0-9]+$'
              required:
                - dni
        description: Dni requiest
components:
  schemas: {}

Expected behavior I expected Dedd to run against my api

What is in your dredd.yml?

I don't think I have one?

What's your dredd --version output?

dredd v12.0.8 (Darwin 18.5.0; x64)

Does dredd --loglevel=debug uncover something? If you run Dredd with debugging output, do you see any interesting information relevant to the bug? Log shows im running it in debug already

Can you send us failing test in a Pull Request? We'll gladly help you to contribute; answering yes raises the chances the issue gets fixed. Do you mean a PR to your repo? Or you want access to my repo with it failing?

eelessam avatar Sep 27 '19 13:09 eelessam

@eelessam My apoligies that this issue never got any attention. I just came across it and had a quick dig into it.

The underlying problem is around handling the headers, in particular the handling in Dredd expects every header to have a "value" (example) so in this case the header doesn't have a value, it causes Dredd to throw an internal error as above.

Even if that above internal error didn't happen Dredd wouldn't be sure which value to send (the header Venture-Name is declared as required). In this particular case there is a schema with enumerations, so Dredd could pick the first one and use that for the request. This will require a bit of changes to our OpenAPI 3.0 parser and Dredd to be able to handle headers in this way. We'll also need to figure out how to handle the case where there is no enumerations, examples for required headers. I would expect perhaps Dredd would warn if there wasn't a concrete value.

As a work around, you can provide an example value for your Parameter Object, as follows:

name: Venture-Name
in: header
required: true
example: VENTURE1
schema:
  enum: [VENTURE1, VENTURE2]

kylef avatar Feb 17 '20 14:02 kylef

Thank you for the work around! I will keep an eye out for a permanent fix

eelessam avatar Apr 24 '20 15:04 eelessam