brandur/json_schema

Expanding json schema causes stack level too deep error

Closed this issue · 0 comments

Here is the brief POC code.

json = <<_JSON_
{
    "id": "http://example.com/poc.json",
    "$schema": "http://json-schema.org/draft-04/hyper-schema#",
    "definitions": {
        "self":    { "$ref": "#" },
        "synonym": { "$ref": "#/definitions/self" }
    },
    "properties": {
        "id":   { "type": "string" }
    }
}
_JSON_

schema = JsonSchema::Parser.new.parse!(JSON.parse(json))
schema.expand_references #=> SystemStackError

I found #/definitions/synonym is treated as original, and schema_children of it includes #/definitions/synonym.
It means schema.parent returns schema itself, and it cause infinite loop and stack level too deep error when schema.parent is called against #/definitions/synonym.
(See: https://github.com/brandur/json_schema/blob/master/lib/json_schema/reference_expander.rb#L100-L104)

I also found # were not treated as original. This is also wired.

I tried to fix "original problem", but I can't....