python-jsonschema / jsonschema

An implementation of the JSON Schema specification for Python
https://python-jsonschema.readthedocs.io
MIT License
4.58k stars 578 forks source link

Failed to validate the schema when shifted from RefResolver to Registry #1174

Closed vishalmane9 closed 11 months ago

vishalmane9 commented 11 months ago

Description: Failed to validate the schema when shifted from RefResolver to Registry and getting an issue of jsonschema.exceptions._WrappedReferencingError: Unresolvable: file:./dynamic_lists_schema.json#/definitions/dynamic_lists_settings

Please refer below files, both are on same levels in directory, This is the test_schema.json

{
    "$schema": "http://json-schema.org/draft-06/schema#",
    "description": "schema for the JSON settings",
    "type": "object",
    "required": [
        "dynamic_lists"
    ],
    "properties": {
        "dynamic_lists": {
            "$ref": "file:./dynamic_lists_schema.json#/definitions/dynamic_lists_settings"
        }
    }
}

and there is another file of dynamic_lists_schema.json, using this file in test_schema.json


{
    "$schema": "http://json-schema.org/draft-06/schema#",
    "definitions": {
        "dynamic_lists_settings": {
            "type": "object",
            "description": "Dynamic block list feature",
            "additionalProperties": false,
            "properties": {
                "enabled": {
                    "type": "boolean",
                    "description": "enables or disables the entire dynamic blocklist feature"
                },
                "configurations": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/dynamic_lists_configuration"
                    }
                }
            }
        },
        "dynamic_lists_configuration": {
            "type": "object",
            "description": "Dynamic block list configurations",
            "additionalProperties": false,
            "properties": {
                "enabled": {
                    "type": "boolean",
                    "description": "True, if user want this configuration to be active."
                },
                "name": {
                    "type": "string",
                    "description": "Name of the block list from source"
                },
                "id": {
                    "type": "string",
                    "description": "ID of the block list from source"
                },
            }
    }
}
Julian commented 11 months ago

That isn't a valid URI -- relative file URIs don't exist in that way. Please look around for other similar issues both here and in the referencing repo, and follow up if you still have questions.

vishalmane9 commented 11 months ago

I didn't find something to provide the relative path of the schema file in $ref, can you please let me know if you have any idea about it...it will be really helpful

Julian commented 11 months ago

https://referencing.readthedocs.io/en/stable/intro/#populating-registries is essentially the basic documentation and seems like it should work for your case -- give both your schemas IDs, populate a registry with both, and then you can use those IDs within the schemas to refer to one or the other.

vishalmane9 commented 10 months ago

Thanks for the reply...I have gone through the Document you provided but didn't find any example, for populating the IDs, can you please provide some link or document which shows how to IDs in schemas