check-jsonschema icon indicating copy to clipboard operation
check-jsonschema copied to clipboard

--check-metaschema doesn't check $ref referenced schemas

Open rssh22 opened this issue 7 months ago • 2 comments

Considering the next json schema definition:

{
   "title": "main.json"
    "$id": "file://test-schemas/schemas/main.json",
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "required": [
        "metadata"
    ],
    "properties": {
        "metadata": {
            "additionalProperties": false,
            "type": "object",
            "required": [
                "props1",
                "props2"
            ],
            "properties": {
                "props1": {
                    "$ref": "/schemas/props1.json#/props"
                },
                "props2": {
                    "$ref": "/schemas/props2.json#/props"
                }
            }
        }
    }
}
{
    "title": "props1.json"
    "$id": "/schemas/props1.json",
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "props": {
        "type": "object",
        "required": [
            "metadata"
        ],
        "properties": {
            "metadata": {
                "additionalProperties": false,
                "type": "object",
                "required": [
                    "name",
                    "id"
                ],
                "properties": {
                    "name": {
                        "type": "BADstring"
                    },
                    "id": {
                        "type": "integer"
                    }
                }
            }
        }
    }
}
{
   "title": "props2.json"
    "$id": "/schemas/props2.json",
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "props": {
        "type": "object",
        "required": [
            "metadata"
        ],
        "properties": {
            "metadata": {
                "additionalProperties": false,
                "type": "object",
                "required": [
                    "name",
                    "id"
                ],
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "id": {
                        "type": "integer"
                    }
                }
            }
        }
    }
}

I'd like to be able to check fully recursively the schema main.json but it seems that check-jsonchema --check-metaschema main.json doesn't traverse references.

In this case, props1.json schema contains an error. "type" can't be "BADstring" (according to the metaschema". However, the check of main.json returns an ok -- validation done

Am I doing something wrong, there is a bug, or it is feature that could be proposed for enhancement?

thanks in advance!!

rssh22 avatar Jul 18 '24 15:07 rssh22