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 Size Exceeded #135

Closed
TyOverby opened this issue Dec 20, 2017 · 10 comments
Closed

Maximum Call Size Exceeded #135

TyOverby opened this issue Dec 20, 2017 · 10 comments
Assignees

Comments

@TyOverby
Copy link

While attempting to compile the following file, I get the a crash with the text "Maximum Call Size Exceeded". For whatever reason I don't get a call stack.

https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json

@bcherny
Copy link
Owner

bcherny commented Dec 21, 2017

Thanks for the report @TyOverby! Can you try to whittle this down to a minimal reproducible case? My hunch is it's a bug with the $ref resolver.

@TyOverby
Copy link
Author

Unfortunately, the size is the repro. I tried trimming it down, but because of how interconnected everything is, it's basically all or nothing.

I turned DEBUG logging on, and it makes it all the way through downloading / resolving and (I think) parsing. My guess would be emit.

@bcherny
Copy link
Owner

bcherny commented Dec 26, 2017

Confirmed that there is a cycle in some union/intersection type that the generator isn't handling:

node --harmony_tailcalls --stack_size=10000 ./node_modules/.bin/ava
// stack overflow

I'll try to continue this investigation this week. @TyOverby Any trimming down of the bad test case you can manage would be immensely helpful.

@mikepatrick
Copy link

Hi there, I saw the "help wanted" tag so I took a look at this.

The bulk of the file in question consists of the long list of schemas in the oneOf under resourceBase. Two of these schemas in particular seem to be problematic.

  • Microsoft.DataFactory.json#/resourceDefinitions/factories and
  • Microsoft.DataFactory.json#/resourceDefinitions/factories_pipelines

both cause my compilation to fail if included.

In other words, if I remove these two entries from the file in question, it compiles fine. Conversely, a file containing only one of these two entries fails to compile.

For example, this trimmed down example, containing only the factories entry, fails to compile. Changing factories to factories_pipelines also results in failure.

@bcherny
Copy link
Owner

bcherny commented Dec 27, 2017

@mikepatrick Thanks for digging into this! As a next step, it would be really helpful to try and figure out what exactly the cycle is that JSTT is choking on. Once we can figure out what the cycle is, we can create a minimal reproducible test case and handle the cycle wherever it's not getting handled currently.

@jdoklovic
Copy link

I'm getting this error as well trying to use the Jira schema:
https://developer.atlassian.com/cloud/jira/platform/swagger.v3.json

Error is:

    at Array.sort (native)
    at /home/doklovic/data/gitstuff/node-jira/node_modules/es5-ext/object/_iterate.js:22:9
    at Function.self (/home/doklovic/data/gitstuff/node-jira/node_modules/cli-color/bare.js:57:3)
    at generateType (/home/doklovic/data/gitstuff/node-jira/node_modules/json-schema-to-typescript/dist/src/generator.js:110:41)
    at /home/doklovic/data/gitstuff/node-jira/node_modules/json-schema-to-typescript/dist/src/generator.js:151:47
    at Array.map (<anonymous>)
    at generateInterface (/home/doklovic/data/gitstuff/node-jira/node_modules/json-schema-to-typescript/dist/src/generator.js:149:14)
    at generateType (/home/doklovic/data/gitstuff/node-jira/node_modules/json-schema-to-typescript/dist/src/generator.js:121:34)
    at /home/doklovic/data/gitstuff/node-jira/node_modules/json-schema-to-typescript/dist/src/generator.js:117:24
    at generateType (/home/doklovic/data/gitstuff/node-jira/node_modules/json-schema-to-typescript/dist/src/generator.js:119:11)

@ianloic
Copy link

ianloic commented Apr 24, 2019

I'm hitting this issue with https://fuchsia.googlesource.com/fuchsia/+/master/zircon/system/host/fidl/schema.json (at this ref)

I've reduced it to a small test case. This works:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "recursive": {
            "$ref": "#/definitions/recursive"
        }
    },
    "definitions": {
        "recursive": {
            "type": "object",
            "properties": {
                "self": {
                    "$ref": "#/definitions/recursive"
                }
            }
        }
    }
}

but this does not:

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "object",
    "properties": {
        "recursive": {
            "$ref": "#/definitions/recursive"
        }
    },
    "definitions": {
        "recursive": {
            "type": "object",
            "properties": {
                "self": {
                    "any-other-property": "with-a-value",
                    "$ref": "#/definitions/recursive"
                }
            }
        }
    }
}

The additional property (it was originally a description but it doesn't seem to matter what it is) confuses things. I've narrowed it down to parser.parse() not realizing that it's seen the node before at first and generates some extra nesting. Then generator.generateInterface recurses forever.

I'm not really sure how to actually fix the problem but that's what I found.

@dl748
Copy link
Contributor

dl748 commented Mar 14, 2020

I'm having a problem with a circular references.

types.schema.json

{
  "$schema": "https://json-schema.org/draft-7/schema",
  "$id": "types.schema.json",
  "title": "types",
  "definitions": {
    "JSONAny": {
      "anyOf": [
        { "$ref": "#/definitions/JSONSimple" },
        { "$ref": "#/definitions/JSONArray" },
        { "$ref": "#/definitions/JSONObject" }
      ]
    },
    "JSONObject": {
      "additionalProperties": {
        "$ref": "#/definitions/JSONAny"
      }
    },
    "JSONArray": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/JSONAny"
      }
    },
    "JSONSimple": {
      "type": [ "string", "number", "boolean", "null" ]
    }
  },
  "properties": {
    "JSONAny": {
      "$ref": "#/definitions/JSONAny"
    }
  }
}

