schema
blobmap.schema ¶
JSON Schema for the manifest, and a small validator that walks it.
The schema is the contract with every consumer, including ones not written yet. It is deliberately a plain dict rather than something generated from the dataclasses: the format has to outlive this package's class layout, and a consumer in another language needs the schema, not a Python model.
Validation walks the schema rather than reimplementing the rules, so the two
cannot drift. Only the keywords the schema actually uses are supported, which
is a fraction of the specification and about sixty lines. tests/test_schema.py
cross-checks the walker against the real jsonschema library, so if the schema
grows a keyword this does not handle, that test fails rather than the keyword
being silently ignored.
Example
validate_document({"schema_version": 3, "scope": "s", "epoch": 1, ... "hot_always": [], "blobs": []}) validate_document({"schema_version": 3, "scope": "s", "epoch": 0, ... "hot_always": [], "blobs": []}) Traceback (most recent call last): ... blobmap.schema.SchemaError: epoch: 0 is less than the minimum 1
SchemaError ¶
Bases: ValueError
A document does not match the manifest schema.
validate_document ¶
validate_document(document: Any) -> None
Check a parsed manifest against SCHEMA.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
document
|
Any
|
A parsed JSON document, before it becomes a
|
required |
Raises:
| Type | Description |
|---|---|
SchemaError
|
On the first violation, naming the path to it. |
Example
validate_document({"schema_version": 3, "scope": "s", "epoch": 1, ... "hot_always": [], ... "blobs": [{"id": "b!", "prefixes": ["x"], ... "bucket": None}]}) Traceback (most recent call last): ... blobmap.schema.SchemaError: blobs[0].id: 'b!' does not match ^[a-z0-9_]+$
Source code in src/blobmap/schema.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 | |