IBM/openapi-validator

Runtime error when validating endpoints referred from another file

Closed this issue ยท 7 comments

Reproducible with Version 0.92.0

A runtime error is thrown when validating an endpoint with 2xx response whose definition is referenced from another file. Check the test.yml and referred.yml files in the attached zip file.
To reproduce try to validate test.yml.

The zip file also includes outputs from version 0.91.0 and the result of validating non 2xx response (with version 0.92.0) for which the bug is NOT reproducible.

Stack trace:


[Error] There was a problem with spectral.
Error running Nimma


[Error] Additional error details:

AggregateError: Error running Nimma
    at Scope.destroy (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/dist/legacy/cjs/runtime/scope.js:137:13)
    at Nimma.eval (eval at query (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/dist/legacy/cjs/core/index.js:66:71), <anonymous>:347:11)
    at Nimma.query (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/dist/legacy/cjs/core/index.js:68:71)
    at execute (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/@stoplight/spectral-core/dist/runner/runner.js:90:11)
    at Runner.run (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/@stoplight/spectral-core/dist/runner/runner.js:53:13)
    at Spectral.runWithResolved (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/@stoplight/spectral-core/dist/spectral.js:60:22)
    at async Spectral.run (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/@stoplight/spectral-core/dist/spectral.js:68:17)
    at async processInput (/usr/local/lib/node_modules/ibm-openapi-validator/src/cli-validator/run-validator.js:246:25) {
  [errors]: [
    RuntimeError: $.paths[*].get.responses[?(@property.match(/2\d\d/))].content[*].schema threw: ErrorWithCause("Function \"\" threw an exception: Cannot read properties of undefined (reading 'operationId')")
        at _callbacks.<computed> (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/dist/legacy/cjs/runtime/proxy-callbacks.js:34:21)
        at callback (eval at <anonymous> (eval at query (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/dist/legacy/cjs/core/index.js:66:71)), <anonymous>:6:7)
        ... 4 lines matching cause stack trace ...
        at /usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/node_modules/jsonpath-plus/dist/index-node-cjs.cjs:369:19
        at /usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/node_modules/jsonpath-plus/dist/index-node-cjs.cjs:576:7
        at Array.forEach (<anonymous>)
        at JSONPath._walk (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/node_modules/jsonpath-plus/dist/index-node-cjs.cjs:575:22) {
      cause: [ErrorWithCause]
    }
  ]
}

example.zip

I think I have the same error as @katya-spasova

[Error] There was a problem with spectral.
Error running Nimma


[Error] Additional error details:

AggregateError: Error running Nimma
    at Scope.destroy (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/dist/legacy/cjs/runtime/scope.js:137:13)
    at Nimma.eval (eval at query (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/dist/legacy/cjs/core/index.js:66:71), <anonymous>:411:11)
    at Nimma.query (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/dist/legacy/cjs/core/index.js:68:71)
    at execute (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/@stoplight/spectral-core/dist/runner/runner.js:82:11)
    at Runner.run (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/@stoplight/spectral-core/dist/runner/runner.js:51:13)
    at Spectral.runWithResolved (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/@stoplight/spectral-core/dist/spectral.js:59:22)
    at async Spectral.run (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/@stoplight/spectral-core/dist/spectral.js:67:17)
    at async processInput (/usr/local/lib/node_modules/ibm-openapi-validator/src/cli-validator/run-validator.js:246:25) {

My OpenAPI structure looks like this:

  • _index.yaml
  • user.yaml

index.yaml:

openapi: 3.0.3
servers:
  - url: 'http://localhost:8000'
paths:
  ### USER
  /users:
    $ref: 'user.yaml#/paths/~1users'

user.yaml:

openapi: 3.0.3
info:
  title: User components
  version: partial
paths:
  /users:
...

validator: 0.96.1; ruleset: 0.44.1

This will be resolved by #511

Resolved in 0.96.2

Hey @dpopp07 ,
Looks like the released binary for macOS is still on v0.96.1.

You're right, just confirmed this. I will investigate

@mehdi-sol I opened up an issue with the details

The good news is, it should only be the version number printed that is wrong. The binary should be reflective of the latest version of the code

Thank you for checking this out @dpopp07.
I've installed the package using npm and I can confirm the version is now 0.96.2:

lint-openapi --version
validator: 0.96.2; ruleset: 0.44.2

But I still get crashes:

lint-openapi -e -s -v openapi/openapi.yaml
'lodash/isPlainObject' is imported by lodash/isPlainObject?commonjs-external, but could not be resolved โ€“ treating it as an external dependency
'lodash/isEqual' is imported by lodash/isEqual?commonjs-external, but could not be resolved โ€“ treating it as an external dependency
'lodash/uniqWith' is imported by lodash/uniqWith?commonjs-external, but could not be resolved โ€“ treating it as an external dependency
'lodash/pickBy' is imported by lodash/pickBy?commonjs-external, but could not be resolved โ€“ treating it as an external dependency

[Error] There was a problem with spectral.
Error running Nimma


[Error] Additional error details:

AggregateError: Error running Nimma
    at Scope.destroy (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/dist/legacy/cjs/runtime/scope.js:137:13)
    at Nimma.eval (eval at query (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/dist/legacy/cjs/core/index.js:66:71), <anonymous>:411:11)
    at Nimma.query (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/dist/legacy/cjs/core/index.js:68:71)
    at execute (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/@stoplight/spectral-core/dist/runner/runner.js:82:11)
    at Runner.run (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/@stoplight/spectral-core/dist/runner/runner.js:51:13)
    at Spectral.runWithResolved (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/@stoplight/spectral-core/dist/spectral.js:55:22)
    at async Spectral.run (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/@stoplight/spectral-core/dist/spectral.js:63:17)
    at async processInput (/usr/local/lib/node_modules/ibm-openapi-validator/src/cli-validator/run-validator.js:246:25) {
  [errors]: [
    RuntimeError: $.paths[*] threw: ErrorWithCause("Function \"noEtagHeader$1\" threw an exception: Cannot read properties of undefined (reading 'toLowerCase')")
        at _callbacks.<computed> (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/dist/legacy/cjs/runtime/proxy-callbacks.js:34:21)
        at Scope.emit (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/dist/legacy/cjs/runtime/scope.js:109:19)
        ... 4 lines matching cause stack trace ...
        at _traverseBody (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/dist/legacy/cjs/runtime/traverse.js:17:5)
        at _traverse (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/dist/legacy/cjs/runtime/traverse.js:41:7)
        at Scope.traverse (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/dist/legacy/cjs/runtime/traverse.js:47:3)
        at Scope.traverse (/usr/local/lib/node_modules/ibm-openapi-validator/node_modules/nimma/dist/legacy/cjs/runtime/scope.js:94:25) {
      cause: [ErrorWithCause]
    }
  ]
}

The worst part is sometimes the process runs successfully, sometimes it doesn't!

The most recent non-crashing version for me seems to be v0.84.2. Anything higher and I frequently get these Nimma crashes.