{
  "openapi": "3.1.0",
  "info": {
    "title": "Random Hadith API",
    "description": "A free, read-only JSON API for authentic hadith from the six canonical Sunni collections (Kutub al-Sittah). No API key or authentication is required. Rate limit: 60 requests per 60-second window per IP.",
    "version": "1.0.0",
    "license": {
      "name": "CC BY-NC 4.0",
      "url": "https://randomhadith.com/licensing"
    },
    "contact": {
      "name": "Random Hadith",
      "url": "https://randomhadith.com/contact-us",
      "email": "contact@randomhadith.com"
    }
  },
  "servers": [{ "url": "https://randomhadith.com" }],
  "paths": {
    "/api": {
      "get": {
        "operationId": "getRandomHadith",
        "summary": "Get a complete random hadith",
        "description": "Returns a complete, randomly selected hadith.",
        "responses": {
          "200": {
            "description": "A complete hadith.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Hadith" }
              }
            }
          },
          "429": { "description": "Rate limit exceeded." }
        }
      }
    },
    "/api/random": {
      "get": {
        "operationId": "getRandomHadithId",
        "summary": "Get a random hadith ID",
        "description": "Returns only a random hadith ID; follow with /api/hadith?id= to load the full narration.",
        "responses": {
          "200": {
            "description": "A random hadith ID.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": { "id": { "type": "integer", "minimum": 1, "maximum": 34477 } },
                  "required": ["id"]
                }
              }
            }
          },
          "429": { "description": "Rate limit exceeded." }
        }
      }
    },
    "/api/hadith": {
      "get": {
        "operationId": "getHadithById",
        "summary": "Get a hadith by ID",
        "description": "Returns a specific hadith by its numeric ID (1–34477).",
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "description": "Numeric hadith ID, 1–34477.",
            "schema": { "type": "integer", "minimum": 1, "maximum": 34477 }
          }
        ],
        "responses": {
          "200": {
            "description": "The requested hadith.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Hadith" }
              }
            }
          },
          "400": { "description": "Missing, non-numeric, or out-of-range ID." },
          "404": { "description": "No hadith exists for the given ID." },
          "429": { "description": "Rate limit exceeded." }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Hadith": {
        "type": "object",
        "properties": {
          "id": { "type": "integer", "description": "Unique identifier used across the site and API." },
          "book": { "type": "string", "description": "Name of the source collection." },
          "chapter_no": { "type": "integer", "description": "Chapter number within the book." },
          "hadith_no": { "type": "string", "description": "Hadith number as referenced in the collection." },
          "chapter_name_en": { "type": "string", "description": "Chapter title in English." },
          "chapter_name_ar": { "type": "string", "description": "Chapter title in Arabic." },
          "text_ar": { "type": "string", "description": "Hadith text in Arabic." },
          "text_en": { "type": "string", "description": "Hadith text in English." },
          "text_ur": { "type": "string", "description": "Urdu text when available; may be empty." }
        },
        "required": ["id", "book", "chapter_no", "hadith_no", "text_ar", "text_en"]
      }
    }
  }
}
