-
Notifications
You must be signed in to change notification settings - Fork 57
Description
Hi,
I think I've reached a bug when using a definition called type.
This is the minimal example I could build to reproduce the situation:
Input
test.json file:
{
"$schema": "test.schema.json",
"type": "test"
}Failing schema
test.schema.json
{
"$schema": "http://json-schema.org/schema",
"properties": {
"type": {
"$ref": "#/$defs/definitionGroup/type"
}
},
"$defs": {
"definitionGroup": {
"type": {
"type": "string",
"description": "'type' description"
}
}
}
}Running check-jsonschema produces the following output:
$ check-jsonschema test.json --schemafile test.schema.json
Error: schemafile was not valid: {'type': 'string', 'description': "'type' description"} is not valid under any of the given schemas
Failed validating 'anyOf' in metaschema['allOf'][0]['properties']['$defs']['additionalProperties']['$dynamicRef']['allOf'][3]['properties']['type']:
{'anyOf': [{'$ref': '#/$defs/simpleTypes'},
{'items': {'$ref': '#/$defs/simpleTypes'},
'minItems': 1,
'type': 'array',
'uniqueItems': True}]}
On schema['$defs']['definitionGroup']['type']:
{'description': "'type' description", 'type': 'string'}
SchemaError: {'type': 'string', 'description': "'type' description"} is not valid under any of the given schemas
Failed validating 'anyOf' in metaschema['allOf'][0]['properties']['$defs']['additionalProperties']['$dynamicRef']['allOf'][3]['properties']['type']:
{'anyOf': [{'$ref': '#/$defs/simpleTypes'},
{'items': {'$ref': '#/$defs/simpleTypes'},
'minItems': 1,
'type': 'array',
'uniqueItems': True}]}
On schema['$defs']['definitionGroup']['type']:
{'description': "'type' description", 'type': 'string'}
in "/home/ntrozzo/.local/lib/python3.10/site-packages/check_jsonschema/checker.py", line 52
>>> return self._schema_loader.get_validator(If the definition is not inside definitionGroup it does not fail.
Schema fixed
Changing the definition name to types instead of type makes the validation pass:
test.schema.json:
{
"$schema": "http://json-schema.org/schema",
"properties": {
"type": {
"$ref": "#/$defs/definitionGroup/types"
}
},
"$defs": {
"definitionGroup": {
"types": {
"type": "string",
"description": "'type' description"
}
}
}
}The output changes to:
$ check-jsonschema test.json --schemafile test.schema.json
ok -- validation doneTo be honest, I have not checked the JSON Schema spec to know if this is a valid schema or not, but it works fine using the JSON Schema VScode extension and it fails when using check-jsonschema.
It took me a while to realise where the error was, and I think it's possibly a bug because the type keyword could be easily hardcoded somewhere.
check-jsonschema version
$ check-jsonschema --version
check-jsonschema, version 0.23.2I'm running this on Ubuntu 22.