Files
BEHAVE/BEHAVE-TEXT/scripts/generate_schema.py
anti bccd1eafd9 feat(text): initial decnet_behave_text spec + tests
Text/messaging-domain behavioral observation registry layered on core.
SPDX: GPL-3.0-or-later (code) / CC-BY-SA-4.0 (attribution-recipes.md).
2026-05-10 06:17:32 -04:00

43 lines
1.2 KiB
Python

# SPDX-License-Identifier: GPL-3.0-or-later
"""Regenerate BEHAVE-TEXT/json/observation.schema.json from the Pydantic source.
Idempotent — CI can gate on `git diff --quiet` after running this.
The artifact is functionally identical to BEHAVE-SHELL's (they share the same
core envelope), modulo the ``$id`` URL identifying the publishing package.
"""
from __future__ import annotations
import json
import sys
from pathlib import Path
_REPO_ROOT = Path(__file__).resolve().parent.parent
if str(_REPO_ROOT) not in sys.path:
sys.path.insert(0, str(_REPO_ROOT))
from decnet_behave_text.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/text/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())