File size: 1,192 Bytes
c4e128a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | """Schema validator for DocumentMeta objects."""
from __future__ import annotations
from app.models.document import DocumentMeta, ValidationResult
class SchemaValidator:
"""Validates DocumentMeta structural integrity and mandatory attributes."""
def validate(self, meta: DocumentMeta) -> ValidationResult:
errors: list[str] = []
warnings: list[str] = []
if meta.pages < 1:
errors.append(f"Invalid page count: {meta.pages}")
if meta.file_size_bytes <= 0:
errors.append(f"Invalid file size: {meta.file_size_bytes} bytes")
if not meta.filename.endswith(".pdf"):
errors.append(f"Filename does not end with .pdf: {meta.filename}")
if meta.sha256 and len(meta.sha256) != 64:
errors.append("sha256 hash must be 64 hexadecimal characters")
if meta.language == "unknown":
warnings.append("Document language is unknown")
if meta.category == "other":
warnings.append("Document category is generic 'other'")
return ValidationResult(
is_valid=len(errors) == 0,
errors=errors,
warnings=warnings,
)
|