feat: deterministic JSON schema inference (genson wrapper)
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user