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

Maximum call stack size exceeded when referencing external json with recursion #376

Closed
jose-bernard-receeve opened this issue Mar 17, 2021 · 5 comments

Comments

@jose-bernard-receeve
Copy link

jose-bernard-receeve commented Mar 17, 2021

Person.json

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "person": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "children": {
          "type": "array",
          "items": { "$ref": "#/definitions/person" },
          "default": []
        }
      }
    }
  },
  "type": "object",
  "properties": {
    "person": { "$ref": "#/definitions/person" }
  }
}

House.json

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "type": "object",
  "properties": {
    "owner": { "$ref": "Person.json" }
  }
}

output

Could not generate type definitions from json-schema RangeError: Maximum call stack size exceeded
    at Object.log (/Users/jose/dev/Decision-Tree/node_modules/json-schema-to-typescript/dist/src/utils.js:1:1)
    at generateRawType (/Users/jose/dev/Decision-Tree/node_modules/json-schema-to-typescript/dist/src/generator.js:153:13)
    at generateType (/Users/jose/dev/Decision-Tree/node_modules/json-schema-to-typescript/dist/src/generator.js:146:16)
    at /Users/jose/dev/Decision-Tree/node_modules/json-schema-to-typescript/dist/src/generator.js:273:47
    at Array.map (<anonymous>)
    at generateInterface (/Users/jose/dev/Decision-Tree/node_modules/json-schema-to-typescript/dist/src/generator.js:271:14)
    at generateRawType (/Users/jose/dev/Decision-Tree/node_modules/json-schema-to-typescript/dist/src/generator.js:168:20)
    at generateType (/Users/jose/dev/Decision-Tree/node_modules/json-schema-to-typescript/dist/src/generator.js:146:16)
    at /Users/jose/dev/Decision-Tree/node_modules/json-schema-to-typescript/dist/src/generator.js:162:28
    at generateRawType (/Users/jose/dev/Decision-Tree/node_modules/json-schema-to-typescript/dist/src/generator.js:164:15)

When I don't reference Person.json it works fine generating the recursive reference

Also tried this other Person schema

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "additionalProperties": false,
  "type": "object",
    "properties": {
      "name": { "type": "string" },
      "children": {
        "type": "array",
        "items": { "$ref": "#" }
      }
  }
}
@monzilnepali
Copy link

@bcherny Can I take this one?

@htbmw
Copy link

htbmw commented Apr 7, 2022

Is there anybody who could assist with this bug.
I encounter the same and need to generate typescript from a recursive JSON schema.
@monzilnepali Could you perhaps show us on a fork where the fixes should be made?

@jan-san
Copy link

jan-san commented Jun 1, 2022

As @bcherny mentioned in #453, this issue only appears for recursive JSON schemas where the recursed schema does not have a title. So adding a title property to the schema should prevent this issue.

@htbmw
Copy link

htbmw commented Jun 2, 2022

@jan-san , thanks for the response. I checked and they all have titles.
I suspect there is some edge case scenario in my schema that causes the issue.
I will have to replicate it with an easy to share example here.

bcherny added a commit that referenced this issue Jun 29, 2022
Fix cycles during emission (fix #376, fix #323)
@bcherny
Copy link
Owner

bcherny commented Jun 29, 2022

Published as part of v11.0.0.

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

5 participants