Skip to content

Export versioned artifact schemas as JSON Schema - #31

Merged
aminemanai2003 merged 4 commits into
mainfrom
feat/json-schema-export
Aug 15, 2026
Merged

Export versioned artifact schemas as JSON Schema#31
aminemanai2003 merged 4 commits into
mainfrom
feat/json-schema-export

Conversation

@trad024

@trad024 trad024 commented Aug 13, 2026

Copy link
Copy Markdown
Collaborator

Closes #14

What changed

Adds roadrisk schemas export --output schemas/ to write self-contained JSON Schema draft 2020-12 files for the public serialized artifacts.

Exported schemas

Artifact Source model
manifest.schema.json Manifest
timeline_record.schema.json TimelineRecord
risk_event.schema.json RiskEvent
trip_summary.schema.json TripSummary
calibration_profile.schema.json CalibrationProfile

The schemas have stable titles, deterministic key ordering, and the current model-declared schema_version. Timeline records are now serialized through TimelineRecord, keeping the generated schema faithful to the actual timeline.json artifact.

Validation

  • CI passes on Python 3.11, 3.12, and 3.13
  • Dependency audit passes
  • Representative artifact records validate against their Pydantic models and generated schemas
  • The timeline writer regression test verifies that serialized records include schema_version
  • No GPU, model weights, video, or network is required
  • docs/data-contract.md documents the export command and compatibility policy

Adds `roadrisk schemas export --output schemas/` which writes each
Pydantic artifact model (manifest, detection, risk_event, trip_summary,
calibration_profile) as a self-contained JSON Schema (draft 2020-12)
with deterministic key order, stable titles and a pinned schema_version
const.

Tests verify field presence, enum values, required/nullable rules,
coordinate conventions and output determinism.

Closes #14

@aminemanai2003 aminemanai2003 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a contract-correct revision before merge:

  1. CI fails in schema_export.py: ARTIFACT_SCHEMAS: dict[str, type] makes model a bare type, so mypy correctly reports that it has no model_json_schema. Type the mapping as Pydantic model classes (for example dict[str, type[BaseModel]]).
  2. Issue #14 explicitly requires a frame/timeline schema, but this PR omits it and exports an in-memory Detection schema instead. Add a serialized timeline-record model matching the actual timeline.json fields/semantics and export it. Do not describe an in-memory model as a public artifact unless an artifact actually uses it.
  3. export_schemas() injects a schema_version property into every generated dictionary. Detection has no such field and uses extra="forbid", so the exported schema says a field is allowed that the reference model rejects. Generated schemas must be faithful to the models/artifacts: put schema_version on the actual versioned serialized record model, not into an arbitrary JSON Schema after generation.

Please also add a test that validates representative real artifact records against each generated schema (including the timeline record), not only structural spot checks. The deterministic ordering, CLI shape, docs, and existing enum/nullability checks are otherwise good.

trad024 and others added 3 commits August 14, 2026 19:23
…ction

- Replace Detection with TimelineRecord in ARTIFACT_SCHEMAS (Detection is
  an in-memory model, not a serialized artifact)
- Tighten type annotation to dict[str, type[BaseModel]]
- Remove schema_version injection — only models that declare it natively
  include it in their JSON Schema
- Add representative artifact record validation tests
- Update data-contract.md to reflect timeline_record export

@aminemanai2003 aminemanai2003 left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The requested contract fixes are addressed. Timeline serialization now uses the versioned TimelineRecord model, the actual writer output is regression-tested, the branch is current with main, and all checks pass.

@aminemanai2003
aminemanai2003 merged commit db6d60c into main Aug 15, 2026
4 checks passed
@aminemanai2003
aminemanai2003 deleted the feat/json-schema-export branch August 15, 2026 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export versioned artifact schemas as JSON Schema

2 participants