# SPDX-License-Identifier: GPL-3.0-or-later """Regenerate ``json/observation.schema.json`` from the Pydantic source of truth. Idempotent. CI can gate on ``git diff --quiet json/observation.schema.json`` after running this — a non-empty diff means someone changed the model without regenerating the JSON Schema artifact. """ from __future__ import annotations import json import sys from pathlib import Path # Allow running this script directly without installing the package. _REPO_ROOT = Path(__file__).resolve().parent.parent if str(_REPO_ROOT) not in sys.path: sys.path.insert(0, str(_REPO_ROOT)) from behave_shell.spec.envelope import OBSERVATION_SCHEMA_VERSION, Observation # noqa: E402 def build_schema() -> dict: schema = Observation.model_json_schema() schema["$id"] = ( f"https://behave.local/schema/observation/v{OBSERVATION_SCHEMA_VERSION}.json" ) schema["$schema"] = "https://json-schema.org/draft/2020-12/schema" return schema def main() -> int: schema = build_schema() out = _REPO_ROOT / "json" / "observation.schema.json" out.parent.mkdir(parents=True, exist_ok=True) out.write_text(json.dumps(schema, indent=2, sort_keys=True) + "\n") print(f"wrote {out}") return 0 if __name__ == "__main__": raise SystemExit(main())