{
  "openapi": "3.1.0",
  "info": {
    "title": "Crews & Anna Recipe Book",
    "version": "1.0.0",
    "description": "Add recipes to Crews and Anna's kitchen inbox. They get filed onto https://recipes.crews.fyi within about an hour. For assistants and Custom GPT Actions."
  },
  "servers": [{ "url": "https://recipes.crews.fyi" }],
  "paths": {
    "/api/plan": {
      "get": {"operationId": "getWeekPlan", "summary": "This week's plan, live from the repo", "security": [{"ApiKeyAuth": []}], "responses": {"200": {"description": "Current plan", "content": {"application/json": {"schema": {"type": "object", "properties": {"week": {"type": "string", "example": "2026-W45"}, "starts": {"type": "string", "example": "2026-11-02"}, "path": {"type": "string"}, "exists": {"type": "boolean"}, "recipes": {"type": "array", "items": {"type": "string"}}, "nights": {"type": "array", "items": {"type": "string"}}, "extras": {"type": "array", "items": {"type": "string"}}}}}}}, "401": {"description": "No key or session"}}},
      "post": {"operationId": "editWeekPlan", "summary": "Add or remove a recipe on this week's plan, or mark a grocery item as already have", "security": [{"ApiKeyAuth": []}], "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "properties": {"slug": {"type": "string", "description": "Recipe slug from recipes/ (for add/remove)", "example": "squash-soup"}, "action": {"type": "string", "enum": ["add", "remove", "have", "unhave"], "default": "add"}, "as": {"type": "string", "enum": ["dinner", "extra"], "description": "Default: main and soup-bowl are dinners, other types are extras"}, "night": {"type": "string", "enum": ["mon", "tue", "wed", "thu", "fri", "sat", "sun", "any"], "default": "any"}, "item": {"type": "string", "maxLength": 80, "description": "For have/unhave: a grocery line's key from /week.json items[].key (or have[].on_hand to undo)", "example": "chicken stock"}}}}}}, "responses": {"200": {"description": "Saved (or already set). /week/ rebuilds in about a minute.", "content": {"application/json": {"schema": {"type": "object", "properties": {"ok": {"type": "boolean"}, "changed": {"type": "boolean"}, "week": {"type": "string"}, "as": {"type": "string"}, "in_plan": {"type": "boolean"}, "commit": {"type": "string", "nullable": true}}}}}}, "400": {"description": "Bad input"}, "401": {"description": "No key or session"}, "404": {"description": "Unknown recipe"}, "409": {"description": "No plan this week (have/unhave)"}}}
    },
    "/api/inventory": {
      "get": {"operationId": "previewInventoryUse", "summary": "Inventory lines a recipe may take off", "security": [{"ApiKeyAuth": []}], "parameters": [{"name": "slug", "in": "query", "required": true, "schema": {"type": "string"}, "example": "squash-soup"}], "responses": {"200": {"description": "Checklist of matching inventory items", "content": {"application/json": {"schema": {"type": "object", "properties": {"slug": {"type": "string"}, "items": {"type": "array", "items": {"type": "object", "properties": {"name": {"type": "string"}, "line": {"type": "string"}, "section": {"type": "string"}, "suggested": {"type": "boolean"}, "reason": {"type": "string"}}}}}}}}}, "401": {"description": "No key or session"}, "404": {"description": "Unknown recipe"}}},
      "post": {"operationId": "editInventory", "summary": "Add or remove grocery names in kitchen/inventory.md", "security": [{"ApiKeyAuth": []}], "requestBody": {"required": true, "content": {"application/json": {"schema": {"type": "object", "properties": {"action": {"type": "string", "enum": ["add", "remove"], "default": "add"}, "items": {"type": "array", "maxItems": 40, "items": {"type": "string", "maxLength": 80}, "example": ["Cremini mushrooms", "Lentils"]}}}}}}, "responses": {"200": {"description": "Saved (or already set). Inventory rebuilds in about a minute.", "content": {"application/json": {"schema": {"type": "object", "properties": {"ok": {"type": "boolean"}, "changed": {"type": "boolean"}, "added": {"type": "array", "items": {"type": "string"}}, "removed": {"type": "array", "items": {"type": "string"}}, "skipped_staples": {"type": "array", "items": {"type": "string"}}, "commit": {"type": "string", "nullable": true}}}}}}, "400": {"description": "Bad input"}, "401": {"description": "No key or session"}}}
    },
    "/api/recipes": {
      "post": {
        "operationId": "addRecipes",
        "summary": "Add one or many recipes",
        "description": "Commit recipes into the public recipe inbox as create-only files. Prefer JSON recipes[]. Markdown also works. Do not invent amounts; use (amount not given).",
        "security": [{ "ApiKeyAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/AddRecipesRequest" },
              "examples": {
                "jsonBatch": {
                  "summary": "Structured recipes",
                  "value": {
                    "recipes": [
                      {
                        "title": "Egg Bites",
                        "ingredients": ["6 eggs", "1/2 cup cottage cheese", "salt"],
                        "steps": ["Blend eggs and cottage cheese.", "Bake in muffin tin at 350F for 20 min."],
                        "source": "Anna",
                        "notes": "Made this morning"
                      }
                    ]
                  }
                },
                "markdown": {
                  "summary": "Markdown paste",
                  "value": { "markdown": "# Egg Bites\n\n## Ingredients\n- 6 eggs\n\n## Steps\n1. Bake." }
                }
              }
            },
            "text/markdown": {
              "schema": { "type": "string" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved to inbox",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AddRecipesResponse" }
              }
            }
          },
          "401": { "description": "Missing or bad API key / session" },
          "413": { "description": "Payload too large" },
          "429": { "description": "Daily cap reached" }
        }
      }
    },
    "/api/add": {
      "post": {
        "operationId": "addRecipesAlias",
        "summary": "Alias of addRecipes",
        "security": [{ "ApiKeyAuth": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/AddRecipesRequest" }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Saved to inbox",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AddRecipesResponse" }
              }
            }
          },
          "401": { "description": "Unauthorized" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Per-person API key from Crews (Bearer token). Never share publicly."
      }
    },
    "schemas": {
      "Recipe": {
        "type": "object",
        "required": ["title"],
        "properties": {
          "title": { "type": "string", "description": "Short dish name, 2-4 words" },
          "ingredients": {
            "type": "array",
            "items": { "oneOf": [{ "type": "string" }, { "type": "object" }] }
          },
          "steps": {
            "type": "array",
            "items": { "oneOf": [{ "type": "string" }, { "type": "object" }] }
          },
          "source": { "type": "string" },
          "notes": { "type": "string" },
          "type": { "type": "string", "description": "main, side, cocktail, etc." },
          "body": { "type": "string", "description": "Optional full markdown body instead of ingredients/steps" },
          "markdown": { "type": "string" }
        }
      },
      "AddRecipesRequest": {
        "type": "object",
        "properties": {
          "recipes": {
            "type": "array",
            "maxItems": 40,
            "items": { "$ref": "#/components/schemas/Recipe" }
          },
          "markdown": { "type": "string", "description": "One or many recipes as markdown; split on --- or # headings" },
          "text": { "type": "string", "description": "Alias of markdown" }
        }
      },
      "AddRecipesResponse": {
        "type": "object",
        "properties": {
          "ok": { "type": "boolean" },
          "who": { "type": "string" },
          "count": { "type": "integer" },
          "titles": { "type": "array", "items": { "type": "string" } },
          "commit": { "type": "string" },
          "message": { "type": "string" }
        }
      }
    }
  }
}
