json-schema-ref-parser
json-schema-ref-parser copied to clipboard
Infinite recursion
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"
I am fairly convinced that https://github.com/APIDevTools/json-schema-ref-parser/pull/169 fixes this issue.
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)
#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.
Can you folks try out 9.0.9 and see if that's fixed it?