From 8a2cc6c86ff282145b32aa977daed215179b4ce6 Mon Sep 17 00:00:00 2001 From: Lars Date: Tue, 2 Sep 2025 19:51:18 +0200 Subject: [PATCH] =?UTF-8?q?app/core/validate=5Fnote.py=20hinzugef=C3=BCgt?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/core/validate_note.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 app/core/validate_note.py diff --git a/app/core/validate_note.py b/app/core/validate_note.py new file mode 100644 index 0000000..1fa77a6 --- /dev/null +++ b/app/core/validate_note.py @@ -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 "" + msgs.append(f"{loc}: {e.message}") + raise ValidationError(" | ".join(msgs))