{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://textrefs.org/schemas/v1/textrefs.schema.json",
  "title": "TextRefs registry object",
  "description": "A single TextRefs registry record: a Work, a CitationSystem, a CanonicalReference, or a MappingAssertion. Generated from the Zod schemas at https://github.com/textrefs/textrefs.org/tree/main/standard/schema, which remain the implementation source of truth. A record served from /id/ also carries a JSON-LD \"@context\" member, and §15 of the specification allows further extension members; neither is declared here, and neither invalidates a record.",
  "oneOf": [
    {
      "$ref": "#/$defs/Work"
    },
    {
      "$ref": "#/$defs/CitationSystem"
    },
    {
      "$ref": "#/$defs/CanonicalReference"
    },
    {
      "$ref": "#/$defs/MappingAssertion"
    }
  ],
  "$defs": {
    "Work": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "draft",
            "active",
            "deprecated",
            "withdrawn",
            "blocked"
          ]
        },
        "created": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        "modified": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        "superseded_by": {
          "type": "string",
          "format": "iri"
        },
        "id": {
          "type": "string",
          "pattern": "^https:\\/\\/textrefs\\.org\\/id\\/work\\/[^/]+$"
        },
        "key": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]*$"
        },
        "type": {
          "type": "string",
          "const": "Work"
        },
        "preferred_label": {
          "type": "string",
          "minLength": 1
        },
        "alternative_labels": {
          "minItems": 1,
          "type": "array",
          "items": {
            "type": "string",
            "minLength": 1
          },
          "uniqueItems": true,
          "description": "Additional names for the work: abbreviations, translated titles, and established short forms. Each entry MUST be unique within the work, and no entry MUST repeat preferred_label (specification §6). The second rule compares two members and has no JSON Schema keyword; the compiler enforces it on every published record."
        },
        "preferred_citation_system_key": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]*$"
        },
        "creators": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "person"
                  },
                  "family": {
                    "type": "string",
                    "minLength": 1
                  },
                  "given": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "required": [
                  "kind",
                  "family"
                ]
              },
              {
                "type": "object",
                "properties": {
                  "kind": {
                    "type": "string",
                    "const": "literal"
                  },
                  "name": {
                    "type": "string",
                    "minLength": 1
                  }
                },
                "required": [
                  "kind",
                  "name"
                ]
              }
            ]
          }
        },
        "alternateOf": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "iri"
          }
        },
        "isReferencedBy": {
          "type": "array",
          "items": {
            "type": "string",
            "format": "iri"
          }
        }
      },
      "required": [
        "status",
        "created",
        "modified",
        "id",
        "key",
        "type",
        "preferred_label",
        "preferred_citation_system_key"
      ]
    },
    "CitationSystem": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "draft",
            "active",
            "deprecated",
            "withdrawn",
            "blocked"
          ]
        },
        "created": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        "modified": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        "superseded_by": {
          "type": "string",
          "format": "iri"
        },
        "id": {
          "type": "string",
          "pattern": "^https:\\/\\/textrefs\\.org\\/id\\/system\\/[^/]+$"
        },
        "key": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]*$"
        },
        "type": {
          "type": "string",
          "const": "CitationSystem"
        },
        "preferred_label": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string",
          "minLength": 1
        },
        "locator_regex": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "status",
        "created",
        "modified",
        "id",
        "key",
        "type",
        "preferred_label",
        "description",
        "locator_regex"
      ]
    },
    "CanonicalReference": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "draft",
            "active",
            "deprecated",
            "withdrawn",
            "blocked"
          ]
        },
        "created": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        "modified": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        "superseded_by": {
          "type": "string",
          "format": "iri"
        },
        "id": {
          "type": "string",
          "pattern": "^https:\\/\\/textrefs\\.org\\/id\\/ref\\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
        },
        "type": {
          "type": "string",
          "const": "CanonicalReference"
        },
        "work_key": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]*$"
        },
        "citation_system_key": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]*$"
        },
        "locator": {
          "type": "string",
          "minLength": 1
        },
        "resolver_targets": {
          "default": [],
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "url": {
                "type": "string",
                "format": "iri"
              },
              "language": {
                "type": "string",
                "pattern": "^(?:[A-Za-z]{2,3}(?:-[A-Za-z]{3}){0,3}|[A-Za-z]{4,8})(?:-[A-Za-z]{4})?(?:-(?:[A-Za-z]{2}|\\d{3}))?(?:-(?:[\\dA-Za-z]{5,8}|\\d[\\dA-Za-z]{3}))*(?:-[\\dA-WY-Za-wy-z](?:-[\\dA-Za-z]{2,8})+)*(?:-[Xx](?:-[\\dA-Za-z]{1,8})+)?$|^[Xx](?:-[\\dA-Za-z]{1,8})+$"
              },
              "edition": {
                "type": "string"
              },
              "provider": {
                "type": "string"
              },
              "access": {
                "type": "string",
                "enum": [
                  "open",
                  "paywalled",
                  "restricted",
                  "unknown"
                ]
              },
              "license": {
                "type": "string"
              },
              "license_url": {
                "anyOf": [
                  {
                    "type": "string",
                    "format": "iri"
                  },
                  {
                    "type": "null"
                  }
                ]
              },
              "last_checked": {
                "type": "string",
                "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
              }
            },
            "required": [
              "url",
              "access"
            ]
          }
        }
      },
      "required": [
        "status",
        "created",
        "modified",
        "id",
        "type",
        "work_key",
        "citation_system_key",
        "locator",
        "resolver_targets"
      ]
    },
    "MappingAssertion": {
      "type": "object",
      "properties": {
        "status": {
          "type": "string",
          "enum": [
            "draft",
            "active",
            "deprecated",
            "withdrawn",
            "blocked"
          ]
        },
        "created": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        "modified": {
          "type": "string",
          "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
        },
        "superseded_by": {
          "type": "string",
          "format": "iri"
        },
        "id": {
          "type": "string",
          "pattern": "^https:\\/\\/textrefs\\.org\\/id\\/mapping\\/[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$"
        },
        "type": {
          "type": "string",
          "const": "MappingAssertion"
        },
        "subject": {
          "type": "string",
          "pattern": "^https:\\/\\/textrefs\\.org\\/id\\/work\\/[a-z0-9][a-z0-9._-]*$"
        },
        "relation": {
          "type": "string",
          "enum": [
            "alternateOf",
            "isReferencedBy"
          ]
        },
        "target": {
          "type": "object",
          "properties": {
            "identifier": {
              "type": "string",
              "format": "iri"
            },
            "conforms_to": {
              "anyOf": [
                {
                  "type": "string",
                  "format": "iri"
                },
                {
                  "minItems": 1,
                  "type": "array",
                  "items": {
                    "type": "string",
                    "format": "iri"
                  }
                }
              ]
            }
          },
          "required": [
            "identifier"
          ]
        },
        "source": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "status",
        "created",
        "modified",
        "id",
        "type",
        "subject",
        "relation",
        "target",
        "source"
      ]
    }
  }
}
