Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded #118

Open
mohamedelhabib opened this issue Dec 16, 2020 · 4 comments

Comments

@mohamedelhabib
Copy link
Contributor

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'
@codekie
Copy link
Owner

codekie commented Dec 16, 2020

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
Copy link
Owner

codekie commented Dec 16, 2020

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.

@mohamedelhabib
Copy link
Contributor Author

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

@codekie
Copy link
Owner

codekie commented Dec 16, 2020

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants