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

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

Closed
LeatherDeerAU opened this issue Feb 9, 2022 · 3 comments · Fixed by #1460
Labels
Milestone

Comments

@LeatherDeerAU
Copy link

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"
          }
        }
      }
    }
  }
}
@eirnym
Copy link

eirnym commented Feb 9, 2022

Could you write a gist and compile an example model?

@LeatherDeerAU
Copy link
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

@joelittlejohn
Copy link
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.

@unkish unkish added the bug label Feb 18, 2022
unkish added a commit to unkish/jsonschema2pojo that referenced this issue Dec 29, 2022
@joelittlejohn joelittlejohn added this to the 1.1.3 milestone Jan 21, 2023
joelittlejohn pushed a commit to unkish/jsonschema2pojo that referenced this issue Jan 21, 2023
@joelittlejohn joelittlejohn 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 Jan 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants