Skip to content

Get Stackoverflow error if array items schema contains trees/cycle dependencies for children #1376

Closed

Description

@LeatherDeerAU

Is it possible to have a field inside an array object pointing to an external array? Such a scheme fails with StackOverflowError.

{
  "type": "array",
  "items": {
    "type": "object",
    "properties": {
      "folders": {
        "$ref": "#"
      }
    }
  }
}

But this schema locally generates classes:

{
  "type": "object",
  "additionalProperties": false,
  "properties": {
    "folders": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/folder"
      }
    }
  },
  "definitions": {
    "folder": {
      "type": "object",
      "properties": {
        "folders": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/folder"
          }
        }
      }
    }
  }
}

Activity

  1. eirnym commented on Feb 9, 2022

    @eirnym

    Could you write a gist and compile an example model?

  2. LeatherDeerAU commented on Feb 10, 2022

    @LeatherDeerAU
    Author

    I want to generate the following class:

    @Generated("jsonschema2pojo")
    public class MyFolder {
    
        @JsonProperty("folders")
        private List<Folder> folders = new ArrayList<Folder>();
    }
    
    @Generated("jsonschema2pojo")
    public class Folder {
        @JsonProperty("folders")
        private List<Folder> folders = new ArrayList<Folder>();
    }
    

    The second scheme from the first message successfully does this. The first scheme throws an error. It seems to me that this is the same scheme, written in different ways

  3. joelittlejohn commented on Feb 11, 2022

    @joelittlejohn
    Owner

    Yes, looks like there's a bug here in how the # reference is resolved. The first schema should just generate:

    @Generated("jsonschema2pojo")
    public class Folder {
        @JsonProperty("folders")
        private List<Folder> folders = new ArrayList<Folder>();
    }

    We have a variety of these self references in our tests, but something about this example is different. You're right it should work. We should add a test for this and fix.

  4. added a commit that references this issue on Dec 29, 2022
    253ad4e
  5. added this to the 1.1.3 milestone on Jan 21, 2023
  6. added a commit that references this issue on Jan 21, 2023
    a44ab03
  7. added a commit that references this issue on Jan 21, 2023
    eedf0ff
  8. changed the title [-]Get Stackoverflow error if schema contains trees/cycle dependencies for children[/-] [+]Get Stackoverflow error if array items schema contains trees/cycle dependencies for children[/+] on Jan 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions