openapi-examples-validator icon indicating copy to clipboard operation
openapi-examples-validator copied to clipboard

UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded

Open mohamedelhabib opened this issue 5 years ago • 4 comments

Hello

i'am using the openapi-examples-validator (4.2.0) to validate a openapi spec yaml that contains a recursive object. i got this error below a example openapi document

(node:19) UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded
    at Function.keys (<anonymous>)
    at crawl (/usr/lib/node_modules/openapi-examples-validator/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:62:30)
    at crawl (/usr/lib/node_modules/openapi-examples-validator/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)
    at crawl (/usr/lib/node_modules/openapi-examples-validator/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)
    at crawl (/usr/lib/node_modules/openapi-examples-validator/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)
    at crawl (/usr/lib/node_modules/openapi-examples-validator/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)
    at crawl (/usr/lib/node_modules/openapi-examples-validator/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)
    at crawl (/usr/lib/node_modules/openapi-examples-validator/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)
    at crawl (/usr/lib/node_modules/openapi-examples-validator/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)
    at crawl (/usr/lib/node_modules/openapi-examples-validator/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)
(node:19) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 4)
(node:19) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

openapi: 3.0.3
info:
  version: 1.0.0
  title: recurive-api
paths:
  /categories:
    get:
      tags:
        - categories
      operationId: listCategories
      responses:
        200:
          description: List of categories retrieved Successfully
          content:
            'application/json':
              schema:
                $ref: '#/components/schemas/Node'
components:
  schemas:
    Node:
      title: Node
      description: This is a recursive element and can hold categories, sub-categories and products
      type: object
      properties:
        nodes:
          type: array
          items:
            $ref: '#/components/schemas/Node'

mohamedelhabib avatar Dec 16 '20 20:12 mohamedelhabib

Yes. In the current implementation that's not going to work because before the validation starts the spec is dereferenced and in this case it ends up in an infinite recursion. I have to check if there's an easy way to solve this.

codekie avatar Dec 16 '20 20:12 codekie

I just had a look at the JSON-schema validator that I use to validate the OpenAPI-description against the examples (which is ajv) and they don't support circular references (see: https://github.com/ajv-validator/ajv/blob/HEAD/docs/security.md#circular-references-in-javascript-objects). So I'll have to put this on hold until they support it.

codekie avatar Dec 16 '20 20:12 codekie

But the issue seem to be related to @apidevtools/json-schema-ref-parser and not to ajv-validator ?

mohamedelhabib avatar Dec 16 '20 21:12 mohamedelhabib

The only way I see to resolve this is to not dereference it in this case but instead keeping the reference pointer in the JSON-schema but then I'd have that circular reference that ajv can't handle.

codekie avatar Dec 16 '20 21:12 codekie