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

JsonParser Fails to Inherit Reference Object Type #106

Open
NJordan72 opened this issue May 20, 2024 · 2 comments
Open

JsonParser Fails to Inherit Reference Object Type #106

NJordan72 opened this issue May 20, 2024 · 2 comments

Comments

@NJordan72
Copy link
Contributor

Take the following JSON Schema

{
  "$defs": {
    "ParentObject": {
      "properties": {
          "child": {
             "type": "string"
          }
      },
      "type": "object"
    }
  },
  "properties": {
    "parent": {
      "$ref": "#/$defs/ParentObject"
    }
  }
}

We would expect this to inherit the object type from ParentObject but instead on input

{"parent": {"child": "test"}}'

we get Exception: Unsupported type None. To fix we have to declare an an object type directly.

@noamgat
Copy link
Owner

noamgat commented May 31, 2024

I'm not sure this is correct. Why should the top level object be classified as an object? Its relation to the ParentObject is that the value of key "parent" is ParentObject, but that doesn't indicate that the top level object in this case is an object in itself. Is there something in the JSON schema spec that says otherwise?

Indeed, adding "type": "object" to the top level object fixes it, and from my (maybe incomplete) understanding, I think that is expected behavior.

@NJordan72
Copy link
Contributor Author

I think it should be inhereting the object type because the reference is, in fact, defined as an object:

{
    "ParentObject": {
        "properties": {
            "child": {
                "type": "string"
            }
        },
        "type": "object"
    }
}

My understanding of how references should work is basically to treat the inner value of the reference as if it was replaced inline.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants