{
  "openapi": "3.0.3",
  "info": {
    "title": "Recipe Box API",
    "version": "1.0.0",
    "description": "Read-only REST API over a catalog of 100 sample recipes.\n\nAll responses are JSON and CORS-enabled (`Access-Control-Allow-Origin: *`), so the API can be called directly from the browser. Data is served live from a SQLite database.",
    "contact": { "name": "Recipe Box" }
  },
  "servers": [
    { "url": "https://178.105.233.80.nip.io", "description": "Production" }
  ],
  "tags": [
    { "name": "Recipes", "description": "Browse and fetch recipes" },
    { "name": "Metadata", "description": "Filter facets" }
  ],
  "paths": {
    "/api/recipes": {
      "get": {
        "tags": ["Recipes"],
        "summary": "List recipes",
        "description": "Returns a paginated list of recipes. All query parameters are optional and combine with AND semantics.",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "description": "Case-insensitive substring match on the recipe name.",
            "schema": { "type": "string" },
            "example": "Beef"
          },
          {
            "name": "cuisine",
            "in": "query",
            "description": "Exact cuisine match (see /api/facets for valid values).",
            "schema": { "type": "string" },
            "example": "Italian"
          },
          {
            "name": "category",
            "in": "query",
            "description": "Exact category match (see /api/facets for valid values).",
            "schema": { "type": "string" },
            "example": "Main"
          },
          {
            "name": "vegetarian",
            "in": "query",
            "description": "When `true` (or `1`), returns only vegetarian recipes.",
            "schema": { "type": "string", "enum": ["true", "1"] }
          },
          {
            "name": "limit",
            "in": "query",
            "description": "Maximum number of recipes to return (1-100). Defaults to all matches.",
            "schema": { "type": "integer", "minimum": 1, "maximum": 100 },
            "example": 20
          },
          {
            "name": "offset",
            "in": "query",
            "description": "Number of recipes to skip, for pagination.",
            "schema": { "type": "integer", "minimum": 0, "default": 0 }
          }
        ],
        "responses": {
          "200": {
            "description": "A page of recipes.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/RecipeList" }
              }
            }
          }
        }
      }
    },
    "/api/recipes/random": {
      "get": {
        "tags": ["Recipes"],
        "summary": "Get a random recipe",
        "description": "Returns one randomly selected recipe, including its ingredients. Never cached.",
        "responses": {
          "200": {
            "description": "A random recipe with ingredients.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/RecipeDetail" }
              }
            }
          },
          "404": {
            "description": "No recipes available.",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/Error" } }
            }
          }
        }
      }
    },
    "/api/recipes/{id}": {
      "get": {
        "tags": ["Recipes"],
        "summary": "Get a recipe by id",
        "description": "Returns a single recipe and its full ingredient list.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "description": "Recipe id (1-100).",
            "schema": { "type": "integer", "minimum": 1 },
            "example": 84
          }
        ],
        "responses": {
          "200": {
            "description": "The requested recipe with ingredients.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/RecipeDetail" }
              }
            }
          },
          "400": {
            "description": "Invalid id.",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/Error" } }
            }
          },
          "404": {
            "description": "Recipe not found.",
            "content": {
              "application/json": { "schema": { "$ref": "#/components/schemas/Error" } }
            }
          }
        }
      }
    },
    "/api/facets": {
      "get": {
        "tags": ["Metadata"],
        "summary": "List filter facets",
        "description": "Returns the distinct cuisines and categories present in the catalog, for building filter UIs.",
        "responses": {
          "200": {
            "description": "Available facets.",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/Facets" }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Recipe": {
        "type": "object",
        "properties": {
          "id": { "type": "integer", "example": 84 },
          "name": { "type": "string", "example": "Grilled Chicken Bowl" },
          "cuisine": { "type": "string", "example": "Italian" },
          "category": { "type": "string", "example": "Soup" },
          "difficulty": { "type": "string", "enum": ["easy", "medium", "hard"], "example": "easy" },
          "prep_min": { "type": "integer", "example": 17 },
          "cook_min": { "type": "integer", "example": 38 },
          "servings": { "type": "integer", "example": 1 },
          "calories": { "type": "integer", "description": "Per serving.", "example": 688 },
          "is_vegetarian": { "type": "integer", "enum": [0, 1], "description": "1 = vegetarian, 0 = not." },
          "image_url": { "type": "string", "format": "uri", "nullable": true, "example": "https://picsum.photos/seed/recipe84/600/400" }
        }
      },
      "Ingredient": {
        "type": "object",
        "properties": {
          "id": { "type": "integer", "example": 461 },
          "recipe_id": { "type": "integer", "example": 84 },
          "name": { "type": "string", "example": "olive oil" },
          "quantity": { "type": "string", "example": "3 cloves" }
        }
      },
      "RecipeDetail": {
        "allOf": [
          { "$ref": "#/components/schemas/Recipe" },
          {
            "type": "object",
            "properties": {
              "ingredients": {
                "type": "array",
                "items": { "$ref": "#/components/schemas/Ingredient" }
              }
            }
          }
        ]
      },
      "RecipeList": {
        "type": "object",
        "properties": {
          "total": { "type": "integer", "description": "Total matches before pagination.", "example": 100 },
          "count": { "type": "integer", "description": "Number returned in this page.", "example": 20 },
          "limit": { "type": "integer", "example": 20 },
          "offset": { "type": "integer", "example": 0 },
          "recipes": {
            "type": "array",
            "items": { "$ref": "#/components/schemas/Recipe" }
          }
        }
      },
      "Facets": {
        "type": "object",
        "properties": {
          "cuisines": {
            "type": "array",
            "items": { "type": "string" },
            "example": ["French", "Greek", "Italian", "Japanese", "Korean", "Moroccan", "Spanish"]
          },
          "categories": {
            "type": "array",
            "items": { "type": "string" },
            "example": ["Appetizer", "Breakfast", "Dessert", "Main", "Salad", "Side", "Snack", "Soup"]
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "error": { "type": "string", "example": "Recipe not found" }
        }
      }
    }
  }
}
