python-jsonschema / python-jsonschema/check-jsonschema

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

Open
#464 2 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement question
Dominant language
Python
Stars
341
Forks
71
Avg merge
15d 20h
Merged PRs (30d)
4

Description

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!!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the behavior with check-jsonschema --check-metaschema main.json and the supplied main.json, props1.json, and props2.json schemas. Trace how metaschema checking handles the $ref entries, then ensure the recursive check reports the BADstring type in props1.json while preserving the existing successful case for props2.json.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.