consumers: resolve the event schema on jsonschema before 4.18
ci/woodpecker/push/main Pipeline failed
ci/woodpecker/push/main Pipeline failed
This commit is contained in:
1 parent
4f3a9bff29
commit
33b73f41e3
1 file changed
+24
-3
@@ -10,7 +10,15 @@ import pathlib
|
|||||||
import sys
|
import sys
|
||||||
|
|
||||||
from jsonschema import Draft202012Validator
|
from jsonschema import Draft202012Validator
|
||||||
from referencing import Registry, Resource
|
|
||||||
|
try:
|
||||||
|
# jsonschema >= 4.18 resolves the external event schema through
|
||||||
|
# `referencing`. The CI image may ship an older jsonschema, so keep the
|
||||||
|
# standard resolver fallback: the public consumer must run on both.
|
||||||
|
from referencing import Registry, Resource
|
||||||
|
except ImportError: # pragma: no cover - exercised by the compatibility shim
|
||||||
|
Registry = None
|
||||||
|
Resource = None
|
||||||
|
|
||||||
ROOT = pathlib.Path(__file__).resolve().parents[2]
|
ROOT = pathlib.Path(__file__).resolve().parents[2]
|
||||||
SCHEMA_DIR = ROOT / "spec" / "schemas"
|
SCHEMA_DIR = ROOT / "spec" / "schemas"
|
||||||
@@ -23,10 +31,23 @@ def load_schema(name):
|
|||||||
return schema
|
return schema
|
||||||
|
|
||||||
|
|
||||||
|
EVENT_SCHEMA_ID = "https://marqdo.dev/schemas/observation-event.schema.json"
|
||||||
|
|
||||||
|
|
||||||
def validator(schema):
|
def validator(schema):
|
||||||
event = load_schema("observation-event.schema.json")
|
event = load_schema("observation-event.schema.json")
|
||||||
registry = Registry().with_resource(event["$id"], Resource.from_contents(event))
|
if Registry is not None:
|
||||||
return Draft202012Validator(schema, registry=registry)
|
registry = Registry().with_resource(EVENT_SCHEMA_ID, Resource.from_contents(event))
|
||||||
|
return Draft202012Validator(schema, registry=registry)
|
||||||
|
# jsonschema < 4.18 (Debian bookworm's python3-jsonschema).
|
||||||
|
from jsonschema import RefResolver
|
||||||
|
|
||||||
|
store = {
|
||||||
|
EVENT_SCHEMA_ID: event,
|
||||||
|
"observation-event.schema.json": event,
|
||||||
|
}
|
||||||
|
resolver = RefResolver.from_schema(schema, store=store)
|
||||||
|
return Draft202012Validator(schema, resolver=resolver)
|
||||||
|
|
||||||
|
|
||||||
def require_valid(schema_name, document, label):
|
def require_valid(schema_name, document, label):
|
||||||
|
|||||||
Reference in new issue
Block a user