feat: deterministic JSON schema inference (genson wrapper)

This commit is contained in:
2026-05-31 23:57:47 +08:00
parent 7956b49e28
commit 5bc7e5b89d
3 changed files with 54 additions and 0 deletions
View File
+24
View File
@@ -0,0 +1,24 @@
from __future__ import annotations
from typing import Any
from genson import SchemaBuilder
class SchemaAccumulator:
"""Accumulate JSON samples into a widening JSON Schema (genson-backed)."""
def __init__(self) -> None:
self._builder = SchemaBuilder()
self._count = 0
def add(self, value: Any) -> None:
self._builder.add_object(value)
self._count += 1
def schema(self) -> dict[str, Any] | None:
if self._count == 0:
return None
result: dict[str, Any] = self._builder.to_schema()
result.pop("$schema", None)
return result