executing json2ts --unreachableDefinitions --input types.schema.json is working correctly

/* tslint:disable */
/**
 * This file was automatically generated by json-schema-to-typescript.
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
 * and run json-schema-to-typescript to regenerate this file.
 */

/**
 * This interface was referenced by `Types`'s JSON-Schema
 * via the `definition` "JSONAny".
 */
export type JSONAny = JSONSimple | JSONArray | JSONObject;
/**
 * This interface was referenced by `Types`'s JSON-Schema
 * via the `definition` "JSONSimple".
 */
export type JSONSimple = string | number | boolean | null;
/**
 * This interface was referenced by `Types`'s JSON-Schema
 * via the `definition` "JSONArray".
 */
export type JSONArray = JSONAny[];

export interface Types {
  JSONAny?: JSONAny;
  [k: string]: any;
}
/**
 * This interface was referenced by `Types`'s JSON-Schema
 * via the `definition` "JSONObject".
 */
export interface JSONObject {
  [k: string]: JSONAny;
}

which is expected but then if i try to use it from an external file, i'm getting errors

test.schema.json

{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "$id": "test.schema.json",
  "title": "test",
  "type": "object",
  "properties": {
    "test": {
      "$ref": "types.schema.json#/definitions/JSONAny"
    }
  }
}

I'm getting

error RangeError: Maximum call stack size exceeded
    at node_modules/json-schema-to-typescript/dist/src/generator.js:256:43
    at Array.map (<anonymous>)
    at generateSetOperation (node_modules/json-schema-to-typescript/dist/src/generator.js:256:30)
    at generateRawType (node_modules/json-schema-to-typescript/dist/src/generator.js:247:20)
    at generateType (node_modules/json-schema-to-typescript/dist/src/generator.js:142:16)
    at node_modules/json-schema-to-typescript/dist/src/generator.js:256:56
    at Array.map (<anonymous>)
    at generateSetOperation (node_modules/json-schema-to-typescript/dist/src/generator.js:256:30)
    at generateRawType (node_modules/json-schema-to-typescript/dist/src/generator.js:247:20)
    at generateType (node_modules/json-schema-to-typescript/dist/src/generator.js:142:16)

if i pull in the definitions manually, I don't get any error

{
  "$schema": "https://json-schema.org/draft/2019-09/schema",
  "$id": "test.schema.json",
  "title": "test",
  "type": "object",
  "additionalProperties": false,
  "definitions": {
    "JSONAny": {
      "anyOf": [
        { "$ref": "#/definitions/JSONSimple" },
        { "$ref": "#/definitions/JSONArray" },
        { "$ref": "#/definitions/JSONObject" }
      ]
    },
    "JSONObject": {
      "additionalProperties": {
        "$ref": "#/definitions/JSONAny"
      }
    },
    "JSONArray": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/JSONAny"
      }
    },
    "JSONSimple": {
      "type": [ "string", "number", "boolean", "null" ]
    }
  },
  "properties": {
    "test": {
      "$ref": "#/definitions/JSONAny"
    }
  }
}

produces

/* tslint:disable */
/**
 * This file was automatically generated by json-schema-to-typescript.
 * DO NOT MODIFY IT BY HAND. Instead, modify the source JSONSchema file,
 * and run json-schema-to-typescript to regenerate this file.
 */

/**
 * This interface was referenced by `Test`'s JSON-Schema
 * via the `definition` "JSONAny".
 */
export type JSONAny = JSONSimple | JSONArray | JSONObject;
/**
 * This interface was referenced by `Test`'s JSON-Schema
 * via the `definition` "JSONSimple".
 */
export type JSONSimple = string | number | boolean | null;
/**
 * This interface was referenced by `Test`'s JSON-Schema
 * via the `definition` "JSONArray".
 */
export type JSONArray = JSONAny[];

export interface Test {
  test?: JSONAny;
}
/**
 * This interface was referenced by `Test`'s JSON-Schema
 * via the `definition` "JSONObject".
 */
export interface JSONObject {
  [k: string]: JSONAny;
}

which is correct

@hillaryan
Copy link

hillaryan commented Apr 14, 2020

If anyone can fix this issue, submit a pull request and get it merged, I will pay them $200. To claim this, email me at [email protected]

@OrangeDrangon
Copy link

OrangeDrangon commented Aug 28, 2020

@ianloic After some fiddling with this issue. I believe that your broken case should in fact be broken. I am not an expert on JSON Schema but the way you have defined properties makes no sense. There is no merge capability in JSON Schema and that is what you are essentially asking it to do.

image

As you can see this random validator I found does not understand it. but if you declare the schema in a different way:

  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
      "recursive": {
          "$ref": "#/definitions/recursive"
      }
  },
  "additionalProperties": false,
  "definitions": {
      "recursive": {
          "type": "object",
          "properties": {
              "self": {
                  "type": "object",
                  "properties": {
                    "any-other-property": {"type": "integer"},
                    "recursive": {
                        "$ref": "#/definitions/recursive"
                    }
                },
                "additionalProperties": false
              }
          },
          "additionalProperties": false
      }
  }
}

image
Now the JSON parser understands it and even better this parser can parse it as well.

bcherny pushed a commit that referenced this issue Aug 7, 2022
@bcherny bcherny closed this as completed Aug 7, 2022
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

8 participants