dredd icon indicating copy to clipboard operation
dredd copied to clipboard

Problem with example node for parameter definition

Open ShimShtein opened this issue 5 years ago • 3 comments

Describe the bug Dredd returns an error when example node does not exist for parameters.

To Reproduce

dredd tmp/shim_doc2.json http://localhost:3000 -y -l debug

json:

{
  "openapi": "3.0.0",
  "info": {
    "version": "1.0.0",
    "title": "API V1",
    "description": ""
  },
  "security": [
    {
      "nil": [

      ]
    }
  ],
  "tags": [
    {
      "name": "Apps"
    },
    {
      "name": "Docs"
    }
  ],
  "paths": {
    "/api/hooks/apps": {
      "get": {
        "operationId": "Apps_Index",
        "tags": [
          "Apps"
        ],
        "description": "Lists all apps requested",
        "parameters": [
          {
            "$ref": "#/components/parameters/Bleh"
          }
        ],
        "responses": {
          "200": {
            "description": "lists all apps requested",
            "content": {
              "application/vnd.api+json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/App"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "App": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "example": "6",
            "description": "Identifier of the application"
          }
        },
        "description": "object"
      }
    },
    "parameters": {
      "Bleh": {
        "name": "X-BLEH-BLEH",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string",
          "example": "bleh"
        }
      }
    }
  }
}

Dredd output:

@shim (dredd)$ dredd tmp/shim_doc2.json http://localhost:3000 -y -l debug
2019-05-15T15:19:50.362Z - debug: Loading configuration file: ./dredd.yml
2019-05-15T15:19:50.364Z - debug: Dredd version: 11.1.0
2019-05-15T15:19:50.364Z - debug: Node.js version: v10.15.0
2019-05-15T15:19:50.364Z - debug: Node.js environment: http_parser=2.9.0, node=10.15.0, v8=6.8.275.32-node.45, uv=1.26.0, zlib=1.2.11, ares=1.15.0, modules=64, nghttp2=1.34.0, napi=3, openssl=1.1.1, icu=62.1, unicode=11.0, cldr=33.1, tz=2018e
2019-05-15T15:19:50.364Z - debug: System version: Linux 4.20.16-200.fc29.x86_64 x64
2019-05-15T15:19:50.524Z - debug: npm version: 6.4.1
2019-05-15T15:19:50.524Z - debug: Configuration: {"_":["tmp/shim_doc2.json"],"color":true,"y":true,"dry-run":true,"l":"debug","loglevel":"debug","hookfiles":null,"f":null,"language":"nodejs","a":"nodejs","require":null,"server":"http://localhost:3000","g":null,"server-wait":3,"init":false,"i":false,"custom":{"cwd":"/home/shim/Documents/foreman/mcom/notifications-backend","argv":["tmp/shim_doc2.json","http://localhost:3000","-y","-l","debug"]},"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":["tmp/shim_doc2.json","tmp/shim_doc2.json"],"p":["tmp/shim_doc2.json","tmp/shim_doc2.json"],"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":"dredd"}
2019-05-15T15:19:50.527Z - debug: No backend server process specified, starting testing at once
2019-05-15T15:19:50.528Z - debug: Running Dredd instance.
2019-05-15T15:19:50.528Z - debug: Resolving --require
2019-05-15T15:19:50.528Z - debug: Configuring reporters
2019-05-15T15:19:50.528Z - debug: Using 'base' reporter.
2019-05-15T15:19:50.529Z - debug: Configuring reporters: []
2019-05-15T15:19:50.529Z - debug: Using 'cli' reporter.
2019-05-15T15:19:50.529Z - debug: Preparing API description documents
2019-05-15T15:19:50.529Z - debug: Resolving locations of API description documents
2019-05-15T15:19:50.532Z - debug: Reading API description documents
2019-05-15T15:19:50.549Z - debug: Parsing API description documents
2019-05-15T15:19:50.606Z - debug: Compiling HTTP transactions from API description documents
2019-05-15T15:19:50.613Z - debug: Dredd instance run finished.
2019-05-15T15:19:50.613Z - error: Unable to compile HTTP transactions from API description document '/home/shim/Documents/foreman/mcom/notifications-backend/tmp/shim_doc2.json': Cannot read property 'toValue' of undefined: Cannot read property 'toValue' of undefined
2019-05-15T15:19:50.613Z - debug: Using native process.exit() method to terminate the Dredd process with status '1'.
2019-05-15T15:19:50.613Z - debug: No backend server process to terminate.

