{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://schemas.metanorma.org/registry/documents-index/v1.json",
  "title": "Registry catalog (documents index)",
  "description": "Contract for the aggregated registry catalog. The Relaton record carried in each item's `bibliographic` field is the canonical source of truth; every other field is a projection generated by the producer and verified by `rake validate_consistency`. Projection rules: `id` = primary `bibliographic.docidentifier[].content`; `title` = main `bibliographic.title[].content` (stripped); `abstract` = first `bibliographic.abstract[].content` else null; `doctype` = `bibliographic.ext.doctype.content`; `stage` = `bibliographic.status.stage.content` downcased, falling back to the release stage, then 'published'; `date` = `bibliographic.date[type=published].at` date part, falling back to the release date; `language`/`copyright`/`authors`/`committee` map from the Relaton arrays; `edition` from the release metadata. Stability promise: within schema major version 1, changes are additive only; consumers must ignore unknown keys. The `metanorma-release` gem is one conforming producer — any generator that emits a payload valid against this schema is valid.",
  "type": "object",
  "required": [
    "$schema",
    "version",
    "generated_at",
    "org",
    "items"
  ],
  "properties": {
    "$schema": {
      "const": "https://schemas.metanorma.org/registry/documents-index/v1.json"
    },
    "version": {
      "const": 1
    },
    "generated_at": {
      "type": "string",
      "format": "date-time"
    },
    "org": {
      "type": "string",
      "description": "Instance organization identity (e.g. 'calconnect')"
    },
    "urn_namespace": {
      "type": "string"
    },
    "url_scheme": {
      "type": "string",
      "description": "Template for canonical document URLs; tokens: :document_id, :year, :edition"
    },
    "generator": {
      "type": "string"
    },
    "links": {
      "type": "object",
      "properties": {
        "search": {
          "type": "string",
          "pattern": "^/"
        },
        "feed": {
          "type": "string",
          "pattern": "^/"
        },
        "opensearch": {
          "type": "string",
          "pattern": "^/"
        },
        "catalog": {
          "type": "string",
          "pattern": "^/"
        }
      }
    },
    "items": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/document"
      }
    }
  },
  "$defs": {
    "document": {
      "type": "object",
      "required": [
        "slug",
        "document_id",
        "id",
        "title",
        "stage",
        "doctype",
        "edition",
        "date",
        "abstract",
        "language",
        "license",
        "copyright",
        "authors",
        "committee",
        "channels",
        "urn",
        "url",
        "latest_url",
        "files",
        "bibliographic",
        "provenance",
        "editions",
        "stage_css",
        "doctype_class",
        "display_category_slug"
      ],
      "properties": {
        "slug": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]*$",
          "description": "Per-version slug derived from the document identifier"
        },
        "document_id": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9._-]*$",
          "description": "Stable per-document identity shared by all editions"
        },
        "id": {
          "type": "string",
          "minLength": 1,
          "description": "Display identifier (projection of the primary Relaton docidentifier)"
        },
        "title": {
          "type": "string"
        },
        "abstract": {
          "type": [
            "string",
            "null"
          ]
        },
        "doctype": {
          "type": [
            "string",
            "null"
          ],
          "description": "Document type slug; instance display categories map over this"
        },
        "stage": {
          "type": "string",
          "description": "Lifecycle stage (downcased)"
        },
        "edition": {
          "type": [
            "string",
            "null"
          ]
        },
        "date": {
          "type": [
            "string",
            "null"
          ],
          "format": "date"
        },
        "year": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^\\d{4}$"
        },
        "language": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "string",
            "pattern": "^[a-zA-Z]{2,3}(-[a-zA-Z0-9-]+)?$"
          },
          "description": "BCP 47 language tags from Relaton"
        },
        "license": {
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "object",
              "description": "null when neither Relaton nor the instance default provides one — tracked in the backfill report, never invented",
              "properties": {
                "name": {
                  "type": "string"
                },
                "url": {
                  "type": "string",
                  "format": "uri"
                },
                "spdx": {
                  "type": "string"
                }
              }
            }
          ]
        },
        "copyright": {
          "oneOf": [
            {
              "type": "null"
            },
            {
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "from": {
                    "type": [
                      "string",
                      "integer"
                    ]
                  },
                  "to": {
                    "type": [
                      "string",
                      "integer",
                      "null"
                    ]
                  },
                  "owner": {
                    "type": "string"
                  }
                }
              }
            }
          ]
        },
        "authors": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "object",
            "properties": {
              "name": {
                "type": "string"
              },
              "role": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        },
        "committee": {
          "type": [
            "string",
            "null"
          ]
        },
        "channels": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "urn": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^urn:[a-z0-9][a-z0-9-]*:[^:]+:.+$",
          "description": "urn:<namespace>:<document_id>:<year|edition>"
        },
        "url": {
          "type": "string",
          "pattern": "^/",
          "description": "Canonical versioned landing URL"
        },
        "latest_url": {
          "type": "string",
          "pattern": "^/",
          "description": "Stable 'latest edition' alias URL"
        },
        "stage_css": {
          "type": "string",
          "description": "Rendering projection: stage as a CSS-safe slug"
        },
        "doctype_class": {
          "type": "string",
          "description": "Rendering projection: CSS class for the doctype"
        },
        "display_category": {
          "type": [
            "string",
            "null"
          ],
          "description": "Instance-config projection"
        },
        "display_category_slug": {
          "type": [
            "string",
            "null"
          ]
        },
        "relaton_schema_version": {
          "type": [
            "string",
            "null"
          ],
          "description": "Relaton dialect of `bibliographic`"
        },
        "files": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/file"
          },
          "description": "The single representation of the item's artifacts; `format` values are unique across the array"
        },
        "bibliographic": {
          "type": [
            "object",
            "null"
          ],
          "description": "Canonical Relaton record"
        },
        "provenance": {
          "$ref": "#/$defs/provenance"
        },
        "editions": {
          "type": "array",
          "minItems": 1,
          "items": {
            "$ref": "#/$defs/edition"
          },
          "description": "All known editions of this document; exactly one carries current: true"
        },
        "relations": {
          "type": [
            "array",
            "null"
          ],
          "description": "Bibliographic relations projected from Relaton (e.g. updatedBy, derivedFrom); target resolution is the renderer's job",
          "items": {
            "type": "object",
            "required": [
              "type",
              "id"
            ],
            "properties": {
              "type": {
                "type": "string"
              },
              "id": {
                "type": "string",
                "description": "Target document identifier as published"
              },
              "date": {
                "type": [
                  "string",
                  "null"
                ],
                "format": "date"
              },
              "edition": {
                "type": [
                  "string",
                  "null"
                ]
              }
            }
          }
        },
        "keywords": {
          "type": [
            "array",
            "null"
          ],
          "items": {
            "type": "string"
          },
          "description": "Subject keywords projected from Relaton"
        }
      }
    },
    "file": {
      "type": "object",
      "required": [
        "format",
        "media_type",
        "bytes",
        "sha256",
        "url"
      ],
      "properties": {
        "format": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9.-]*$"
        },
        "name": {
          "type": "string",
          "description": "Basename of the artifact"
        },
        "media_type": {
          "type": "string",
          "pattern": "^[a-z0-9][a-z0-9!#$&^_.+-]*/[a-z0-9][a-z0-9!#$&^_.+-]*$"
        },
        "bytes": {
          "type": "integer",
          "minimum": 0
        },
        "sha256": {
          "type": "string",
          "pattern": "^[a-f0-9]{64}$"
        },
        "url": {
          "type": "string",
          "pattern": "^/",
          "description": "Published URL of the artifact (site-absolute)"
        }
      }
    },
    "provenance": {
      "type": "object",
      "required": [
        "source",
        "generator"
      ],
      "properties": {
        "source": {
          "enum": [
            "release",
            "collection",
            "local"
          ]
        },
        "source_repository": {
          "type": "string",
          "pattern": "^[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+$"
        },
        "release_tag": {
          "type": "string"
        },
        "release_url": {
          "type": "string",
          "format": "uri"
        },
        "release_date": {
          "type": [
            "string",
            "null"
          ]
        },
        "built_at": {
          "type": "string",
          "format": "date-time"
        },
        "generator": {
          "type": "string"
        }
      }
    },
    "edition": {
      "type": "object",
      "required": [
        "edition",
        "date",
        "year",
        "stage",
        "slug",
        "url",
        "current"
      ],
      "properties": {
        "edition": {
          "type": [
            "string",
            "null"
          ]
        },
        "date": {
          "type": [
            "string",
            "null"
          ]
        },
        "year": {
          "type": [
            "string",
            "null"
          ]
        },
        "stage": {
          "type": "string"
        },
        "slug": {
          "type": "string"
        },
        "url": {
          "type": [
            "string",
            "null"
          ],
          "pattern": "^/"
        },
        "current": {
          "type": "boolean"
        }
      }
    }
  }
}
