jsonchema bump to v4 (2020-12 draft) breaks bma.blockchain.difficulties
Problem
Since jsonschema
bump from v3 to v4, at least bma.blockchain.difficulties
throws the error in this post.
Error
>>> from duniterpy.api import bma
>>> from duniterpy.api.client import Client
>>> c = Client("BMAS g1.duniter.org 443")
>>> c(bma.blockchain.difficulties)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/work/u23a14/ML/duniterpy/duniterpy/api/client.py", line 442, in __call__
return _function(self, *args, **kwargs)
File "/work/u23a14/ML/duniterpy/duniterpy/api/bma/blockchain.py", line 330, in difficulties
return client.get(f"{MODULE}/difficulties", schema=DIFFICULTIES_SCHEMA)
File "/work/u23a14/ML/duniterpy/duniterpy/api/client.py", line 359, in get
return client.request_url(
File "/work/u23a14/ML/duniterpy/duniterpy/api/client.py", line 274, in request_url
parse_response(content, schema)
File "/work/u23a14/ML/duniterpy/duniterpy/api/client.py", line 89, in parse_response
jsonschema.validate(data, schema)
File "/home/u23a14/.cache/pypoetry/virtualenvs/duniterpy-3m7gpsy_-py3.10/lib/python3.10/site-packages/jsonschema/validators.py", line 1117, in validate
cls.check_schema(schema)
File "/home/u23a14/.cache/pypoetry/virtualenvs/duniterpy-3m7gpsy_-py3.10/lib/python3.10/site-packages/jsonschema/validators.py", line 231, in check_schema
raise exceptions.SchemaError.create_from(error)
jsonschema.exceptions.SchemaError: [{'type': 'object', 'properties': {'uid': {'type': 'string'}, 'level': {'type': 'number'}}, 'required': ['uid', 'level']}] is not of type 'object', 'boolean'
Failed validating 'type' in metaschema['allOf'][1]['properties']['properties']['additionalProperties']['$dynamicRef']['allOf'][1]['properties']['items']['$dynamicRef']['allOf'][0]:
{'$defs': {'anchorString': {'pattern': '^[A-Za-z_][-A-Za-z0-9._]*$',
'type': 'string'},
'uriReferenceString': {'format': 'uri-reference',
'type': 'string'},
'uriString': {'format': 'uri', 'type': 'string'}},
'$dynamicAnchor': 'meta',
'$id': 'https://json-schema.org/draft/2020-12/meta/core',
'$schema': 'https://json-schema.org/draft/2020-12/schema',
'$vocabulary': {'https://json-schema.org/draft/2020-12/vocab/core': True},
'properties': {'$anchor': {'$ref': '#/$defs/anchorString'},
'$comment': {'type': 'string'},
'$defs': {'additionalProperties': {'$dynamicRef': '#meta'},
'type': 'object'},
'$dynamicAnchor': {'$ref': '#/$defs/anchorString'},
'$dynamicRef': {'$ref': '#/$defs/uriReferenceString'},
'$id': {'$comment': 'Non-empty fragments not allowed.',
'$ref': '#/$defs/uriReferenceString',
'pattern': '^[^#]*#?$'},
'$ref': {'$ref': '#/$defs/uriReferenceString'},
'$schema': {'$ref': '#/$defs/uriString'},
'$vocabulary': {'additionalProperties': {'type': 'boolean'},
'propertyNames': {'$ref': '#/$defs/uriString'},
'type': 'object'}},
'title': 'Core vocabulary meta-schema',
'type': ['object', 'boolean']}
On schema['properties']['levels']['items']:
[{'properties': {'level': {'type': 'number'},
'uid': {'type': 'string'}},
'required': ['uid', 'level'],
'type': 'object'}]
JSON Drafts
From what I understood, v4 introduced 2020-12
and 2019-09
drafts and therefore the last one supported becomes default.
These drafts are JSON specifications for jsonschema
schemas.
BMA
I quickly checked the other bma
GET
requests, and they seem to work. We don’t have (integration) tests checking that the GET
requests are still working.
bma.blockchain.difficulties
does not support 2020-12
draft, but supports previous ones.
This seems to be only affecting bma.blockchain.DIFFICULTIES_SCHEMA
since it’s the only one declaring "items": []
items
with a list. I would fix this one by using prefixItems
as stated in this ticket.
Solutions
We have these choices:
- switch back to
jsonschema
v3.2.0, but, I would prefer the latter to keep the latestjsonschema
version - In
DIFFICULTIES_SCHEMA
:- set
"$schema": jsonschema.Draft7Validator.META_SCHEMA["$id"],
- remove the list
[]
wrapping, not sure if this is correct - set
prefixItems
- set
References
Edited by Moul