Expected behavior If the input JSON is changed to have the example node outside of schema, everything works:

    "parameters": {
      "Bleh": {
        "name": "X-BLEH-BLEH",
        "in": "header",
        "required": true,
        "schema": {
          "type": "string"
        },
        "example": "bleh"
      }

Results in:

@shim (dredd)$ dredd tmp/shim_doc2.json http://localhost:3000 -y -l debug
2019-05-15T15:19:43.351Z - debug: Loading configuration file: ./dredd.yml
2019-05-15T15:19:43.353Z - debug: Dredd version: 11.1.0
2019-05-15T15:19:43.354Z - debug: Node.js version: v10.15.0
2019-05-15T15:19:43.354Z - debug: Node.js environment: http_parser=2.9.0, node=10.15.0, v8=6.8.275.32-node.45, uv=1.26.0, zlib=1.2.11, ares=1.15.0, modules=64, nghttp2=1.34.0, napi=3, openssl=1.1.1, icu=62.1, unicode=11.0, cldr=33.1, tz=2018e
2019-05-15T15:19:43.354Z - debug: System version: Linux 4.20.16-200.fc29.x86_64 x64
2019-05-15T15:19:43.514Z - debug: npm version: 6.4.1
2019-05-15T15:19:43.514Z - debug: Configuration: {"_":["tmp/shim_doc2.json"],"color":true,"y":true,"dry-run":true,"l":"debug","loglevel":"debug","hookfiles":null,"f":null,"language":"nodejs","a":"nodejs","require":null,"server":"http://localhost:3000","g":null,"server-wait":3,"init":false,"i":false,"custom":{"cwd":"/home/shim/Documents/foreman/mcom/notifications-backend","argv":["tmp/shim_doc2.json","http://localhost:3000","-y","-l","debug"]},"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":["tmp/shim_doc2.json","tmp/shim_doc2.json"],"p":["tmp/shim_doc2.json","tmp/shim_doc2.json"],"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":"dredd"}
2019-05-15T15:19:43.518Z - debug: No backend server process specified, starting testing at once
2019-05-15T15:19:43.519Z - debug: Running Dredd instance.
2019-05-15T15:19:43.519Z - debug: Resolving --require
2019-05-15T15:19:43.519Z - debug: Configuring reporters
2019-05-15T15:19:43.519Z - debug: Using 'base' reporter.
2019-05-15T15:19:43.521Z - debug: Configuring reporters: []
2019-05-15T15:19:43.521Z - debug: Using 'cli' reporter.
2019-05-15T15:19:43.522Z - debug: Preparing API description documents
2019-05-15T15:19:43.522Z - debug: Resolving locations of API description documents
2019-05-15T15:19:43.525Z - debug: Reading API description documents
2019-05-15T15:19:43.533Z - debug: Parsing API description documents
2019-05-15T15:19:43.596Z - debug: Compiling HTTP transactions from API description documents
2019-05-15T15:19:43.603Z - warn: API description parser warning in /home/shim/Documents/foreman/mcom/notifications-backend/tmp/shim_doc2.json:8 (from line 8 column 3 to column 13): 'OpenAPI Object' contains unsupported key 'security'
2019-05-15T15:19:43.603Z - warn: API description parser warning in /home/shim/Documents/foreman/mcom/notifications-backend/tmp/shim_doc2.json:15 (from line 15 column 3 to column 9): 'OpenAPI Object' contains unsupported key 'tags'
2019-05-15T15:19:43.603Z - warn: API description parser warning in /home/shim/Documents/foreman/mcom/notifications-backend/tmp/shim_doc2.json:27 (from line 27 column 9 to column 15): 'Operation Object' contains unsupported key 'tags'
2019-05-15T15:19:43.603Z - warn: API description parser warning in /home/shim/Documents/foreman/mcom/notifications-backend/tmp/shim_doc2.json:73 (from line 73 column 9 to column 17): 'Parameter Object' contains unsupported key 'schema'
2019-05-15T15:19:43.603Z - debug: Starting the transaction runner
2019-05-15T15:19:43.604Z - debug: Starting reporters and waiting until all of them are ready
2019-05-15T15:19:43.604Z - debug: Beginning Dredd testing...
2019-05-15T15:19:43.604Z - debug: Sorting HTTP transactions
2019-05-15T15:19:43.604Z - debug: Configuring HTTP transactions
2019-05-15T15:19:43.606Z - debug: Reading hook files and registering hooks
2019-05-15T15:19:43.607Z - debug: Found Hookfiles:
2019-05-15T15:19:43.631Z - debug: Executing HTTP transactions
2019-05-15T15:19:43.631Z - debug: Running 'beforeAll' hooks
2019-05-15T15:19:43.633Z - debug: Processing transaction #1: /api/hooks/apps > GET > 200 > application/vnd.api+json
2019-05-15T15:19:43.633Z - debug: Running 'beforeEach' hooks
2019-05-15T15:19:43.633Z - debug: Running 'before' hooks
2019-05-15T15:19:43.634Z - debug: Emitting to reporters: test start
info: Dry run. Not performing HTTP request
2019-05-15T15:19:43.635Z - debug: Running 'afterEach' hooks
2019-05-15T15:19:43.635Z - debug: Running 'after' hooks
2019-05-15T15:19:43.636Z - debug: Evaluating results of transaction execution #1: /api/hooks/apps > GET > 200 > application/vnd.api+json
2019-05-15T15:19:43.636Z - debug: Emitting to reporters: test skip
skip: GET (200) /api/hooks/apps
2019-05-15T15:19:43.636Z - debug: Running 'afterAll' hooks
2019-05-15T15:19:43.636Z - debug: Wrapping up testing and waiting until all reporters are done
complete: 0 passing, 0 failing, 0 errors, 1 skipped, 1 total
complete: Tests took 32ms
2019-05-15T15:19:43.637Z - debug: Dredd instance run finished.
2019-05-15T15:19:43.637Z - debug: Using native process.exit() method to terminate the Dredd process with status '0'.
2019-05-15T15:19:43.637Z - debug: No backend server process to terminate.

What is in your dredd.yml?

no YAML, running from command line.

What's your dredd --version output?

dredd v11.1.0 (Linux 4.20.16-200.fc29.x86_64; x64)

Does dredd --loglevel=debug uncover something?

Not too much

Can you send us failing test in a Pull Request?

I am Ruby programmer, so it would take me some time to get the tests right.

ShimShtein avatar May 15 '19 15:05 ShimShtein

@ShimShtein The OpenAPI 3 parser doesn't yet support schema inside a Parameter Object, there is a warning stating this in the output of Dredd

2019-05-15T15:19:43.603Z - warn: API description parser warning in /home/shim/Documents/foreman/mcom/notifications-backend/tmp/shim_doc2.json:73 (from line 73 column 9 to column 17): 'Parameter Object' contains unsupported key 'schema'

I've created an issue at https://github.com/apiaryio/api-elements.js/issues/226 to track this in the parser.

kylef avatar May 15 '19 16:05 kylef

Is there some sort of workaround for this?

ShimShtein avatar May 16 '19 04:05 ShimShtein

some news here? i've got a list of warning just because of this :/

thomassittig avatar Dec 04 '20 16:12 thomassittig