Skip to content

Version the schema $id so it tracks the contract, not a branch - #19

Merged
AM-L merged 2 commits into
mainfrom
tooling/version-schema-id
Sep 7, 2026
Merged

AM-L merged 2 commits into
mainfrom
tooling/version-schema-id

Conversation

@ambroise-leclerc

Copy link
Copy Markdown
Contributor

Closes #6.

Each schema declared $id: https://github.com/Compliatory/MedUI/raw/main/schemas/<name>.json. A $id is an identity, so resolving it followed main as it moved — while everything else in the contract is pinned by SHA. Two consumers validating against "the" diagnostic schema could be validating different documents.

The $id now ends /schemas/<MAJOR.MINOR>/<name>.schema.json and is treated as a name, not a fetch target. governance/versioning.md records that the segment tracks the VERSION minor and moves only on a release that changes what validates; tools/validate.py checks every schema's $id against the VERSION minor.

Validation: python3 tools/validate.py → OK.

Stacked on #18.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new schema $id validation should read schema files with explicit UTF-8 encoding and fail with a clearer diagnostic instead of raising uncaught parse/key errors.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

This PR versions JSON Schema $id values by contract major.minor so schema identities don’t implicitly track a moving branch ref, aligning schema identification with the repository’s pin-by-SHA consumption model (closes #6).

Changes:

  • Updates each schema’s $id to end with /schemas/<MAJOR.MINOR>/<filename>.schema.json (e.g., .../schemas/0.2/...).
  • Documents the $id identity/versioning policy in governance/versioning.md.
  • Adds a validator check in tools/validate.py to enforce that all schema $id values embed the current VERSION major.minor.
File summaries
File Description
tools/validate.py Enforces schema $id major.minor alignment with VERSION.
schemas/diagnostic.schema.json Updates $id to the versioned identity form.
schemas/consumer-manifest.schema.json Updates $id to the versioned identity form.
schemas/case.schema.json Updates $id to the versioned identity form.
governance/versioning.md Specifies the schema $id identity policy and how it tracks releases.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 1
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tools/validate.py
Comment on lines +55 to +60
# Every schema's $id names the contract minor it belongs to (governance/versioning.md).
minor = ".".join(version.split(".")[:2])
for schema_path in sorted((ROOT / "schemas").glob("*.schema.json")):
schema_id = json.loads(schema_path.read_text())["$id"]
if not schema_id.endswith(f"/schemas/{minor}/{schema_path.name}"):
fail(f"{schema_path.name} $id does not carry the {minor} contract minor: {schema_id}")
@AM-L
AM-L force-pushed the tooling/version-schema-id branch from c3d5bfa to fa6e6ee Compare September 7, 2026 07:21
@ambroise-leclerc
ambroise-leclerc force-pushed the tooling/version-schema-id branch from fa6e6ee to e355eac Compare September 7, 2026 07:27
Base automatically changed from tooling/harden-validator to main September 7, 2026 07:32
Each schema declared $id: .../raw/main/schemas/<name>.json. A $id is an
identity, so resolving it followed main as it moved while everything else in
the contract is pinned by SHA - two consumers could validate against different
documents through the same identifier.

The $id now ends /schemas/<MAJOR.MINOR>/<name>.schema.json and is treated as a
name rather than a fetch target. governance/versioning.md records that the
segment tracks the VERSION minor and moves only on a release that changes what
validates. tools/validate.py checks every schema's $id against the VERSION
minor.
@AM-L
AM-L force-pushed the tooling/version-schema-id branch from e355eac to b612946 Compare September 7, 2026 07:32
Follow-up to review on PR #19. The schema $id check read each file with the
platform default encoding and did `json.loads(...)["$id"]` raw, so a malformed
schema or a missing $id raised a traceback instead of a validation failure.
It now goes through load_json (explicit UTF-8, JSONDecodeError reported) and
fails with a clear message when $id is absent or non-string.
@ambroise-leclerc

Copy link
Copy Markdown
Contributor Author

Addressed in 6d6b5e7: the $id check now reads each schema through load_json() (explicit UTF-8, JSONDecodeError reported as a validation failure — same helper the other schema reads use) and fails with "<file> has no string $id" when $id is absent or non-string, instead of a raw KeyError / JSONDecodeError traceback.

Verified: a schema with $id removed → MedUI validation: diagnostic.schema.json has no string $id; a malformed schema → MedUI validation: schemas/diagnostic.schema.json is not valid JSON: ....

@AM-L
AM-L merged commit 3cd74ca into main Sep 7, 2026
2 checks passed
@AM-L
AM-L deleted the tooling/version-schema-id branch September 7, 2026 08:17
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.

Schema $id resolves to a mutable ref, contradicting the pin-by-SHA policy

3 participants