Upgrade CI scripts dependencies (#1786)
Will allow us to benefit from future fixes in JSON Schema validation. Signed-off-by: Kévin Commaille <zecakeh@tedomum.fr>
This commit is contained in:
parent
becc667672
commit
a81b720151
6 changed files with 51 additions and 13 deletions
1
changelogs/internal/newsfragments/1786.clarification
Normal file
1
changelogs/internal/newsfragments/1786.clarification
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Upgrade jsonschema and python-jsonpath CI scripts dependencies.
|
|
@ -42,6 +42,12 @@ except ImportError as e:
|
||||||
import_error("jsonschema", "jsonschema", "jsonschema", e)
|
import_error("jsonschema", "jsonschema", "jsonschema", e)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
try:
|
||||||
|
import referencing
|
||||||
|
except ImportError as e:
|
||||||
|
import_error("referencing", "referencing", "referencing", e)
|
||||||
|
raise
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import yaml
|
import yaml
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
|
@ -56,13 +62,14 @@ def check_example_file(examplepath, schemapath):
|
||||||
with open(schemapath) as f:
|
with open(schemapath) as f:
|
||||||
schema = yaml.safe_load(f)
|
schema = yaml.safe_load(f)
|
||||||
|
|
||||||
|
# $id as a URI with scheme is necessary to make registry resolver work.
|
||||||
fileurl = "file://" + os.path.abspath(schemapath)
|
fileurl = "file://" + os.path.abspath(schemapath)
|
||||||
schema["id"] = fileurl
|
schema["$id"] = fileurl
|
||||||
resolver = jsonschema.RefResolver(fileurl, schema, handlers={"file": helpers.load_file_from_uri})
|
|
||||||
|
|
||||||
print ("Checking schema for: %r %r" % (examplepath, schemapath))
|
print ("Checking schema for: %r %r" % (examplepath, schemapath))
|
||||||
try:
|
try:
|
||||||
validator = jsonschema.Draft202012Validator(schema, resolver)
|
registry = referencing.Registry(retrieve=helpers.load_resource_from_uri)
|
||||||
|
validator = jsonschema.validators.Draft202012Validator(schema, registry=registry)
|
||||||
validator.validate(example)
|
validator.validate(example)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError("Error validating JSON schema for %r %r" % (
|
raise ValueError("Error validating JSON schema for %r %r" % (
|
||||||
|
|
|
@ -42,6 +42,12 @@ except ImportError as e:
|
||||||
import_error("jsonschema", "jsonschema", "jsonschema", e)
|
import_error("jsonschema", "jsonschema", "jsonschema", e)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
try:
|
||||||
|
import referencing
|
||||||
|
except ImportError as e:
|
||||||
|
import_error("referencing", "referencing", "referencing", e)
|
||||||
|
raise
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import yaml
|
import yaml
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
|
@ -70,10 +76,12 @@ class SchemaDirReport:
|
||||||
self.errors += other_report.errors
|
self.errors += other_report.errors
|
||||||
|
|
||||||
def check_example(path, schema, example):
|
def check_example(path, schema, example):
|
||||||
# URI with scheme is necessary to make RefResolver work.
|
# $id as a URI with scheme is necessary to make registry resolver work.
|
||||||
fileurl = "file://" + os.path.abspath(path)
|
fileurl = "file://" + os.path.abspath(path)
|
||||||
resolver = jsonschema.RefResolver(fileurl, schema, handlers={"file": helpers.load_file_from_uri})
|
schema["$id"] = fileurl
|
||||||
validator = jsonschema.Draft202012Validator(schema, resolver)
|
|
||||||
|
registry = referencing.Registry(retrieve=helpers.load_resource_from_uri)
|
||||||
|
validator = jsonschema.validators.Draft202012Validator(schema, registry=registry)
|
||||||
|
|
||||||
validator.validate(example)
|
validator.validate(example)
|
||||||
|
|
||||||
|
@ -128,7 +136,7 @@ def check_schema_file(schema_path):
|
||||||
|
|
||||||
# Check schema is valid.
|
# Check schema is valid.
|
||||||
try:
|
try:
|
||||||
validator = jsonschema.Draft202012Validator
|
validator = jsonschema.validators.Draft202012Validator
|
||||||
validator.check_schema(schema)
|
validator.check_schema(schema)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Failed to validate JSON schema: {e}")
|
print(f"Failed to validate JSON schema: {e}")
|
||||||
|
|
|
@ -42,6 +42,12 @@ except ImportError as e:
|
||||||
import_error("jsonschema", "jsonschema", "jsonschema", e)
|
import_error("jsonschema", "jsonschema", "jsonschema", e)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
|
try:
|
||||||
|
import referencing
|
||||||
|
except ImportError as e:
|
||||||
|
import_error("referencing", "referencing", "referencing", e)
|
||||||
|
raise
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import yaml
|
import yaml
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
|
@ -50,8 +56,11 @@ except ImportError as e:
|
||||||
|
|
||||||
|
|
||||||
def check_schema(filepath, example, schema):
|
def check_schema(filepath, example, schema):
|
||||||
resolver = jsonschema.RefResolver(filepath, schema, handlers={"file": helpers.load_file_from_uri})
|
# $id as a URI with scheme is necessary to make registry resolver work.
|
||||||
validator = jsonschema.Draft202012Validator(schema, resolver)
|
schema["$id"] = filepath
|
||||||
|
|
||||||
|
registry = referencing.Registry(retrieve=helpers.load_resource_from_uri)
|
||||||
|
validator = jsonschema.validators.Draft202012Validator(schema, registry=registry)
|
||||||
validator.validate(example)
|
validator.validate(example)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
|
import referencing
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
@ -84,4 +85,15 @@ def load_file_from_uri(path):
|
||||||
else:
|
else:
|
||||||
# We have to assume it's YAML because some of the YAML examples
|
# We have to assume it's YAML because some of the YAML examples
|
||||||
# do not have file extensions.
|
# do not have file extensions.
|
||||||
return yaml.safe_load(f)
|
return yaml.safe_load(f)
|
||||||
|
|
||||||
|
def load_resource_from_uri(path):
|
||||||
|
"""Load a JSON or YAML JSON Schema, as a `referencing.Resource` object, from
|
||||||
|
a file:// URI.
|
||||||
|
"""
|
||||||
|
contents = load_file_from_uri(path)
|
||||||
|
resource = referencing.Resource(
|
||||||
|
contents=contents,
|
||||||
|
specification=referencing.jsonschema.DRAFT202012
|
||||||
|
)
|
||||||
|
return resource
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
# no doubt older versions would be fine for many of these but these were
|
# no doubt older versions would be fine for many of these but these were
|
||||||
# current at the time of writing
|
# current at the time of writing
|
||||||
|
|
||||||
# we need at least version 4.0.0 for support of JSON Schema Draft 2020-12.
|
# we need at least version 4.18.0 for support of referencing library.
|
||||||
jsonschema == 4.17.3
|
jsonschema >= 4.18.0
|
||||||
|
referencing >= 0.28.4
|
||||||
|
|
||||||
python-jsonpath == 0.9.0
|
python-jsonpath >= 1.0.0
|
||||||
attrs >= 23.1.0
|
attrs >= 23.1.0
|
||||||
PyYAML >= 3.12
|
PyYAML >= 3.12
|
||||||
requests >= 2.18.4
|
requests >= 2.18.4
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue