This commit is contained in:
1 parent
b076cabae7
commit
8a2cc6c86f
1 file changed
+16
@@ -0,0 +1,16 @@
|
|||||||
|
from __future__ import annotations
|
||||||
|
from typing import Dict
|
||||||
|
from jsonschema import ValidationError
|
||||||
|
from .schema_loader import get_validator
|
||||||
|
|
||||||
|
NOTE_SCHEMA_NAME = "note.schema.json"
|
||||||
|
|
||||||
|
def validate_note_payload(payload: Dict) -> None:
|
||||||
|
validator = get_validator(NOTE_SCHEMA_NAME)
|
||||||
|
errors = sorted(validator.iter_errors(payload), key=lambda e: e.path)
|
||||||
|
if errors:
|
||||||
|
msgs = []
|
||||||
|
for e in errors:
|
||||||
|
loc = ".".join([str(x) for x in e.path]) or "<root>"
|
||||||
|
msgs.append(f"{loc}: {e.message}")
|
||||||
|
raise ValidationError(" | ".join(msgs))
|
||||||
Reference in new issue
Block a user