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

Recursive references cause a RangeError (stack overflow) #24

Open
bascoder opened this issue Dec 12, 2016 · 0 comments
Open

Recursive references cause a RangeError (stack overflow) #24

bascoder opened this issue Dec 12, 2016 · 0 comments

Comments

@bascoder
Copy link
Contributor

When running matic for a JSON file with recursive references ($ref), then a RangeError is caused.

C:\node_modules\matic\lib\merge.js:52
        itterate(val, key, obj, schema);
        ^

RangeError: Maximum call stack size exceeded
    at C:\node_modules\matic\lib\merge.js:52:9
    at Function._.each._.forEach (C:\node_modules\matic\node_modules\underscore\underscore.js:87:22)
    at C:\node_modules\matic\lib\merge.js:14:7
    at C:\node_modules\matic\lib\merge.js:52:9
    at Function._.each._.forEach (C:\node_modules\matic\node_modules\underscore\underscore.js:87:22)
    at C:\node_modules\matic\lib\merge.js:14:7
    at merge (C:\node_modules\matic\lib\merge.js:64:12)
    at C:\node_modules\matic\lib\merge.js:33:36
    at Function._.each._.forEach (C:\node_modules\matic\node_modules\underscore\underscore.js:87:22)
    at C:\node_modules\matic\lib\merge.js:14:7

As example I cloned matic-draft4-example([https://github.com/mattyod/matic-draft4-example). And I changed the example.json file to the following:

{
  "title": "Matic Draft 4 Example",
  "Description": "An example schema to demonstrate Matic",
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "items": {
    "allOf": [
      {
        "$ref": "#definitions/foo"
      },
      {
        "$ref": "#definitions/bar"
      }
    ],
    "anyOf": [
      {
        "$ref": "#definitions/foo"
      }
    ],
    "oneOf": [
      {
        "$ref": "#definitions/bar"
      }
    ]
  },
  "definitions": {
    "foo": {
      "title": "Foo",
      "description": "A foo schema",
      "$schema": "http://json-schema.org/draft-04/schema#",
      "type": "object",
      "properties": {
        "url": {
          "title": "A url",
          "description": "An example url schema",
          "type": "string",
          "format": "uri",
          "example": "http://github.com/mattyod/matic"
        },
        "list": {
          "title": "A list",
          "description": "A list of things",
          "type": "array",
          "example": [
            "one",
            "two",
            "three"
          ]
        },
        "recursion" : {
          "$ref": "#definitions/foo"
        }
      },
      "required": [
        "url"
      ]
    },
    "bar": {
      "title": "Bar",
      "description": "A bar schema",
      "$schema": "http://json-schema.org/draft-04/schema#",
      "type": "object",
      "properties": {
        "thing": {
          "title": "thing",
          "description": "a thing that uses a local pointer to an other thing for it's properties",
          "type": "object",
          "properties": {
            "$ref": "example"
          }
        },
        "thing2": {
          "$ref": "#/properties/otherThing"
        },
        "otherThing": {
          "id": "example",
          "type": "integer"
        }
      },
      "required": [
        "thing",
        "thing2",
        "otherThing"
      ]
    }
  }
}

Note that I've inlined the bar and foo objects. And to foo I have added the following property:

"recursion" : {
          "$ref": "#definitions/foo"
        }

So it contains a recursive reference which is allowed by the JSON Schema spec.

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

1 participant