Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@ Python 3.10 or newer is required.
## Validate MAP documents

```python
from mailschema import validate_map_document, validate_content_review_request
from mailschema import get_content_review_contract, validate_map_document, validate_content_review_request

validate_map_document(description)
validate_content_review_request(request)
contract = get_content_review_contract()
```

The CLI performs the same checks against local JSON files:
Expand All @@ -43,7 +44,7 @@ schema = get_contribution_schema()

`validate_record`, `record_errors` and `get_record_schema` handle expanded Registry records. Pass `--record` to the CLI for the corresponding record format.

The package bundles the MAP 0.1, Content Review 0.1 and Registry schemas. It uses the established `jsonschema` and `referencing` libraries for validation and performs no network requests.
The package bundles the MAP 0.1 and Registry schemas, the Content Review 0.1 request schema and its canonical type contract. It uses the established `jsonschema` and `referencing` libraries for validation and performs no network requests.

## Trust boundary

Expand Down
2 changes: 1 addition & 1 deletion UPSTREAM.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ Version `0.1.2` was prepared from [`mailschema/mailschema@eddc745`](https://gith

The included contribution schema has SHA-256 digest `a8a241b4837971a6251bcc135c704283536f4fb825fbbaedaf1598c6e688d564`. The canonical schemas live in the main MailSchema repository; this repository owns the Python package surface and its release history.

The unreleased MAP contract projection is derived from [`mailschema/mailschema@ab91b37`](https://github.com/mailschema/mailschema/commit/ab91b37d29dbf95a2e208a34a144bf5f7c26d0a6). Its MAP schema digest is `d908a960f53fade9ab47876bf69b1b3d037adeb7096091e22ca71fbc3909429c`; its Content Review schema digest is `dba2a2f1e57f843f43080f5a40ced2d9c84e7c7036ec306c371a82d39f6d6c9f`. These files are projections of that source commit and do not independently define MAP.
The unreleased MAP contract projection is derived from [`mailschema/mailschema@e2f2cc6`](https://github.com/mailschema/mailschema/commit/e2f2cc6983173e5aba1da27f1f8bff37336efd77). Its MAP schema digest is `c39befeecf8643e8beda1f53a8d1411482b68ddf14974f3806cfa95776103f85`; its Content Review schema digest is `10e2263c820ba3a6ef0381c377078e2c1f324c3b142a6f8caf92b298cc66c692`; and its Content Review contract byte digest is `754ab7245ddb09ff4da000fccc60d746724379d4146ea227973e5d87f105f800`. These files are exact projections of that source commit and do not independently define MAP.
5 changes: 5 additions & 0 deletions src/mailschema/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def get_content_review_schema() -> dict[str, Any]:
return _bundled("content-review-0.1.schema.json")


def get_content_review_contract() -> dict[str, Any]:
"""Return a fresh copy of the canonical Content Review 0.1 type contract."""
return _bundled("content-review-0.1.contract.json")


def get_record_schema() -> dict[str, Any]:
"""Return the schema for expanded Registry records."""
schema = get_contribution_schema()
Expand Down
58 changes: 58 additions & 0 deletions src/mailschema/content-review-0.1.contract.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"kind": "MapTypeContract",
"id": "https://mailschema.org/types/content-review",
"version": "0.1",
"profile": "https://mailschema.org/profiles/map/0.1",
"target": "Service-owned content at the exact revision and digest named in the request.",
"requestSchema": {
"url": "https://mailschema.org/schemas/content-review-0.1.schema.json",
"canonicalDigest": "sha-256:cdad1149ab193d1bf71cb9463e3c4b7331ed56b0123e225adf68f70a2022b29d"
},
"operations": [
{
"id": "request-changes",
"effect": "Record review feedback on the named revision.",
"results": [
{
"state": "accepted",
"outputSchema": {
"type": "object",
"additionalProperties": false,
"properties": {
"feedbackRecorded": { "const": true }
},
"required": ["feedbackRecorded"]
}
}
]
},
{
"id": "approve",
"effect": "Record approval of the named revision.",
"results": [
{
"state": "approval-required",
"outputSchema": {
"type": "object",
"additionalProperties": false,
"properties": {
"approvalUrl": { "type": "string", "format": "uri", "pattern": "^https://" }
},
"required": ["approvalUrl"]
}
},
{
"state": "completed",
"outputSchema": {
"type": "object",
"additionalProperties": false,
"properties": {
"decision": { "const": "approved" }
},
"required": ["decision"]
}
}
]
}
]
}
7 changes: 2 additions & 5 deletions src/mailschema/content-review-0.1.schema.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://mailschema.org/schemas/content-review-0.1.schema.json",
"title": "Content Review 0.1 MAP request",
"title": "Content Review 0.1 MAP request binding",
"allOf": [
{ "$ref": "https://mailschema.org/schemas/map-0.1.schema.json#/$defs/request" },
{
Expand All @@ -11,10 +11,7 @@
"type": "object",
"properties": {
"id": { "const": "https://mailschema.org/types/content-review" },
"version": { "const": "0.1" },
"recordDigest": {
"const": "sha-256:0e6365df1bf904f2475f972ec66a5561edc0bfaae69fd7a1b41f53b40bf8ac1c"
}
"version": { "const": "0.1" }
}
}
}
Expand Down
142 changes: 109 additions & 33 deletions src/mailschema/map-0.1.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"type": "string",
"pattern": "^sha-256:[a-f0-9]{64}$"
},
"recordDigest": {
"contractDigest": {
"type": "string",
"pattern": "^sha-256:[a-f0-9]{64}$"
},
Expand All @@ -46,9 +46,9 @@
"pattern": "^[0-9]+\\.[0-9]+(?:\\.[0-9]+)?(?:-[a-zA-Z0-9.-]+)?$",
"maxLength": 80
},
"recordDigest": { "$ref": "#/$defs/recordDigest" }
"contractDigest": { "$ref": "#/$defs/contractDigest" }
},
"required": ["id", "version", "recordDigest"]
"required": ["id", "version", "contractDigest"]
},
"target": {
"type": "object",
Expand Down Expand Up @@ -172,7 +172,6 @@
"profile": { "$ref": "#/$defs/profile" },
"requestId": { "$ref": "#/$defs/uuidUrn" },
"interactionId": { "$ref": "#/$defs/uuidUrn" },
"requestedAt": { "type": "string", "format": "date-time" },
"type": { "$ref": "#/$defs/typeReference" },
"operation": {
"type": "string",
Expand All @@ -187,7 +186,6 @@
"profile",
"requestId",
"interactionId",
"requestedAt",
"type",
"operation",
"target",
Expand Down Expand Up @@ -273,61 +271,139 @@
},
"target": { "$ref": "#/$defs/target" }
},
"required": [
"type",
"title",
"status",
"detail",
"instance",
"profile",
"requestId",
"interactionId",
"code"
],
"required": ["type", "title", "status", "detail"],
"dependentRequired": {
"instance": ["profile", "requestId", "code"],
"profile": ["instance", "requestId", "code"],
"requestId": ["instance", "profile", "code"],
"interactionId": ["instance", "profile", "requestId", "code"],
"code": ["instance", "profile", "requestId"]
},
"allOf": [
{
"if": {
"properties": { "code": { "not": { "const": "result-not-found" } } },
"required": ["code"]
},
"then": { "required": ["interactionId"] }
},
{
"if": { "properties": { "code": { "const": "invalid-request" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/invalid-request" }, "status": { "const": 400 } } }
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/invalid-request" },
"status": { "const": 400 }
}
}
},
{
"if": { "properties": { "code": { "const": "authentication-required" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/authentication-required" }, "status": { "const": 401 } } }
"if": {
"properties": { "code": { "const": "authentication-required" } },
"required": ["code"]
},
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/authentication-required" },
"status": { "const": 401 }
}
}
},
{
"if": { "properties": { "code": { "const": "refused" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/refused" }, "status": { "const": 403 } } }
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/refused" },
"status": { "const": 403 }
}
}
},
{
"if": { "properties": { "code": { "const": "result-not-found" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/result-not-found" }, "status": { "const": 404 } } }
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/result-not-found" },
"status": { "const": 404 }
}
}
},
{
"if": { "properties": { "code": { "const": "stale-target" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/stale-target" }, "status": { "const": 409 } }, "required": ["target"] }
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/stale-target" },
"status": { "const": 409 }
},
"required": ["target"]
}
},
{
"if": { "properties": { "code": { "const": "idempotency-conflict" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/idempotency-conflict" }, "status": { "const": 409 } } }
"if": {
"properties": { "code": { "const": "idempotency-conflict" } },
"required": ["code"]
},
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/idempotency-conflict" },
"status": { "const": 409 }
}
}
},
{
"if": { "properties": { "code": { "const": "request-in-progress" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/request-in-progress" }, "status": { "const": 409 } } }
"if": {
"properties": { "code": { "const": "request-in-progress" } },
"required": ["code"]
},
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/request-in-progress" },
"status": { "const": 409 }
}
}
},
{
"if": { "properties": { "code": { "const": "expired-interaction" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/expired-interaction" }, "status": { "const": 410 } } }
"if": {
"properties": { "code": { "const": "expired-interaction" } },
"required": ["code"]
},
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/expired-interaction" },
"status": { "const": 410 }
}
}
},
{
"if": { "properties": { "code": { "const": "unsupported-profile" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/unsupported-profile" }, "status": { "const": 422 } } }
"if": {
"properties": { "code": { "const": "unsupported-profile" } },
"required": ["code"]
},
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/unsupported-profile" },
"status": { "const": 422 }
}
}
},
{
"if": { "properties": { "code": { "const": "unsupported-type" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/unsupported-type" }, "status": { "const": 422 } } }
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/unsupported-type" },
"status": { "const": 422 }
}
}
},
{
"if": { "properties": { "code": { "const": "unsupported-operation" } }, "required": ["code"] },
"then": { "properties": { "type": { "const": "https://mailschema.org/problems/unsupported-operation" }, "status": { "const": 422 } } }
"if": {
"properties": { "code": { "const": "unsupported-operation" } },
"required": ["code"]
},
"then": {
"properties": {
"type": { "const": "https://mailschema.org/problems/unsupported-operation" },
"status": { "const": 422 }
}
}
}
]
}
Expand Down
5 changes: 5 additions & 0 deletions tests/content-review.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
"exception": "An approval request for revision 3 is refused once that revision is stale. Approval of revision 4 does not send the campaign."
},
"references": [
{
"title": "Content Review 0.1 contract",
"href": "https://mailschema.org/contracts/content-review-0.1.json",
"description": "Normative canonical type contract used by MAP wire messages."
},
{
"title": "Schema.org Actions",
"href": "https://schema.org/docs/actions.html",
Expand Down
2 changes: 1 addition & 1 deletion tests/map-description.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": {
"id": "https://mailschema.org/types/content-review",
"version": "0.1",
"recordDigest": "sha-256:0e6365df1bf904f2475f972ec66a5561edc0bfaae69fd7a1b41f53b40bf8ac1c"
"contractDigest": "sha-256:deba8fc588c83c7cdf9d4e47d23b114861aea35c3daaf71854dc6c626c8a1d05"
},
"describedAt": "2026-09-23T01:00:00Z",
"expiresAt": "2026-09-30T01:00:00Z",
Expand Down
3 changes: 1 addition & 2 deletions tests/map-request.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@
"profile": "https://mailschema.org/profiles/map/0.1",
"requestId": "urn:uuid:018f47a2-b4d3-7c02-b491-7bdf2eaac67c",
"interactionId": "urn:uuid:018f47a2-5d7c-7b11-9a3d-4d2160b85b10",
"requestedAt": "2026-09-23T01:06:00Z",
"type": {
"id": "https://mailschema.org/types/content-review",
"version": "0.1",
"recordDigest": "sha-256:0e6365df1bf904f2475f972ec66a5561edc0bfaae69fd7a1b41f53b40bf8ac1c"
"contractDigest": "sha-256:deba8fc588c83c7cdf9d4e47d23b114861aea35c3daaf71854dc6c626c8a1d05"
},
"operation": "approve",
"target": {
Expand Down
2 changes: 1 addition & 1 deletion tests/map-result.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": {
"id": "https://mailschema.org/types/content-review",
"version": "0.1",
"recordDigest": "sha-256:0e6365df1bf904f2475f972ec66a5561edc0bfaae69fd7a1b41f53b40bf8ac1c"
"contractDigest": "sha-256:deba8fc588c83c7cdf9d4e47d23b114861aea35c3daaf71854dc6c626c8a1d05"
},
"operation": "approve",
"state": "completed",
Expand Down
2 changes: 2 additions & 0 deletions tests/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from mailschema import (
contribution_errors,
get_contribution_schema,
get_content_review_contract,
get_record_schema,
get_map_schema,
validate_contribution,
Expand Down Expand Up @@ -44,6 +45,7 @@ def test_schema_copies_and_record_reference(self):
self.assertNotEqual(get_contribution_schema()["title"], "mutated")
self.assertEqual(get_record_schema()["$ref"], "#/$defs/record")
self.assertEqual(get_map_schema()["$id"], "https://mailschema.org/schemas/map-0.1.schema.json")
self.assertEqual(get_content_review_contract()["id"], "https://mailschema.org/types/content-review")

def test_map_documents(self):
validate_map_document(self.description)
Expand Down
Loading