justify icon indicating copy to clipboard operation
justify copied to clipboard

Infinite loop when two schemas references each other

Open hathiphant opened this issue 3 years ago • 1 comments

When I have two schemas each referencing the other, creating a loop, I see an error (infinite loop) when loading schemas.

Example

Schema 1 (file person.schema.json)

{
    "$id": "https://example.com/person.schema.json",
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "Person",
    "type": "object",
    "properties": {
        "firstName": {
            "type": "string",
            "description": "The person's first name."
        },
        "lastName": {
            "type": "string",
            "description": "The person's last name."
        },
        "company": {
            "$ref": "https://example.com/company.schema.json",
            "description": "The company's person."
        }
    },
    "additionalProperties": false
}

with property company referencing schema 2.

Schema 2 (file company.schema.json)

{
    "$id": "https://example.com/company.schema.json",
    "$schema": "http://json-schema.org/draft-07/schema#",
    "title": "company",
    "type": "object",
    "properties": {
        "name": {
            "type": "string",
            "description": "The company's name."
        },
        "CEO": {
            "$ref": "https://example.com/person.schema.json",
            "description": "The CEO person."
        }
    },
    "additionalProperties": false
}

with property CEO referencing schema 1.

Data (file person.json)

{
    "firstName": "John",
    "lastName": "Doe",
    "company": {
        "name": "inc."
    }
}

Tests

AJV works: ajv validate -s person.schema.json -r company.schema.json -d person.json

Justify fails by not finding back reference (schema 2 -> schema 1) with command ./justify -s person.schema.json -r company.schema.json -i person.json, of by stack overflow (infinite loop) with command ./justify -s person.schema.json -r company.schema.json -r person.schema.json -i person.json.

hathiphant avatar May 17 '21 07:05 hathiphant

@hathiphant Sorry for delayed response. Your report is nice and helpful. I reproduced the problem. Please wait for further investigation.

leadpony avatar May 23 '21 11:05 leadpony