{
  "openapi": "3.1.0",
  "info": {
    "title": "Tabseer public read API",
    "version": "1.0.0",
    "description": "Anonymous read access. Records may contain optional source-dependent fields. Honor response cache headers."
  },
  "servers": [
    {
      "url": "/"
    }
  ],
  "paths": {
    "/api/collections": {
      "get": {
        "operationId": "listCollections",
        "summary": "Collections and exact chapter titles",
        "parameters": [],
        "responses": {
          "200": {
            "description": "data is an array of collection objects with chapters",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Invalid or out-of-range parameters"
          },
          "404": {
            "description": "Record or chapter page not found"
          },
          "422": {
            "description": "Invalid collection or hadith identifier"
          },
          "500": {
            "description": "Temporary server error; retry with backoff"
          }
        }
      }
    },
    "/api/hadith/{collection}/{number}": {
      "get": {
        "operationId": "getHadith",
        "summary": "Retrieve one Hadith",
        "parameters": [
          {
            "name": "collection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "bukhari",
                "muslim",
                "abudawud",
                "tirmidhi",
                "nasai",
                "ibnmajah"
              ]
            }
          },
          {
            "name": "number",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "status, message, and data (the Hadith record)",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Invalid or out-of-range parameters"
          },
          "404": {
            "description": "Record or chapter page not found"
          },
          "422": {
            "description": "Invalid collection or hadith identifier"
          },
          "500": {
            "description": "Temporary server error; retry with backoff"
          }
        }
      }
    },
    "/api/hadith/{collection}/{number}/takhrij": {
      "get": {
        "operationId": "getTakhrij",
        "summary": "Transmission tree and related reports",
        "parameters": [
          {
            "name": "collection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "bukhari",
                "muslim",
                "abudawud",
                "tirmidhi",
                "nasai",
                "ibnmajah"
              ]
            }
          },
          {
            "name": "number",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1
            }
          }
        ],
        "responses": {
          "200": {
            "description": "status, data (tree), cached (precomputed shard availability, not HTTP cache status)",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Invalid or out-of-range parameters"
          },
          "404": {
            "description": "Record or chapter page not found"
          },
          "422": {
            "description": "Invalid collection or hadith identifier"
          },
          "500": {
            "description": "Temporary server error; retry with backoff"
          }
        }
      }
    },
    "/api/chapter": {
      "get": {
        "operationId": "getChapter",
        "summary": "Read a chapter with cursor pagination",
        "parameters": [
          {
            "name": "book",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "enum": [
                "bukhari",
                "muslim",
                "abudawud",
                "tirmidhi",
                "nasai",
                "ibnmajah"
              ]
            }
          },
          {
            "name": "title",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 500
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "lastHadithNumber",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 0,
              "minimum": 0,
              "maximum": 9007199254740991
            }
          },
          {
            "name": "view",
            "in": "query",
            "required": false,
            "description": "Use card for the smaller reader payload; full preserves the original API response.",
            "schema": {
              "type": "string",
              "enum": [
                "full",
                "card"
              ],
              "default": "full"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "status, message, data (Hadith array). Set cursor to the last hadith_number. An empty page returns 404.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Invalid or out-of-range parameters"
          },
          "404": {
            "description": "Record or chapter page not found"
          },
          "422": {
            "description": "Invalid collection or hadith identifier"
          },
          "500": {
            "description": "Temporary server error; retry with backoff"
          }
        }
      }
    },
    "/api/search": {
      "get": {
        "operationId": "searchHadiths",
        "summary": "Search Arabic or English Hadith texts",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          },
          {
            "name": "mode",
            "in": "query",
            "description": "all returns every matching narration; meaning groups text matches using direct takhrij links.",
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "meaning"
              ],
              "default": "all"
            }
          },
          {
            "name": "sixOnly",
            "in": "query",
            "description": "Restrict matching narrations to the six canonical books. Expanded takhrij references always include every collection.",
            "schema": {
              "type": "string",
              "enum": [
                "0",
                "1"
              ],
              "default": "0"
            }
          },
          {
            "name": "collection",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 100,
              "description": "Comma-separated collection IDs or all; collections is also accepted as an alias"
            }
          },
          {
            "name": "narrator",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          },
          {
            "name": "skip",
            "in": "query",
            "required": false,
            "description": "Number of displayed results to skip; counts groups in meaning mode.",
            "schema": {
              "type": "integer",
              "default": 0,
              "minimum": 0
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 20,
              "minimum": 1,
              "maximum": 100
            }
          }
        ],
        "responses": {
          "200": {
            "description": "data contains narration summaries (with groupKey in meaning mode); hasMore and nextSkip describe pagination.",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Invalid or out-of-range parameters"
          },
          "404": {
            "description": "Record or chapter page not found"
          },
          "422": {
            "description": "Invalid collection or hadith identifier"
          },
          "500": {
            "description": "Temporary server error; retry with backoff"
          },
          "503": {
            "description": "Search or takhrij data is temporarily unavailable; retry."
          }
        }
      }
    },
    "/api/narrators": {
      "get": {
        "operationId": "listNarrators",
        "summary": "Search and browse narrators",
        "parameters": [
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1,
              "maximum": 5000
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 24,
              "minimum": 1,
              "maximum": 100
            }
          },
          {
            "name": "collection",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "bukhari",
                "muslim",
                "abudawud",
                "tirmidhi",
                "nasai",
                "ibnmajah"
              ]
            }
          },
          {
            "name": "generation",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "sahaba",
                "kibar_tabiin",
                "tabiin",
                "atba_tabiin",
                "later"
              ]
            }
          },
          {
            "name": "grade",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "thiqah",
                "sahabi",
                "saduq",
                "daif"
              ]
            }
          },
          {
            "name": "has_appraisals",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            }
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "hadiths",
                "death_asc",
                "death_desc",
                "name_asc",
                "arabic_asc"
              ]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "status, data.narrators, data.pagination (page, limit, total, totalPages)",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Invalid or out-of-range parameters"
          },
          "404": {
            "description": "Record or chapter page not found"
          },
          "422": {
            "description": "Invalid collection or hadith identifier"
          },
          "500": {
            "description": "Temporary server error; retry with backoff"
          }
        }
      }
    },
    "/api/narrator/{id}": {
      "get": {
        "operationId": "getNarrator",
        "summary": "Profile, relationships, and paginated Hadiths",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 1,
              "minimum": 1,
              "maximum": 200
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 10,
              "minimum": 1,
              "maximum": 50
            }
          },
          {
            "name": "book",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "all",
                "bukhari",
                "muslim",
                "abudawud",
                "tirmidhi",
                "nasai",
                "ibnmajah"
              ]
            }
          },
          {
            "name": "search",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "maxLength": 200
            }
          }
        ],
        "responses": {
          "200": {
            "description": "status, data.narrator, data.teachers, data.students, data.stats, data.hadiths, data.pagination",
            "headers": {
              "Cache-Control": {
                "schema": {
                  "type": "string"
                }
              }
            },
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "additionalProperties": true
                }
              }
            }
          },
          "400": {
            "description": "Invalid or out-of-range parameters"
          },
          "404": {
            "description": "Record or chapter page not found"
          },
          "422": {
            "description": "Invalid collection or hadith identifier"
          },
          "500": {
            "description": "Temporary server error; retry with backoff"
          }
        }
      }
    },
    "/api/hadith/{collection}/{number}/takhrij/references": {
      "get": {
        "operationId": "getTakhrijReferences",
        "summary": "All direct takhrij references across every collection, without the tree display limit",
        "parameters": [
          {
            "name": "collection",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Any available collection ID"
          },
          {
            "name": "number",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "data is the complete list of references: label, optional href, external, and takhrijHref. References without verified destinations are citations."
          },
          "400": {
            "description": "Invalid hadith reference"
          },
          "404": {
            "description": "Hadith not found"
          },
          "503": {
            "description": "Takhrij data unavailable; retry"
          }
        }
      }
    }
  }
}
