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

RangeError for circular references to oneOf containing definition with the $ref #547

Closed
christianklotz opened this issue Aug 22, 2023 · 3 comments

Comments

@christianklotz
Copy link

I have been trying to generate Typescript types from the Amazon State Language JSON Schema which leads to the following error:

RangeError: Maximum call stack size exceeded

As far as I can tell this is a circular reference where the referenced definition itself is a oneOf which in turn contains the definition with the $ref.

  "Not": {
    "$ref": "#/properties/States/additionalProperties/oneOf/4/allOf/2/properties/Choices/items/oneOf/18/properties/Not"
  },

Removing all unnecessary layers and definitions leaves the following schema.

Reduced schema

{
  "type": "object",
  "properties": {
    "States": {
      "type": "object",
      "properties": {
        "Choices": {
          "type": "array",
          "description": "An array of Choice Rules that determines which state the state machine transitions to next.",
          "minItems": 1,
          "items": {
            "type": "object",
            "properties": {
              "Not": {
                "oneOf": [
                  {
                    "type": "object",
                    "properties": {
                      "Not": {
                        "$ref": "#/properties/States/properties/Choices/items/properties/Not"
                      }
                    },
                    "required": [
                      "Not"
                    ]
                  }
                ]
              }
            },
            "required": [
              "Not"
            ]
          },
          "additionalItems": false
        }
      },
      "required": [
        "Choices"
      ]
    }
  },
  "required": [
    "States"
  ]
}

Reduced schema without oneOf in referenced type

The moment the referenced definition is an object, no longer a oneOf, the circular reference gets resolved correctly.

{
  "type": "object",
  "properties": {
    "States": {
      "type": "object",
      "properties": {
        "Choices": {
          "type": "array",
          "description": "An array of Choice Rules that determines which state the state machine transitions to next.",
          "minItems": 1,
          "items": {
            "type": "object",
            "properties": {
              "Not": {
                "type": "object",
                "properties": {
                  "Not": {
                    "$ref": "#/properties/States/properties/Choices/items/properties/Not"
                  }
                },
                "required": [
                  "Not"
                ]
              }
            },
            "required": [
              "Not"
            ]
          },
          "additionalItems": false
        }
      },
      "required": [
        "Choices"
      ]
    }
  },
  "required": [
    "States"
  ]
}

I'd be happy to take a look myself but would appreciate a few suggestions on where to look, possible routes.

@christianklotz
Copy link
Author

I looked at the issues earlier but somehow missed #523 which looks very similar.

@bcherny
Copy link
Owner

bcherny commented Aug 27, 2023

Dup of #523

@alexmojaki
Copy link

I disagree with closing this as a duplicate:

  1. Per my comment on Cyclical dependency in oneOf causes generation to fatal #523, it seems like that issue isn't an issue at all as the reported schema is invalid.
  2. The error is different: TypeError: Converting circular structure to JSON vs RangeError: Maximum call stack size exceeded.
  3. Closing this issue means that future readers are likely to only read the other issue and not this one and most likely get an incomplete picture.

Having said that, the minimal schema given here is confusing to think about. Unlike the other issue, this one passes validation, but it still seems invalid because I can't see how to construct a finite valid object according to the schema:

Screenshot from 2023-08-27 13-40-15

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

3 participants