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

Infinite recursion #180

Closed
jeanfrancois8512 opened this issue Jun 2, 2020 · 4 comments
Closed

Infinite recursion #180

jeanfrancois8512 opened this issue Jun 2, 2020 · 4 comments

Comments

@jeanfrancois8512
Copy link

Hi, I'm not sure this is a bug with this library, the library that does the call, or my schema.

here the stack trace:

RangeError: Maximum call stack size exceeded
    at RegExp.exec (<anonymous>)
    at Url.parse (url.js:257:31)
    at urlParse (url.js:150:13)
    at Object.urlResolve [as resolve] (url.js:660:10)
    at resolveIf$Ref (node_modules/json-schema-ref-parser/lib/pointer.js:218:24)
    at Pointer.resolve (node_modules/json-schema-ref-parser/lib/pointer.js:80:9)
    at $Ref.resolve (node_modules/json-schema-ref-parser/lib/ref.js:83:18)
    at $Refs._resolve (node_modules/json-schema-ref-parser/lib/refs.js:155:15)
    at resolveIf$Ref (node_modules/json-schema-ref-parser/lib/pointer.js:225:41)
    at Pointer.resolve (node_modules/json-schema-ref-parser/lib/pointer.js:80:9)
...
    at Array.forEach (<anonymous>)
    at crawl (node_modules/json-schema-ref-parser/lib/dereference.js:52:24)
    at /node_modules/json-schema-ref-parser/lib/dereference.js:65:28
    at Array.forEach (<anonymous>)
    at crawl (node_modules/json-schema-ref-parser/lib/dereference.js:52:24)
    at /node_modules/json-schema-ref-parser/lib/dereference.js:65:28
    at Array.forEach (<anonymous>)
    at crawl (node_modules/json-schema-ref-parser/lib/dereference.js:52:24)
    at /node_modules/json-schema-ref-parser/lib/dereference.js:65:28
    at Array.forEach (<anonymous>)
    at crawl (node_modules/json-schema-ref-parser/lib/dereference.js:52:24)
    at /node_modules/json-schema-ref-parser/lib/dereference.js:65:28
    at Array.forEach (<anonymous>)
    at crawl (node_modules/json-schema-ref-parser/lib/dereference.js:52:24)
    at /node_modules/json-schema-ref-parser/lib/dereference.js:65:28
    at Array.forEach (<anonymous>)
    at crawl (node_modules/json-schema-ref-parser/lib/dereference.js:52:24)
    at dereference (node_modules/json-schema-ref-parser/lib/dereference.js:20:22)
    at /node_modules/json-schema-ref-parser/lib/index.js:248:7
    at async module.exports (node_modules/ibm-openapi-validator/src/cli-validator/utils/buildSwaggerObject.js:40:26)
    at async module.exports (node_modules/ibm-openapi-validator/src/lib/index.js:16:19)
    at async Context.<anonymous> (test/openapi.test.js:16:20)

The file to be validated by ibm-openapi-validator:

openapi: 3.0.2
info:
  title: this is a test
  version: 1.0.0

paths:
  /test:
    get:
      description: won't work
      responses:
        "200":
          description: ""
          content:
            application/json:
              schema:
                $ref: "trie.yml"

and the referenced schema:

definitions:
  trie:
    type: object
    properties:
      name:
        type: string
      children:
        type: array
        items:
          $ref: "#/definitions/trie"

$ref: "#/definitions/trie"
@P0lip
Copy link
Member

P0lip commented Jun 26, 2020

I am fairly convinced that #169 fixes this issue.

@mohamedelhabib
Copy link

mohamedelhabib commented Dec 16, 2020

I have the same issue with the below openapi. i'am using v9.0.6 version it contains the #169 fix

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
          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'
(node:17) UnhandledPromiseRejectionWarning: RangeError: Maximum call stack size exceeded
    at crawl (/usr/lib/node_modules/openapi-examples-validator/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:54:16)
    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)
    at crawl (/usr/lib/node_modules/openapi-examples-validator/node_modules/@apidevtools/json-schema-ref-parser/lib/resolve-external.js:70:38)

@jeanfrancois8512
Copy link
Author

#169 Did you try my example or @mohamedelhabib one? I think those can be good test cases. I have read your test and I'm not even sure if your schema is recursive. If I find some time to try it by my self I will let you know if it works. Thanks for the patch this really interesting stuff.

@philsturgeon
Copy link
Member

Can you folks try out 9.0.9 and see if that's fixed it?

@jonluca jonluca closed this as completed Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants